auto-uv 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,344 @@
1
+ Metadata-Version: 2.4
2
+ Name: auto-uv
3
+ Version: 0.1.0
4
+ Summary: Automatically use 'uv run' when executing Python scripts
5
+ Project-URL: Repository, https://github.com/xRiskLab/auto-uv
6
+ Project-URL: Issues, https://github.com/xRiskLab/auto-uv/issues
7
+ Author-email: xRiskLab <contact@xrisklab.ai>
8
+ Maintainer-email: xRiskLab <contact@xrisklab.ai>
9
+ License: MIT License
10
+
11
+ Copyright (c) 2025 Auto UV
12
+
13
+ Permission is hereby granted, free of charge, to any person obtaining a copy
14
+ of this software and associated documentation files (the "Software"), to deal
15
+ in the Software without restriction, including without limitation the rights
16
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
+ copies of the Software, and to permit persons to whom the Software is
18
+ furnished to do so, subject to the following conditions:
19
+
20
+ The above copyright notice and this permission notice shall be included in all
21
+ copies or substantial portions of the Software.
22
+
23
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
+ SOFTWARE.
30
+
31
+ License-File: LICENSE
32
+ Keywords: automation,development,package manager,python,uv
33
+ Classifier: Development Status :: 4 - Beta
34
+ Classifier: Intended Audience :: Developers
35
+ Classifier: License :: OSI Approved :: MIT License
36
+ Classifier: Operating System :: OS Independent
37
+ Classifier: Programming Language :: Python :: 3
38
+ Classifier: Programming Language :: Python :: 3.9
39
+ Classifier: Programming Language :: Python :: 3.10
40
+ Classifier: Programming Language :: Python :: 3.11
41
+ Classifier: Programming Language :: Python :: 3.12
42
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
43
+ Requires-Python: >=3.9
44
+ Provides-Extra: dev
45
+ Requires-Dist: bandit>=1.7.0; extra == 'dev'
46
+ Requires-Dist: black>=24.0.0; extra == 'dev'
47
+ Requires-Dist: build>=1.0.0; extra == 'dev'
48
+ Requires-Dist: bump2version>=1.0.0; extra == 'dev'
49
+ Requires-Dist: hatch-autorun>=1.0.0; extra == 'dev'
50
+ Requires-Dist: isort>=5.0.0; extra == 'dev'
51
+ Requires-Dist: mypy>=1.0.0; extra == 'dev'
52
+ Requires-Dist: pre-commit>=3.0.0; extra == 'dev'
53
+ Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
54
+ Requires-Dist: pytest>=7.0.0; extra == 'dev'
55
+ Requires-Dist: ruff>=0.1.0; extra == 'dev'
56
+ Requires-Dist: twine>=4.0.0; extra == 'dev'
57
+ Description-Content-Type: text/markdown
58
+
59
+ # auto-uv
60
+
61
+ [![Python Version](https://img.shields.io/badge/python-3.9%2B-blue)](https://www.python.org/downloads/)
62
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
63
+ [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
64
+
65
+ Automatically use `uv run` when executing Python scripts. Just type `python script.py` instead of `uv run script.py`!
66
+
67
+ ## What is This?
68
+
69
+ `auto-uv` is a Python package that intercepts script execution and automatically uses [uv](https://github.com/astral-sh/uv) to run them. Install it once, then forget about it - your scripts just work with proper dependency management.
70
+
71
+ ## Installation
72
+
73
+ ```bash
74
+ pip install auto-uv
75
+ ```
76
+
77
+ That's it! Now when you run `python script.py`, it automatically uses `uv run` behind the scenes.
78
+
79
+ ## Quick Start
80
+
81
+ ```bash
82
+ # Install
83
+ pip install auto-uv
84
+
85
+ # Run any script - auto-uv handles the rest
86
+ python your_script.py
87
+
88
+ # Disable temporarily if needed
89
+ AUTO_UV_DISABLE=1 python your_script.py
90
+ ```
91
+
92
+ ## How It Works
93
+
94
+ When you install `auto-uv`, it uses the `hatch-autorun` plugin to automatically run code when Python starts. This code checks if:
95
+
96
+ 1. You're running a script file (not interactive mode)
97
+ 2. `uv` is available on your system
98
+ 3. You're not already running under `uv run`
99
+
100
+ If all conditions are met, it re-executes your script with `uv run`, giving you automatic dependency management.
101
+
102
+ ## Requirements
103
+
104
+ - Python 3.9+
105
+ - `uv` installed and in your PATH
106
+
107
+ Install uv:
108
+ ```bash
109
+ curl -LsSf https://astral.sh/uv/install.sh | sh # macOS/Linux
110
+ # or
111
+ pip install uv
112
+ ```
113
+
114
+ ## Configuration
115
+
116
+ ### Environment Variables
117
+
118
+ - `AUTO_UV_DISABLE`: Set to `1`, `true`, or `yes` to disable auto-uv
119
+ - `UV_RUN_ACTIVE`: Automatically set by auto-uv (don't set manually)
120
+
121
+ ### Disabling auto-uv
122
+
123
+ ```bash
124
+ # Temporarily disable
125
+ AUTO_UV_DISABLE=1 python script.py
126
+
127
+ # Permanently disable (add to your shell profile)
128
+ export AUTO_UV_DISABLE=1
129
+ ```
130
+
131
+ ## Development
132
+
133
+ ### Setup
134
+
135
+ ```bash
136
+ # Clone the repository
137
+ git clone https://github.com/xRiskLab/auto-uv.git
138
+ cd auto-uv
139
+
140
+ # Install with all dev dependencies
141
+ uv pip install -e ".[dev]"
142
+
143
+ # Install pre-commit hooks
144
+ pre-commit install
145
+
146
+ # Or use the Makefile
147
+ make dev
148
+ ```
149
+
150
+ ### Testing
151
+
152
+ ```bash
153
+ # Run tests
154
+ make test
155
+
156
+ # Run tests with act (local GitHub Actions)
157
+ make act-test
158
+
159
+ # Format and lint
160
+ make format lint
161
+
162
+ # Full CI pipeline locally
163
+ make ci
164
+ ```
165
+
166
+ ### Available Make Targets
167
+
168
+ ```bash
169
+ make help # Show all available commands
170
+ make dev # Setup development environment
171
+ make test # Run tests
172
+ make lint # Run linters
173
+ make format # Format code
174
+ make build # Build package with uv
175
+ make publish-test # Publish to Test PyPI
176
+ make publish # Publish to PyPI
177
+ make clean # Clean build artifacts
178
+ make act-test # Test with act (local GitHub Actions)
179
+ make pre-commit # Run pre-commit hooks
180
+ make commit # Format, lint, and test before commit
181
+ ```
182
+
183
+ ### Publishing Manually
184
+
185
+ ```bash
186
+ # 1. Get token from https://pypi.org/manage/account/token/
187
+
188
+ # 2. Add to .env file (already in .gitignore)
189
+ echo "UV_PUBLISH_TOKEN=pypi-AgE..." >> .env
190
+
191
+ # 3. Build and publish (Makefile auto-loads .env)
192
+ make publish-test
193
+
194
+ # 4. If successful, publish to PyPI
195
+ make publish
196
+ ```
197
+
198
+ ## Testing with Act
199
+
200
+ Test GitHub Actions workflows locally before pushing:
201
+
202
+ ```bash
203
+ # Install act
204
+ brew install act # macOS
205
+ # or see: https://github.com/nektos/act
206
+
207
+ # Optional: Create .env file for secrets (if needed)
208
+ echo "GITHUB_TOKEN=your_token_here" > .env
209
+
210
+ # Test workflows
211
+ make act-test # Quick test
212
+ make act-lint # Test linting
213
+ make act-all # Test everything
214
+ ```
215
+
216
+ ## Version Management
217
+
218
+ Bump version using GitHub Actions:
219
+
220
+ ```bash
221
+ gh workflow run version-bump.yml -f version_type=patch # 0.1.0 -> 0.1.1
222
+ gh workflow run version-bump.yml -f version_type=minor # 0.1.0 -> 0.2.0
223
+ gh workflow run version-bump.yml -f version_type=major # 0.1.0 -> 1.0.0
224
+ ```
225
+
226
+ Or use the Makefile:
227
+
228
+ ```bash
229
+ make version-patch # Bump patch version
230
+ make version-minor # Bump minor version
231
+ make version-major # Bump major version
232
+ ```
233
+
234
+ ## CI/CD
235
+
236
+ The project includes three GitHub Actions workflows:
237
+
238
+ 1. **test.yml** - Run tests on multiple Python versions (3.9-3.12) and OS (Ubuntu, macOS, Windows)
239
+ 2. **workflow.yml** - Build and publish to PyPI on release (required name for PyPI)
240
+ 3. **version-bump.yml** - Automated version management
241
+
242
+ ## Troubleshooting
243
+
244
+ ### Installing packages in a uv project
245
+
246
+ Use `uv add` to manage dependencies:
247
+
248
+ ```bash
249
+ # Add runtime dependency
250
+ uv add requests
251
+
252
+ # Add development dependency
253
+ uv add --dev pytest
254
+
255
+ # Add multiple packages
256
+ uv add --dev mypy black ruff
257
+ ```
258
+
259
+ ### Can't install packages
260
+
261
+ If auto-uv is interfering:
262
+
263
+ ```bash
264
+ # Option 1: Disable auto-uv temporarily
265
+ AUTO_UV_DISABLE=1 pip install package-name
266
+
267
+ # Option 2: Uninstall auto-uv if not needed
268
+ pip uninstall auto-uv
269
+ ```
270
+
271
+ ### Auto-uv not working
272
+
273
+ ```bash
274
+ # Check if uv is installed
275
+ uv --version
276
+
277
+ # Check if auto-uv is installed
278
+ python -c "import auto_uv; print('Installed')"
279
+
280
+ # Test manually
281
+ python -c "import os; print('UV_RUN_ACTIVE:', os.environ.get('UV_RUN_ACTIVE'))"
282
+ ```
283
+
284
+ ## Contributing
285
+
286
+ Contributions welcome! Here's the quick workflow:
287
+
288
+ ```bash
289
+ # 1. Fork and clone
290
+ git clone https://github.com/YOUR_USERNAME/auto-uv.git
291
+ cd auto-uv
292
+
293
+ # 2. Setup
294
+ make dev
295
+
296
+ # 3. Create branch
297
+ git checkout -b feature/your-feature
298
+
299
+ # 4. Make changes and test
300
+ make commit
301
+
302
+ # 5. Test with act
303
+ make act-test
304
+
305
+ # 6. Push and create PR
306
+ git push origin feature/your-feature
307
+ gh pr create
308
+ ```
309
+
310
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed guidelines.
311
+
312
+ ## Why auto-uv?
313
+
314
+ ### Without auto-uv:
315
+ ```bash
316
+ uv run script.py # Have to remember uv run every time
317
+ ```
318
+
319
+ ### With auto-uv:
320
+ ```bash
321
+ python script.py # Just works!
322
+ ```
323
+
324
+ Benefits:
325
+ - ✅ Seamless workflow
326
+ - ✅ Automatic dependency management via uv
327
+ - ✅ Zero configuration
328
+ - ✅ Easy to disable when needed
329
+ - ✅ Safe fallback if uv not available
330
+
331
+ ## Inspiration
332
+
333
+ Inspired by [pyauto-dotenv](https://github.com/hmiladhia/auto-dotenv) which automatically loads `.env` files.
334
+
335
+ ## License
336
+
337
+ MIT License - see [LICENSE](LICENSE) file for details.
338
+
339
+ ## Links
340
+
341
+ - **Repository**: https://github.com/xRiskLab/auto-uv
342
+ - **Issues**: https://github.com/xRiskLab/auto-uv/issues
343
+ - **uv**: https://github.com/astral-sh/uv
344
+ - **hatch-autorun**: https://github.com/pypa/hatch
@@ -0,0 +1,6 @@
1
+ auto_uv.py,sha256=zJCs7l5dT2zoQFRgktR8vUou_dTvbfZ8pNDUd-Mb2pM,1900
2
+ hatch_autorun_auto_uv.pth,sha256=TNfVTcdzkwlUD5Sm-tccl77whdVV_94tsLodj8RKmG0,58
3
+ auto_uv-0.1.0.dist-info/METADATA,sha256=2Qq1TSEfEM_VjJiWtXQidA-wxKlbiYyGA0x0AGL1cXU,9253
4
+ auto_uv-0.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
5
+ auto_uv-0.1.0.dist-info/licenses/LICENSE,sha256=_EJByt8cL-R7sa3hKWOcbHPAUMYBmNwEhw2I_z4G3m8,1065
6
+ auto_uv-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Auto UV
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
auto_uv.py ADDED
@@ -0,0 +1,59 @@
1
+ import sys
2
+ import os
3
+ import subprocess
4
+
5
+
6
+ def should_use_uv():
7
+ """Check if we should intercept and use uv run."""
8
+ # Don't intercept if we're already running under uv
9
+ if os.environ.get("UV_RUN_ACTIVE"):
10
+ return False
11
+
12
+ # Don't intercept if AUTO_UV is explicitly disabled
13
+ if os.environ.get("AUTO_UV_DISABLE", "").lower() in ("1", "true", "yes"):
14
+ return False
15
+
16
+ # Check if uv is available
17
+ try:
18
+ subprocess.run(
19
+ ["uv", "--version"],
20
+ capture_output=True,
21
+ check=True,
22
+ timeout=2
23
+ )
24
+ return True
25
+ except (subprocess.CalledProcessError, FileNotFoundError, subprocess.TimeoutExpired):
26
+ return False
27
+
28
+
29
+ def auto_use_uv():
30
+ """
31
+ Automatically re-execute the current script with 'uv run' if conditions are met.
32
+
33
+ This function checks if:
34
+ 1. We're not already running under uv
35
+ 2. UV_RUN_ACTIVE environment variable is not set
36
+ 3. uv is available in the system
37
+ 4. We're running a script (not interactive or -c command)
38
+
39
+ If all conditions are met, it re-executes the script with 'uv run'.
40
+ """
41
+ # Only intercept if running a script file
42
+ if len(sys.argv) > 0 and sys.argv[0] and os.path.isfile(sys.argv[0]):
43
+ if should_use_uv():
44
+ # Set environment variable to prevent infinite loop
45
+ env = os.environ.copy()
46
+ env["UV_RUN_ACTIVE"] = "1"
47
+
48
+ # Build the uv run command
49
+ cmd = ["uv", "run"] + sys.argv
50
+
51
+ # Execute with uv run and exit
52
+ try:
53
+ result = subprocess.run(cmd, env=env)
54
+ sys.exit(result.returncode)
55
+ except Exception as e:
56
+ # If uv run fails, continue with normal execution
57
+ print(f"Warning: Failed to run with uv: {e}", file=sys.stderr)
58
+ return
59
+
@@ -0,0 +1 @@
1
+ import os, sys;exec("__import__('auto_uv').auto_use_uv()")