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
Subprocesses are not fully isolated when --extend-pythonpath is used #138
Comments
Just checking again; do you (the maintainers) have a preference? |
Hi @itamarst, Sorry for the delay in getting back to you! Times are strange. The reason that I implemented PYTHONPATH handling for shiv as an extension was to ensure that the behavior was consistent between the calling program and the subprocess. Consider this example:
If I create a
As you can see, a
The
As you can see, now our frozen environment comes before the Now, if we add a new module to our package named
Normal
So, pretty similar output to before except that, as expected, the child process doesn't have the frozen environment from the
🚨 If we are adding the frozen environment's site-packages to PYTHONPATH, it should be searched first. IMO I believe the behavior that you desire can be accomplished via https://github.com/linkedin/shiv/compare/itamarst-pythonpath-fixes which just re-orders the PYTHONPATH handling logic to ensure that the entire manipulated We have to use either the whole Here's how it behaves with that diff:
So now the frozen environment's site-packages is on
That also looks good to me, what do you think? |
Thanks for the thorough response, and for propsing a fix! And no need to apologize for late reply. The proposed fix does seem like it makes subprocesses have a more consistent-with-parent-PYTHONPATH, yes. Perhaps unrelated, or perhaps a way to make the last example at least less haphazard: the fact that path order depends on the name of the directory ("site-packages") makes me feel a little uneasy. What were the circumstances that motivated this particular logic? Virtualenvs, for example, don't modify the PYTHONPATH env variable at all, they work by having a different |
Hi again @itamarst,
Putting the dependencies managed by So, the way we ensure that the dependencies that you include in your
|
I may not have been clear, sorry. The specific thing that bothers me a little is the logic described by your statement "if our PYTHONPATH variable contains a site-packages or dist-packages directory, that changes the outcome". That is, directories with particular names have special logic (somewhere). |
Oh sure, but that's not something that we specifically look for in PYTHONPATH, we always dice up the I think the lack of clarity is that we are using PYTHONPATH as a means of informing subprocesses about the dependencies included by |
shiv/src/shiv/bootstrap/__init__.py Line 129 in 526ebbe
Back to the issue at hand, your proposed patch seems reasonable, if you want to merge it. Thanks for working on this! |
It is useful to be able to launch subprocesses with the exact same PYTHONPATH as the parent
process, but it doesn't seem possible with shiv at the moment.
For example, if I have a virtualenv, and I either
activate
it or setPATH
to use it, Python subprocesses will import from the virtualenv.Shiv's
--extend-pythonpath
is close to that behavior, but not sufficient. Specifically, when the option is enabled, PYTHONPATH for subprocesses is extended (shiv/src/shiv/bootstrap/__init__.py
Lines 167 to 169 in 526ebbe
The parent process, in contrast, adds the shiv site-packages to the start of
sys.path
:shiv/src/shiv/bootstrap/__init__.py
Lines 171 to 173 in 526ebbe
I can think of two ways to address this:
--extend-pythonpath
to match shiv's internal behavior. This is not backwards-compatible, however.--override-pythonpath
maybe?). Potentially this would also involve deprecating the old option, but perhaps some people have a reason for that variant too.If you have a preference, I can submit a PR with your preferred option.
The text was updated successfully, but these errors were encountered: