astral-sh / uv

An extremely fast Python package installer and resolver, written in Rust.
https://astral.sh/
Apache License 2.0
14.54k stars 410 forks source link

`uv venv` doesn't add PyPy executables #2092

Open charliermarsh opened 4 months ago

charliermarsh commented 4 months ago

We don't officially support PyPy right now, this is more a note for the future, but we need to include a variety of pypy binaries / symlinks:

❯ ls .venv/bin
Activate.ps1  activate      activate.csh  activate.fish pip           pip3          pip3.9        pypy          pypy3         pypy3.9       python        python3       python3.9
charliermarsh commented 4 months ago

@gaborbernat - A related question: how does virtualenv "know" to create site-packages for PyPy at .venv/lib/pypy3.10/site-packages instead of .venv/lib/python3.10/site-packages? Is that encoded in virtualenv somewhere? Or is it read from the interpreter? Was trying to find it.

gaborbernat commented 4 months ago

That's done here https://github.com/pypa/virtualenv/blob/main/src/virtualenv/create/via_global_ref/builtin/pypy/pypy3.py#L31 and https://github.com/pypa/virtualenv/blob/main/src/virtualenv/create/via_global_ref/builtin/pypy/common.py#L41. It knows to do that just for PyPy because of https://github.com/pypa/virtualenv/blob/main/src/virtualenv/create/via_global_ref/builtin/pypy/common.py#L13. The purelib/platlib paths are using the sysconfig information, which is inquired as part of https://github.com/pypa/virtualenv/blob/main/src/virtualenv/discovery/py_info.py#L80-L103.

Note that .venv/lib/pypy3.10/site-packages is often refered to as purelib, and in CPython by default this aligns up with platlib, but CPython allows distributions to move this to their desired path. So ultimately, the question is: When you say .venv/lib/pypy3.10/site-packages are you refering to platlib or purelib?

charliermarsh commented 4 months ago

Ah yeah, I'm referring to purelib. (Though I haven't really done the work yet to understand what happens when you, e.g., pip uninstall and purelib and platlib are not the same thing.)

If sysconfig is returning the purelib and platlib paths for the invoked interpreter, where / how do those get translated to paths for the virtualenv? E.g.:

>>> sysconfig.get_paths(scheme="venv")
{'stdlib': '/Users/crmarsh/.local/share/rtx/installs/python/3.12.0/lib/python3.12', 'platstdlib': '/Users/crmarsh/.local/share/rtx/installs/python/3.12.0/lib/python3.12', 'purelib': '/Users/crmarsh/.local/share/rtx/installs/python/3.12.0/lib/python3.12/site-packages', 'platlib': '/Users/crmarsh/.local/share/rtx/installs/python/3.12.0/lib/python3.12/site-packages', 'include': '/Users/crmarsh/.local/share/rtx/installs/python/3.12.0/include/python3.12', 'platinclude': '/Users/crmarsh/.local/share/rtx/installs/python/3.12.0/include/python3.12', 'scripts': '/Users/crmarsh/.local/share/rtx/installs/python/3.12.0/bin', 'data': '/Users/crmarsh/.local/share/rtx/installs/python/3.12.0'}
gaborbernat commented 4 months ago

That depends. You can get the schema and inject your config vars of sys.prefix to calculate where it should go.

gaborbernat commented 4 months ago

See https://github.com/pypa/virtualenv/blob/main/src/virtualenv/discovery/py_info.py#L224

charliermarsh commented 4 months ago

Thank you!

charliermarsh commented 4 months ago

Filed some info in https://github.com/astral-sh/uv/issues/2095. (No obligation to chime in there.)

charliermarsh commented 3 months ago

@edgarrmondragon - when you’re in a PyPy virtualenv, do you typically invoke Python as “pypy” or “python”? I’m trying to make some decisions around this with respect to #2316.

edgarrmondragon commented 3 months ago

@edgarrmondragon - when you’re in a PyPy virtualenv, do you typically invoke Python as “pypy” or “python”? I’m trying to make some decisions around this with respect to #2316.

Actually, always as python or python3.x