Skip to content
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

tox-uv underspecifies the uv -p option, allowing uv to find PyPy instead of CPython versions #142

Closed
kurtmckee opened this issue Dec 19, 2024 · 0 comments · Fixed by #143
Labels
bug Something isn't working

Comments

@kurtmckee
Copy link
Contributor

kurtmckee commented Dec 19, 2024

Issue

On Windows, I'm finding that uv discovers PyPy 3.10 before CPython 3.10 under the following circumstances:

  • When given only a language version identifier, like -p 3.10
  • When that PyPy language version appears on the $PATH but not the CPython language version

However, uv correctly distinguishes between PyPy and CPython when the implementation is included:

-p cpython3.10
-p pypy3.10

tox-uv removes the implementation if it's cpython, which -- on my Windows box -- means that my "py3.10" factor is unexpectedly running on PyPy 3.10 and fails due to a PyPy-incompatible dependency.

# tox_uv/_venv.py:185
uv_imp = "" if (imp and imp == "cpython") else imp

Environment

  • OS: Windows
  • Installed Pythons: PyPy 3.10 and CPython 3.10
  • PATH (trimmed to only Python versions):
C:\Program Files\Python312;C:\Program Files\Python312\Scripts;C:\Users\Kurt\AppData\Roaming\Python\Python312\Scripts;C:\Program Files\pypy310
Output of pip list of the host Python, where tox is installed
$ C:\Users\Kurt\.local\pipx\venvs\tox\Scripts\python.exe -m pip list
Package       Version
------------- -------
cachetools    5.5.0
chardet       5.2.0
colorama      0.4.6
distlib       0.3.9
filelock      3.16.1
packaging     24.2
pip           24.3.1
platformdirs  4.3.6
pluggy        1.5.0
pyproject-api 1.8.0
setuptools    69.1.0
tox           4.23.2
tox-uv        1.16.1
uv            0.5.10
virtualenv    20.28.0
wheel         0.42.0

Output of running tox

Output of tox -rvv

See reproducer below

Minimal example

On Windows:

  • Install CPython 3.10 for all users to C:\Program Files\Python 3.10\.
  • For lack of an installer, extract PyPy 3.10 from its zip file and put it in C:\Program Files\pypy310
  • Set the PATH so that PyPy 3.10 is on the path but CPython 3.10 isn't. (For me, on Windows, only one CPython and one PyPy version are on my path; the others are discovered by tox as needed.)

Then, run the following in any directory:

$ tox -vvre py3.10
ROOT: 353 D setup logging to DEBUG on pid 4652 [tox\report.py:222]
ROOT: 516 W No tox.ini or setup.cfg or pyproject.toml or tox.toml found, assuming empty tox.ini at C:\Users\Kurt\Documents\dev\test [tox\config\source\discover.py:91]
py3.10: 554 W remove tox env folder C:\Users\Kurt\Documents\dev\test\.tox\py3.10 [tox\tox_env\api.py:325]
py3.10: 570 W venv> C:\Users\Kurt\.local\pipx\venvs\tox\Scripts\uv.exe venv -p 3.10 --allow-existing -v C:\Users\Kurt\Documents\dev\test\.tox\py3.10 [tox\tox_env\api.py:427]
DEBUG uv 0.5.10 (37b11ddb2 2024-12-17)
DEBUG Using Python request `3.10` from explicit request
DEBUG Searching for Python 3.10 in managed installations, search path, or registry
DEBUG Searching for managed installations at `C:\Users\Kurt\AppData\Roaming\uv\python`
DEBUG Found `cpython-3.12.8-windows-x86_64-none` at `C:\Program Files\Python312\python.exe` (search path)
DEBUG Skipping interpreter at `C:\Program Files\Python312\python.exe` from search path: does not satisfy request `3.10`
DEBUG Found `pypy-3.10.12-windows-x86_64-none` at `C:\Program Files\pypy310\python3.10.exe` (search path)
DEBUG Skipping alternative implementation pypy-3.10.12-windows-x86_64-none
DEBUG Found `pypy-3.10.12-windows-x86_64-none` at `C:\Program Files\pypy310\python3.exe` (search path)
Using PyPy 3.10.12 interpreter at: C:\Program Files\pypy310\python3.exe
Creating virtual environment at: .tox\py3.10
DEBUG Using base executable for virtual environment: C:\Program Files\pypy310\python3.exe
DEBUG Allowing existing directory
Activate with: .tox\py3.10\Scripts\activate
py3.10: 854 I exit 0 (0.28 seconds) C:\Users\Kurt\Documents\dev\test> C:\Users\Kurt\.local\pipx\venvs\tox\Scripts\uv.exe venv -p 3.10 --allow-existing -v C:\Users\Kurt\Documents\dev\test\.tox\py3.10 pid=12852 [tox\execute\api.py:286]
  py3.10: OK (0.30 seconds)
  congratulations :) (0.50 seconds)

I've tested a fix for this that always specifies the implementation when invoking uv (in the form cpython3.10 or pypy3.10) and have confirmed that uv correctly finds CPython and PyPy with that fix in place.

I'll submit a PR as soon as I figure out the remaining piece -- a test that demonstrates the issue and fixes it.

@kurtmckee kurtmckee added the bug Something isn't working label Dec 19, 2024
kurtmckee added a commit to kurtmckee/pr-tox-uv that referenced this issue Dec 19, 2024
kurtmckee added a commit to kurtmckee/pr-tox-uv that referenced this issue Dec 19, 2024
Doing so ensures that uv cannot find an unexpected implementation
(like PyPy) that matches based solely on the language version.

Fixes tox-dev#142
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant