Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add UV support for Python environment discovery #228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Jul 14, 2025

This PR adds support for UV (https://github.com/astral-sh/uv), a fast Python package installer and resolver, to the python-environment-tools library.

What this PR does

  • Discovers UV-managed global Python installations: Detects Python installations managed by UV in its data directory
  • Cross-platform support: Works on Windows, macOS, and Linux with platform-specific default locations
  • Respects UV configuration: Honors the UV_DATA_DIR environment variable for custom UV data locations
  • Integrates with existing virtual environment detection: UV-created virtual environments are standard Python venvs that are automatically detected by the existing venv locator

Implementation details

Core changes:

  • Added PythonEnvironmentKind::Uv to represent UV-managed Python environments
  • Added EnvManagerType::Uv to represent UV as an environment manager
  • Added LocatorKind::Uv for the UV locator type
  • Updated README.md to document UV as a supported environment type

New pet-uv crate:

  • Implements the Locator trait for UV Python discovery
  • Discovers Python installations in UV's data directory:
    • Windows: %APPDATA%\uv\python\
    • Unix-like: ~/.local/share/uv/python/
    • Custom: Configurable via UV_DATA_DIR environment variable
  • Identifies UV Python installations by checking if executables/prefixes are under UV's python directory
  • Finds UV executable in PATH for proper manager attribution

Testing:

  • Comprehensive unit tests for UV data directory discovery
  • Integration tests for end-to-end UV locator functionality
  • All existing tests continue to pass
  • Manual verification with mock UV environments

Usage example

# UV locator appears in breakdown
$ pet find
Breakdown by each locator:
--------------------------
Conda                : 19.507ms
...
Uv                   : 127.519µs
...

Environments (4):
------------------
Conda                : 1
LinuxGlobal          : 2
Uv                   : 1

# Can filter specifically for UV environments
$ pet find --kind uv

# UV appears as a supported environment kind
$ pet find --help
... --kind <KIND> ... [possible values: ..., uv, ...]

This addresses both requirements from the issue:

  • ✅ Discovery of all global Python installs (done via UV)
  • ✅ Discovery of all Python virtual environments (created via UV, detected as standard venvs)

Fixes #227.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • astral.sh
    • Triggering command: curl -LsSf REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] support search for UV Add UV support for Python environment discovery Jul 14, 2025
Copilot finished work on behalf of eleanorjboyd July 14, 2025 21:36
@Copilot Copilot AI requested a review from eleanorjboyd July 14, 2025 21:36
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.

support search for UV
2 participants