Add --use-uv flag for faster venv creation using uv - #409
Conversation
Added opt-in --use-uv flag to create_venvs.py that uses uv for venv creation and package installation instead of the stdlib venv + pip. When the flag is not provided, behavior is unchanged. Updated README with usage example.
There was a problem hiding this comment.
Thank you for your contribution!
Overall this is solid work — the approach is clean and well-scoped.
The PR also has a merge conflict with main that will need a rebase before this can land.
Happy to approve once the comments and the rebase are addressed.
| venv.create(venv_path, with_pip=True, symlinks=True) | ||
| if use_uv: | ||
| subprocess.run(["uv", "venv", str(venv_path)], check=True) | ||
| else: |
There was a problem hiding this comment.
nit: Without --python, uv picks its own default interpreter, which, although unlikely, may not match what verify_python_version() validated above — silently creating a venv on a different Python version.
Suggested fix:
subprocess.run(["uv", "venv", "--python", sys.executable, str(venv_path)], check=True)| "--python", | ||
| os.path.join(venv_dir, "bin", "python"), | ||
| *args, | ||
| ], |
There was a problem hiding this comment.
The existing codebase already has Windows support — the README documents a PowerShell 5.1 setup, and main already guards against Windows in create_venv():
# Already in main branch:
venv.create(venv_path, with_pip=True, symlinks=(sys.platform != "win32"))So Windows developers do run create_venvs.py locally. This hardcoded path will silently fail for them — Windows venvs use Scripts\python.exe, not bin/python.
Suggested fix:
python_path = str(Path(venv_dir) / ("Scripts" if sys.platform == "win32" else "bin") / "python")
Summary
Adds an opt-in
--use-uvflag tocreate_venvs.pythat uses uv instead of the stdlibvenv+pipfor significantly faster virtual environment creation and package installation.Changes
is_uv_available()helper to check ifuvis on PATH.uv_install()function that usesuv pip install --python <venv_python>for package installation.create_venv()to accept ause_uvparameter:True: usesuv venvfor venv creation anduv pip installfor all packages, skipping the pip upgrade step (not needed with uv).False(default): behavior is completely unchanged.--use-uvargparse flag with a clear error message if uv is not installed.Compatibility
create_venvs.py --target productionwithout--use-uv.uv venvproduces a standard venv structure (bin/activate,bin/python) so all downstream consumers (quality checks, linting, unit tests, build scripts, VS Code settings) work identically.Testing
Verified the following scenarios:
--use-uvwith uv installed — creates venv withuv venv, installs packages withuv pip install--use-uv— identical behavior to before--use-uvwithout uv installed — exits with clear error message--use-uvwith--recreate— properly deletes and recreates venv using uv--help— new flag appears in usage output