feat(venv): add configurable venv directory via --venv-path flag#25
Merged
Conversation
This pull request adds support for configurable virtual environment directory names and paths, allowing users to specify custom venv locations via a new flag or environment variable. The main changes enhance flexibility in venv management. **Configurable venv directory support:** * Added a new `--venv-path` flag that accepts either a directory name (relative) or an absolute path to specify the venv location, replacing the hardcoded `.venv` default. * Introduced `resolve_venv_name()` function that prioritizes the `--venv-path` flag, falls back to `$UV_SHELL_VENV` environment variable, or defaults to `.venv` for backward compatibility. * Updated `get_venv_path()` to accept a configurable name parameter and handle both relative and absolute paths correctly. * Modified `find_venv_upward()` to support custom venv directory names and handle absolute paths by checking them directly without filesystem traversal. **Argument parsing and forwarding:** * Extended `scan_flags()` to parse and extract the `--venv-path` argument (both `--venv-path <PATH>` and `--venv-path=<PATH>` formats) without forwarding it to `uv venv`. * Updated flag stripping logic to filter out `--venv-path` and its value from arguments forwarded to `uv venv`, similar to existing `--prefix` handling. * Enhanced the `anchor` subcommand to use the resolved venv name for improved error messages showing the actual venv directory being searched. **Testing improvements:** * Added comprehensive unit tests for the new `--venv-path` flag parsing in both space-separated and equals-sign formats. * Updated all existing `scan_flags()` test cases to handle the new return value tuple structure.
benbenbang
enabled auto-merge (squash)
March 28, 2026 10:36
|
🎉 This PR is included in version 2.6.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request adds support for configurable virtual environment directory names and paths, allowing users to specify custom venv locations via a new flag or environment variable. The main changes enhance flexibility in venv management.
Configurable venv directory support:
--venv-pathflag that accepts either a directory name (relative) or an absolute path to specify the venv location, replacing the hardcoded.venvdefault.resolve_venv_name()function that prioritizes the--venv-pathflag, falls back to$UV_SHELL_VENVenvironment variable, or defaults to.venvfor backward compatibility.get_venv_path()to accept a configurable name parameter and handle both relative and absolute paths correctly.find_venv_upward()to support custom venv directory names and handle absolute paths by checking them directly without filesystem traversal.Argument parsing and forwarding:
scan_flags()to parse and extract the--venv-pathargument (both--venv-path <PATH>and--venv-path=<PATH>formats) without forwarding it touv venv.--venv-pathand its value from arguments forwarded touv venv, similar to existing--prefixhandling.anchorsubcommand to use the resolved venv name for improved error messages showing the actual venv directory being searched.Testing improvements:
--venv-pathflag parsing in both space-separated and equals-sign formats.scan_flags()test cases to handle the new return value tuple structure.