-
-
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
virtualenv extends sys.path after sitecustomize.py #1861
Comments
Can you quote this? I can't seem to find a reference to this. |
Moreover, this does not happen for Python3:
|
This is kinda irrelevant, Python 3 has venv so has better semantics and expectation of what a virtual environment is. Python 2, on the other hand, does not offer such guarantees, so it's a bit less strict on what should happen, and a lot cannot be guaranteed given the limitations you can do within the system. |
This is not how virtual environments work, at least not with virtualenv. We offer strict guarantees about what must be on sys.path for a newly created virtual environment. purelib/platlib is guaranteed to be on the sys.path post creation, you removing these elements from sys.path during startup (inside the site/user customize) puts you out of contract, as you remove these guarantees. In the case of Python 3 we don't perform this check, but if anything that's the bug here; rather than on Python 2 we do. |
The last three paragraphs in the docs are:
which seems to me that the imports should be the last things happening at the end of the I understand your point of view but I also think that it removes flexibility. I am not saying it's a bad thing to have guarantees what is in |
The quotes explain how things happen, and the way I read at no point require that no path manipulation happen post site/usercustomize.
This is true only for python 2 though. Not sure what's a good solution here. That code needs to run to maintain guarantees, and defend against already-in-place OS path customization of Python versions unlikely to be changed going ahead. Perhaps the fixup operation could be skipped if a certain |
The latest virtualenv does some dark magic for sys.path in Python 2 so the BuildEnvironment is no longer isolated here. See: pypa/virtualenv#1861
The original question has been answered and we did not identify any actionable follow-up, so I'll close it for now. |
The latest virtualenv does some dark magic for sys.path in Python 2 so the BuildEnvironment is no longer isolated here. See: pypa/virtualenv#1861
The latest virtualenv does some dark magic for sys.path in Python 2 so the BuildEnvironment is no longer isolated here. See: pypa/virtualenv#1861
Let's imagine a situation when I know exactly what I need to have in
sys.path
. An obvious choice, in that case, would be to implement it insitecustomize.py
module because according to Python docssitecustomize.py
orusercustomize.py
should be the last place wheresys.path
is altered before a script starts.I cannot achieve that with Python 2 virtualenv because it alters
sys.path
aftersite
module is reloaded andsitecustomize.py
module is processed.Reproducer preparation: simple
sitecustomize.py
with two debug prints and a regular virtual environment with Python 2.When I run the Python from the testvenv with
sitecustomize.py
loaded, virtualenv adds its site-packages paths into sys.path aftersitecustomize.py
is loaded:The code causing this is there (see the order of the commands):
virtualenv/src/virtualenv/create/via_global_ref/builtin/python2/site.py
Lines 39 to 56 in f99353c
It's not possible to simply move the call to
reload
to the end because thesite
module needs to be reloaded sooner to loadaddsitedir
function.Context:
sitecustomize
is used in pip tests to create an isolated virtual environment but with the latest virtualenv, it isn't isolated.The text was updated successfully, but these errors were encountered: