Skip to content

feat(venv): add configurable venv directory via --venv-path flag#25

Merged
benbenbang merged 1 commit into
mainfrom
custom_venv_path
Mar 28, 2026
Merged

feat(venv): add configurable venv directory via --venv-path flag#25
benbenbang merged 1 commit into
mainfrom
custom_venv_path

Conversation

@benbenbang

Copy link
Copy Markdown
Owner

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.

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.
@github-actions github-actions Bot added enhancement New feature or request triage labels Mar 28, 2026
@benbenbang
benbenbang enabled auto-merge (squash) March 28, 2026 10:36
@benbenbang
benbenbang merged commit c466c18 into main Mar 28, 2026
2 checks passed
@benbenbang
benbenbang deleted the custom_venv_path branch March 28, 2026 10:37
@ptah-technical-app

Copy link
Copy Markdown

🎉 This PR is included in version 2.6.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request released triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant