-
-
Notifications
You must be signed in to change notification settings - Fork 31k
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
sys._base_executable resolves symlinks too eagerly, resulting in undesirable venv from venv behaviour #128670
Comments
There is also some useful context on cases that are covered by |
As of GH-127972, does this even really matter? Most users will be using Python installations with a shared libpython, so we can know the base prefix from there. Realistically, the Apart from the All these complications exist in modern system that adopt a non-standard installation model. It seems reasonable to me that for these complicated scenarios to be supported to ask that we are running in an installation with a shared libpython. That should be working right now in |
In uv, for the relocatable builds, we now resolve symlinks iteratively until we find a path that "would" be a valid home, by replicating some of the logic used in CPython startup. This tends to "do the right thing" in practice. (Edit: missed that this was stated above in #128670 (comment), but happy to answer questions about that approach.) |
Bug report
Bug description:
In #106045, the use case of putting a symlink in
/usr/local/bin
to a Python binary from another prefix was highlighted. For homebrew, this use case is used with the idea that the symlink is the public interface/location, and the prefix where it is actually installed is an implementation detail (and can change over time) (more details in astral-sh/uv#1640).#106045 seems to have now been resolved by #127974 (I wrote a test for that). The originating issue proposed a solution which would fix the problem with the broken virtual environment in that case, but would actually break the aforementioned homebrew example by eagerly resolving the symlinked executable and using the resolved path to determine the
home
value inpyvenv.cfg
- thereby exposing the "internal" prefix intopyvenv.cfg
.The problem I am reporting here is that
sys._base_executable
eagerly resolves symlinks ingetpath.py
venv
,virtualenv
anduv
all usesys._base_executable
to determine thehome
locationhome
location will be resolved, whereas the first will not be. Thereby bleeding the implementation detail once more.In
uv
, the behaviour was solidified in astral-sh/uv#8433 to avoid exposing the internal prefix in the venv. Note thatvirtualenv
is (accidentally?) now exposing the internal prefix even on the first virtual environment pypa/virtualenv#2770.To reproduce this:
And observe that the second venv's home is not
/tmp/public/bin
but the "internal detail" one.A quick test for getpath, and a complete test for venv are included below (both failing):
cc @FFY00 following on from our conversation in #127974 (comment) (I would love to get a commit for the tests, if not the fix 😜).
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
The text was updated successfully, but these errors were encountered: