Skip to content

feat(venv): add upward directory traversal for .venv discovery - #22

Merged
benbenbang merged 1 commit into
mainfrom
feat/anchor_traveral
Mar 27, 2026
Merged

feat(venv): add upward directory traversal for .venv discovery#22
benbenbang merged 1 commit into
mainfrom
feat/anchor_traveral

Conversation

@benbenbang

Copy link
Copy Markdown
Owner

This pull request enhances the anchor command to search for virtual environments by traversing up the directory tree, rather than only checking the current directory. The main changes improve usability when working in project subdirectories.

Virtual environment discovery enhancement:

  • Added a new find_venv_upward function in src/main.rs that walks from the current directory up to the filesystem root looking for .venv/pyvenv.cfg, enabling anchor to work from any subdirectory within a project.
  • Refactored the anchor function to use find_venv_upward instead of only checking the current directory, with improved error messaging that indicates the traversal behavior.

Testing improvements:

  • Added a new integration test anchor_finds_venv_in_parent_directory in tests/integration.rs that verifies the anchor command correctly finds .venv when executed from nested subdirectories and sets VIRTUAL_ENV to the correct root path.
  • Updated existing test assertions to verify the new error message mentions "or any parent directory" when no .venv is found.
  • Added cleanup of temporary directories in existing tests to prevent resource leaks.

This pull request enhances the anchor command to search for virtual environments by traversing up the directory tree, rather than only checking the current directory. The main changes improve usability when working in project subdirectories.

**Virtual environment discovery enhancement:**
* Added a new `find_venv_upward` function in `src/main.rs` that walks from the current directory up to the filesystem root looking for `.venv/pyvenv.cfg`, enabling anchor to work from any subdirectory within a project.
* Refactored the `anchor` function to use `find_venv_upward` instead of only checking the current directory, with improved error messaging that indicates the traversal behavior.

**Testing improvements:**
* Added a new integration test `anchor_finds_venv_in_parent_directory` in `tests/integration.rs` that verifies the anchor command correctly finds `.venv` when executed from nested subdirectories and sets VIRTUAL_ENV to the correct root path.
* Updated existing test assertions to verify the new error message mentions "or any parent directory" when no .venv is found.
* Added cleanup of temporary directories in existing tests to prevent resource leaks.
@github-actions github-actions Bot added enhancement New feature or request triage labels Mar 27, 2026
@benbenbang
benbenbang merged commit d0a705d into main Mar 27, 2026
2 checks passed
@benbenbang
benbenbang deleted the feat/anchor_traveral branch March 27, 2026 19:15
@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