-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuv-scripts.mdc
More file actions
83 lines (70 loc) · 1.97 KB
/
uv-scripts.mdc
File metadata and controls
83 lines (70 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
---
description: Standards for creating and managing utility scripts with UV
globs: scripts/.*
---
# UV Scripts Standards
<rule>
name: uv_scripts
description: Standards for creating and managing utility scripts with UV
filters:
- type: file_extension
pattern: "\\.py$"
- type: path
pattern: "^scripts/.*"
- type: exclude_path
pattern: "^(stackone_ai|examples)/.*" # Exclude package and examples
actions:
- type: suggest
message: |
When creating utility scripts with UV:
1. Location:
- Place all utility scripts in the `scripts/` directory
- NOT for examples (use examples/ directory instead)
2. Include UV script dependencies header:
```python
# /// script
# requires-python = ">=3.8"
# dependencies = [
# "package1",
# "package2>=1.0.0"
# ]
# ///
```
3. Script Structure:
- Type hints are required
- Use async/await when doing I/O operations
- Include main guard: `if __name__ == "__main__":`
- Add return types to functions
4. Running Scripts:
```bash
uv run scripts/your_script.py
```
5. Error Handling:
- Use try/except blocks for external calls
- Print meaningful error messages
- Exit with appropriate status codes
examples:
- input: |
# Utility script
# /// script
# requires-python = ">=3.8"
# dependencies = ["httpx"]
# ///
from typing import Dict
import asyncio
import httpx
async def fetch_data() -> Dict:
async with httpx.AsyncClient() as client:
response = await client.get("https://api.example.com")
return response.json()
if __name__ == "__main__":
asyncio.run(fetch_data())
output: "Correctly structured utility script"
metadata:
priority: high
version: 1.1
tags:
- scripts
- uv
- python
</rule>