-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Created virtual env does not honour sys.base_prefix correctly #2770
Comments
It seems to me there are two separate use cases related to symlinks (as well as #2684, which is related to canonicalisation of filenames, rather than symlinks). In #2682, the use case is running In the case here, though, you are running To be honest, I don't think there's a clear "one size fits all" solution here. We could say that if the python executable itself is a symlink, then resolve it, but if a component is a symlink, then don't. But that seems fairly hacky, and prone to errors if there are situations we haven't considered. My personal experience with symlinks is on Windows, where if an exe loads a DLL saved alongside it, a symlink won't run as the OS doesn't follow the symlink to find the DLL. So by analogy with that, I'd have been inclined to say that #2682 wasn't a bug, but was simply a consequence of how symlinks work when trying to find dependent files relative to the executable. But I'm clearly in a minority here, as #2682 was accepted and fixed. I don't have a good answer here, except to say that we should probably follow the behaviour of the core |
This is interesting, I thought it was other way around and we do novel stuff here which |
I'd say that behaviour should be consistent, but quality of life details (like performance, additional shell integrations) are what distinguishes |
I thought the same.
Issues were filed in both cpython & virtualenv (with a link to the cpython issue). While the cpython issue is still opened, the virtualenv one was "fixed" introducing a regression in other use-cases. If the aim of
As of now, there are 3 identified use-cases related to symlinks that might be addressed by the hack mentioned (I don't know enough about the Windows one to be sure nothing else would be required). |
Issue
When creating a virtual environment, the base prefix of the virtual environment should be the same as the base prefix of the Python that is creating the virtual environment - there should be no additional resolve steps with regards to symlinks.
This behaviour is seen in
venv
, and was implemented as expected until #2686, where symlinks were resolved.Why is this important?
In big (scientific) institutions, it is common to have a network mounted filesystem which can be access from all managed machines. This could be to mount a homespace, or to mount some data etc. (I've seen both). To scale this up, it is necessary to have multiple filesystem servers all using the same underlying storage. Machines are then clustered to point to different servers, but the user doesn't know which server a machine is talking to. When combining this with something such as autofs, you find that the server being contacted is in the path (e.g.
/nfs/some-machine/
), and to smoothen this out accross machines, the managed machines get a canonical symlink (e.g./project/{my-project}
which symlinks to the specific machine mountpoint). Essentially:With this setup, you can create a virtual environment in
/project/my-project
which works on both machines IFF the symlink is not resolved. This is the behaviour of CPython, and also the behaviour ofvenv
andvirtualenv<20.25.1
.Reproducer
Written in the form of a pytest (w validation against
venv
also):The result is a pass in
20.25.0
and a fail since:It is worth noting that the implementation of #2686 has a bug in the fact that the symlink at
dest_venv / 'bin' / 'python'
points tosys.base_prefix / 'bin' / 'python'
, and not the resolved symlink location ofsys.base_prefix
. Therefore thehome
value is inconsistent with the symlink that is created byvirtualenv
. The test validates this.Implications
There are two issues which #2686 closed:
To be honest, I'm not sure what #2682 is asking for. Perhaps is is a request for behaviour that is different for
venv
and also the std library (wrt.sys.base_prefix
) @mayeut.For #2684, I also don't fully understand the reason for this being a
virtualenv
issue (this is my problem, not a problem with the issue itself) - and somebody who knows what the correct behaviour should be would need to chime in (perhaps @ofek?).The text was updated successfully, but these errors were encountered: