Skip to content

Discover and resolve .venv files (PEP 832)#431

Closed
edvilme wants to merge 6 commits intomicrosoft:mainfrom
edvilme:pep832
Closed

Discover and resolve .venv files (PEP 832)#431
edvilme wants to merge 6 commits intomicrosoft:mainfrom
edvilme:pep832

Conversation

@edvilme
Copy link
Copy Markdown
Collaborator

@edvilme edvilme commented Apr 16, 2026

This pull request introduces a new utility function for resolving Python virtual environments in a project directory, supporting both the traditional .venv directory and the PEP 832 convention where .venv is a file pointing to the environment. The function is thoroughly tested and integrated into multiple places in the codebase, replacing previous direct .venv path usage to improve compatibility and correctness.

New .venv resolution utility:

  • Added resolve_dot_venv to crates/pet-fs/src/path.rs, which resolves .venv as either a directory or a file (per PEP 832), handling absolute and relative paths and validating existence.
  • Comprehensive unit tests for resolve_dot_venv covering all edge cases, including missing .venv, directory, file with absolute/relative paths, non-existent targets, whitespace handling, and file-vs-directory distinction.

Integration into environment discovery:

  • Updated crates/pet-poetry/src/environment_locations.rs to use resolve_dot_env (likely a wrapper or alias for resolve_dot_venv) instead of directly joining .venv, ensuring correct environment resolution in Poetry projects.
  • Updated crates/pet-uv/src/lib.rs to use resolve_dot_env for both workspace root and directory environment detection, ensuring .venv file conventions are supported. [1] [2]
  • Updated crates/pet/src/find.rs to use resolve_dot_env when searching for environments in workspace folders, improving detection accuracy.

@edvilme edvilme force-pushed the pep832 branch 2 times, most recently from 97e85bf to 2a96166 Compare April 16, 2026 17:41
edvilme and others added 2 commits April 16, 2026 11:29
- find.rs: resolve_dot_venv returns Option<PathBuf>, use if-let to
  conditionally insert into search paths vec
- environment_locations.rs: fix bug where ? operator on None would
  short-circuit the function, losing already-collected environments
- path.rs: remove trailing whitespace in doc comments (fmt check)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…uation

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@edvilme edvilme changed the title Pep832 Discover and resolve .venv files (PEP 832) Apr 16, 2026
@edvilme
Copy link
Copy Markdown
Collaborator Author

edvilme commented Apr 17, 2026

Replaced by #433

@edvilme edvilme closed this Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant