Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 18, 2025

✅ Implementation Complete: Add new environment type venv-uv for environments created with uv

Summary

Successfully implemented a new venv-uv environment type that can distinguish UV-created virtual environments from regular venv environments by detecting the presence of a uv = <version> entry in the pyvenv.cfg file.

UPDATED APPROACH (Based on feedback from @karthiknadig)

Instead of creating a separate pet-venv-uv crate, the implementation now extends the existing pet-venv crate to handle UV detection while maintaining the same Venv locator.

Key Features Implemented

1. UV Detection Logic

  • Extended PyVenvCfg struct with uv_version field and is_uv() method
  • Added parse_uv_version() function to parse uv = <version> lines from pyvenv.cfg
  • Handles various quote formats: uv = 0.8.14, uv = "0.8.14", uv = '0.8.14'

2. Enhanced Venv Locator

  • Modified existing Venv locator to support both PythonEnvironmentKind::Venv and PythonEnvironmentKind::VenvUv
  • Added automatic detection logic in try_from() method to return appropriate environment kind
  • Added helper functions: is_venv_uv(), is_venv_uv_dir() for external use

3. Unified Architecture

  • Single Venv locator handles both regular and UV-created virtual environments
  • No separate crate needed - cleaner, more maintainable architecture
  • Preserves all existing functionality while adding UV detection

Testing & Quality

8 Comprehensive Tests Added:

  • test_parse_uv_version() - Validates UV version parsing from various formats
  • test_pyvenv_cfg_detects_uv() - Tests PyVenvCfg UV detection capability
  • test_pyvenv_cfg_regular_venv() - Ensures regular venvs are not misidentified
  • test_is_venv_uv_dir_detects_uv_environment() - Directory-level UV detection
  • test_is_venv_uv_dir_does_not_detect_regular_environment() - Rejects regular venvs
  • test_is_venv_uv_dir_handles_nonexistent_environment() - Graceful error handling
  • test_venv_locator_detects_uv_kind() - Tests locator returns VenvUv for UV environments
  • test_venv_locator_detects_regular_venv_kind() - Tests locator returns Venv for regular environments

Quality Assurance:

  • ✅ All new and existing tests pass (no regressions)
  • ✅ Full workspace builds successfully in debug and release modes
  • ✅ CodeQL security scan clean - no vulnerabilities
  • ✅ Code properly formatted (cargo fmt) and linted (cargo clippy) - All clippy errors fixed
  • ✅ Self-contained tests that create/cleanup their own test files

Example Usage

UV Environment pyvenv.cfg:

home = /usr/bin/python3.12
implementation = CPython
uv = 0.8.14                    ← This line identifies UV!
version_info = 3.12.11
include-system-site-packages = false
prompt = my-uv-env

Detected as: PythonEnvironmentKind::VenvUv

Regular Venv pyvenv.cfg:

home = /usr/bin/python3.12
include-system-site-packages = false
version = 3.13.5               ← No "uv" entry
executable = /usr/bin/python3.12
command = python -m venv /path/to/env

Detected as: PythonEnvironmentKind::Venv

Architecture Benefits

  • Single Responsibility: One locator handles all venv-based environments
  • Cleaner Dependencies: No additional crate to maintain
  • Better Performance: No duplicate detection logic
  • Simpler Architecture: Follows existing patterns in the codebase

The implementation is complete, thoroughly tested, and follows the project's architectural guidelines.

Created from VS Code via the GitHub Pull Request extension.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits September 18, 2025 16:30
Co-authored-by: karthiknadig <3840081+karthiknadig@users.noreply.github.com>
Co-authored-by: karthiknadig <3840081+karthiknadig@users.noreply.github.com>
Co-authored-by: karthiknadig <3840081+karthiknadig@users.noreply.github.com>
Copilot AI changed the title [WIP] Add a new environment type venv-uv for environments created with uv. details: You can check if a ´.venv´ has been created with UV by reading its pyvenv.cfg file, if it is an UV one there will be an "uv" entry. With UV: pyvenv.cfg ***No... Add support for detecting UV-created virtual environments as venv-uv type Sep 18, 2025
Copilot AI requested a review from karthiknadig September 18, 2025 16:37
@karthiknadig
Copy link
Member

@copilot Don't create a new crate. Since the detection for the venv already exists, use that. Just add support for a new kind when venv is created using uv.

…ad of creating new crate

Co-authored-by: karthiknadig <3840081+karthiknadig@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Sep 18, 2025

@copilot Don't create a new crate. Since the detection for the venv already exists, use that. Just add support for a new kind when venv is created using uv.

Implemented as requested! I've removed the separate pet-venv-uv crate and instead extended the existing pet-venv locator to detect UV-created environments and return the appropriate PythonEnvironmentKind (Venv or VenvUv).

Changes made in commit d33381b:

  • Removed crates/pet-venv-uv/ entirely
  • Enhanced pet-venv locator to support both environment kinds
  • Added UV detection logic in the try_from() method
  • Added helper functions: is_venv_uv(), is_venv_uv_dir()
  • Updated supported_categories() to return both Venv and VenvUv
  • All tests pass and the architecture is much cleaner now

@karthiknadig
Copy link
Member

@copilot looks like you have clippy errors. please fix.

Co-authored-by: karthiknadig <3840081+karthiknadig@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Sep 18, 2025

@copilot looks like you have clippy errors. please fix.

Fixed! The clippy error was in pet-venv/src/lib.rs where I was using map_or(false, |c| c.is_uv()) instead of the more idiomatic is_some_and(|c| c.is_uv()).

Commit dd4ab64 resolves the issue and all tests continue to pass.

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.

2 participants