Skip to content

Conversation

zsol
Copy link

@zsol zsol commented Sep 22, 2025

RFC

I'm putting this PR up early to get feedback on the overall approach. It's not yet ready to merge.

Description

This makes pet discover uv workspaces as described in the docs. It also will recognize venvs created by uv and report them as PythonEnvironmentKind::Uv instead of PythonEnvironmentKind::Venv.

Notes:

  • only venvs that are already materialized on disk are returned
  • when pointed directly at a materialized workspace venv, it will not go look for individual project environments
  • for a workspace that's also a project, only the workspace env will be reported

TODOs:

  • make sure workspace members/exclude configuration is consulted
  • write test cases

Examples

A simple Python project with no workspaces but a venv managed by uv
❯ pet find -l
Environment (Uv)
   Display-Name: example
   Name        : example
   Executable  : /Users/zsol/dev/example/.venv/bin/python
   Version     : 3.13.7
   Prefix      : /Users/zsol/dev/example/.venv
   Symlinks    : "/Users/zsol/dev/example/.venv/bin/python"
               : "/Users/zsol/dev/example/.venv/bin/python3"
               : "/Users/zsol/dev/example/.venv/bin/python3.13"

Environment (Homebrew)
   Executable  : /opt/homebrew/bin/python3
   Version     : 3.13.7
[...]

Environment (MacCommandLineTools)
   Executable  : /usr/bin/python3
   Version     : 3.9.6.final.0
   Prefix      : /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9
   Architecture: x64
[...]

Breakdown by each locator:
--------------------------
Conda                : 6.348625ms
Homebrew             : 19.94475ms
MacCommandLineTools  : 32.338292ms
MacPythonOrg         : 17.708µs
MacXCode             : 83ns
PipEnv               : 84ns
Pixi                 : 0ns
Poetry               : 558.833µs
PyEnv                : 59.625µs
Uv                   : 894.5µs
Venv                 : 292ns
VirtualEnv           : 291ns
VirtualEnvWrapper    : 42ns

Breakdown for finding Environments:
-----------------------------------
GlobalVirtualEnvs    : 26.625µs
Locators             : 33.296708ms
Path                 : 34.134875ms
Workspaces           : 2.355125ms

Environments (3):
------------------
Homebrew             : 1
MacCommandLineTools  : 1
Uv                   : 1

Completed in 75ms
A project that's part of a larger workspace, but the project itself doesn't have its own venv
❯ pwd
/Users/zsol/dev/airflow/shared/logging
❯ pet find -l
Environment (UvWorkspace)
   Name        : apache-airflow
   Executable  : /Users/zsol/dev/airflow/.venv/bin/python
   Version     : 3.13.7
   Prefix      : /Users/zsol/dev/airflow/.venv
   Symlinks    : "/Users/zsol/dev/airflow/.venv/bin/python"
               : "/Users/zsol/dev/airflow/.venv/bin/python3"
               : "/Users/zsol/dev/airflow/.venv/bin/python3.13"

Environment (Homebrew)
   Executable  : /opt/homebrew/bin/python3
   Version     : 3.13.7
[...]

Environment (MacCommandLineTools)
   Executable  : /usr/bin/python3
   Version     : 3.9.6.final.0
[...]

Breakdown by each locator:
--------------------------
Conda                : 7.496ms
Homebrew             : 18.846625ms
MacCommandLineTools  : 31.925875ms
MacPythonOrg         : 10.416µs
MacXCode             : 542ns
PipEnv               : 542ns
Pixi                 : 834ns
Poetry               : 1.839375ms
PyEnv                : 116.5µs
Uv                   : 2.428833ms
Venv                 : 417ns
VirtualEnv           : 250ns
VirtualEnvWrapper    : 125ns

Breakdown for finding Environments:
-----------------------------------
GlobalVirtualEnvs    : 1.449916ms
Locators             : 33.650333ms
Path                 : 34.450042ms
Workspaces           : 2.147375ms

Environments (3):
------------------
Homebrew             : 1
MacCommandLineTools  : 1
UvWorkspace          : 1

Completed in 66ms
Multiple projects in the same workspace
❯ pet find -l airflow/shared/logging airflow/shared/timezones/
Environment (UvWorkspace)
   Name        : apache-airflow
   Executable  : airflow/.venv/bin/python
   Version     : 3.13.7
   Prefix      : airflow/.venv
   Symlinks    : "airflow/.venv/bin/python"
               : "airflow/.venv/bin/python3"
               : "airflow/.venv/bin/python3.13"

Environment (Homebrew)
   Executable  : /opt/homebrew/bin/python3
   Version     : 3.13.7
[...]

Environment (MacCommandLineTools)
   Executable  : /usr/bin/python3
   Version     : 3.9.6.final.0
[...]


Breakdown by each locator:
--------------------------
Conda                : 6.214958ms
Homebrew             : 18.067875ms
MacCommandLineTools  : 31.45625ms
MacPythonOrg         : 11.959µs
MacXCode             : 333ns
PipEnv               : 41ns
Pixi                 : 375ns
Poetry               : 803.917µs
PyEnv                : 56.5µs
Uv                   : 2.251417ms
Venv                 : 125ns
VirtualEnv           : 333ns
VirtualEnvWrapper    : 208ns

Breakdown for finding Environments:
-----------------------------------
GlobalVirtualEnvs    : 251µs
Locators             : 32.306459ms
Path                 : 33.075333ms
Workspaces           : 1.33325ms

Environments (3):
------------------
Homebrew             : 1
MacCommandLineTools  : 1
UvWorkspace          : 1

Completed in 71ms
A workspace and a project outside of it
❯ pet find -l airflow example
Environment (Uv)
   Name        : example
   Executable  : example/.venv/bin/python
   Version     : 3.13.7
   Prefix      : example/.venv
   Symlinks    : "example/.venv/bin/python"
               : "example/.venv/bin/python3"
               : "example/.venv/bin/python3.13"

Environment (UvWorkspace)
   Name        : apache-airflow
   Executable  : airflow/.venv/bin/python
   Version     : 3.13.7
   Prefix      : airflow/.venv
   Symlinks    : "airflow/.venv/bin/python"
               : "airflow/.venv/bin/python3"
               : "airflow/.venv/bin/python3.13"

Environment (Homebrew)
   Executable  : /opt/homebrew/bin/python3
   Version     : 3.13.7
[...]

Environment (MacCommandLineTools)
   Executable  : /usr/bin/python3
   Version     : 3.9.6.final.0
[...]

Breakdown by each locator:
--------------------------
Conda                : 7.473667ms
Homebrew             : 19.655875ms
MacCommandLineTools  : 32.770083ms
MacPythonOrg         : 16.292µs
MacXCode             : 375ns
PipEnv               : 208ns
Pixi                 : 250ns
Poetry               : 3.4505ms
PyEnv                : 87.125µs
Uv                   : 2.769417ms
Venv                 : 250ns
VirtualEnv           : 167ns
VirtualEnvWrapper    : 208ns

Breakdown for finding Environments:
-----------------------------------
GlobalVirtualEnvs    : 38.542µs
Locators             : 33.704875ms
Path                 : 34.471416ms
Workspaces           : 4.482583ms

Environments (4):
------------------
Homebrew             : 1
MacCommandLineTools  : 1
Uv                   : 1
UvWorkspace          : 1

Completed in 70ms

@zsol
Copy link
Author

zsol commented Sep 22, 2025

@microsoft-github-policy-service agree company="Astral"

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