Skip to content

Conversation

@silvanocerza
Copy link
Contributor

Summary

Should fix #2092.

This PR changes uv venv so it also creates symlinks to pypy on Unix and copies executables on Windows when creating a new environment using PyPy.

I found a bit of discrepancy between creation of a venv using python and uv, as using python brings all the executables with it. While uv brings only those without any version number, at least on Windows. The behaviour is different on Unix as we take the versioned symlinks too.

Some examples below.

python -m venv generates the following Scripts folder.

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----         7/14/2024     15:41           2031 activate
-a----         7/14/2024     15:41           1029 activate.bat
-a----         7/14/2024     15:41           9033 Activate.ps1
-a----         7/14/2024     15:41            393 deactivate.bat
-a----         7/14/2024     15:40          27648 libffi-8.dll
-a----         7/14/2024     15:41       44290560 libpypy3.10-c.dll
-a----         7/14/2024     15:41         108424 pip.exe
-a----         7/14/2024     15:41         108424 pip3.10.exe
-a----         7/14/2024     15:41         108424 pip3.exe
-a----         7/14/2024     15:41          79360 pypy.exe
-a----         7/14/2024     15:41          79360 pypy3.10.exe
-a----         7/14/2024     15:41          79360 pypy3.10w.exe
-a----         7/14/2024     15:41          79360 pypy3.exe
-a----         7/14/2024     15:41          79360 pypyw.exe
-a----         7/14/2024     15:41          79360 python.exe
-a----         7/14/2024     15:41          79360 python3.10.exe
-a----         7/14/2024     15:41          79360 python3.exe
-a----         7/14/2024     15:41          79360 pythonw.exe

uv venv instead generates this.

-a----         7/14/2024     16:27           3360 activate
-a----         7/14/2024     16:27           2251 activate.bat
-a----         7/14/2024     16:27           2627 activate.csh
-a----         7/14/2024     16:27           4191 activate.fish
-a----         7/14/2024     16:27           3875 activate.nu
-a----         7/14/2024     16:27           2766 activate.ps1
-a----         7/14/2024     16:27           2378 activate_this.py
-a----         7/14/2024     16:27           1728 deactivate.bat
-a----         7/13/2024     19:19          27648 libffi-8.dll
-a----         7/13/2024     19:19       44290560 libpypy3.10-c.dll
-a----         7/14/2024     16:27           1215 pydoc.bat
-a----         7/13/2024     19:19          79360 pypy.exe
-a----         7/13/2024     19:19          79360 pypyw.exe
-a----         7/13/2024     19:19          79360 python.exe
-a----         7/13/2024     19:19          79360 pythonw.exe

Test Plan

To verify the correct behaviour:

  1. Download and install PyPy from official website
  2. Call uv venv -p <path_to_pypy_>
  3. Run .\.venv\Scripts\activate on Windows or ./.venv/Scripts/activate on Unix
  4. Run pypy

I thought of writing some automated tests but I couldn't rely on uv python install command to install PyPy as it's not in the list of installable Python builds.

Comment on lines 356 to 357
WindowsExecutable::PyPy => "venvlauncher.exe",
WindowsExecutable::PyPyw => "venvwlauncher.exe",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea whether this is correct or not.

Reading a comment below I seemed to understand that the shims changed name in Python 3.13 but after installing it doesn't seem like it.

Also I think this shouldn't apply to PyPy for the time being since it supports up to Python 3.10 only.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment explaining this?

@silvanocerza silvanocerza changed the title Add pypy executables when calling uv venv Add pypy executables when calling uv venv Jul 14, 2024
@zanieb zanieb self-assigned this Jul 14, 2024
@zanieb
Copy link
Member

zanieb commented Jul 14, 2024

Here's a commit showing how we could add a CI test for this until we add support to the actual test suite 908eeb9

I think on Windows we generally assume all Python executables don't contain version numbers cc @konstin, interesting that Python creates them in virtual environments.

@konstin
Copy link
Member

konstin commented Jul 14, 2024

It looks like pypy always has pythonx.y.exe on windows, both in the archive and in the venv, and it's cpython-specific to omit the version number.

@silvanocerza
Copy link
Contributor Author

@zanieb new job added. Should I maybe add one for Windows too? I could actually do it all in a single job if I'm clever with matrix.

@konstin should I add the versioned binaries then?

@zanieb
Copy link
Member

zanieb commented Jul 15, 2024

I merged #5048 so we can have most of the test changes separate from here — lmk if the conflicts are a problem.

@zanieb
Copy link
Member

zanieb commented Jul 15, 2024

We could add one for Windows but let's do it separately as a follow-up pull request, I suspect it'll be a little painful.

@zanieb
Copy link
Member

zanieb commented Jul 15, 2024

And yeah I'd add the versioned binaries to match the standard behavior.

@zanieb zanieb added the enhancement New feature or improvement to existing functionality label Jul 15, 2024
@silvanocerza
Copy link
Contributor Author

@zanieb cool, will add the binaries then. I already handled the conflicts. 👍

@silvanocerza
Copy link
Contributor Author

PR ready. 👍

@zanieb zanieb merged commit c2ef825 into astral-sh:main Jul 15, 2024
@zanieb
Copy link
Member

zanieb commented Jul 15, 2024

Nice :)

@silvanocerza silvanocerza deleted the venv-add-pypy-exes branch July 15, 2024 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or improvement to existing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

uv venv doesn't add PyPy executables

3 participants