Skip to content
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

fix(PATH): push PATH updates into os.environ on change #5054

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

gforsyth
Copy link
Collaborator

This issue was raised in
#5050.

If users (or xontribs) make use of subprocess, the PATH available
to subprocess is the value of PATH in os.environ, which is set at
the first import of os.environ.

This means (meant) that if a user updates their PATH in xonshrc,
those changes aren't visible to a bare subprocess call.
(This is what UPDATE_OS_ENVIRON is nominally for, but since changes to
PATH are mutating a mutable object, we don't hit any of the
__setitem__ checks in the env object).

So, instead, I've added an explicit call to update the os.environ
value of PATH after each mutating call to our EnvPath class, so this
should also work for the various _PATH variables (e.g. LDD_LIBRARY_PATH).

For community

⬇️ Please click the 👍 reaction instead of leaving a +1 or 👍 comment

@gforsyth gforsyth force-pushed the gil/update_environ_path branch 6 times, most recently from 93a0d39 to a6ebe19 Compare February 16, 2023 13:44
@gforsyth gforsyth force-pushed the gil/update_environ_path branch 2 times, most recently from 64b907d to 9ba5e12 Compare July 21, 2023 18:17
events needs to be free from as many internal dependencies as possible
to allow early import
This issue was raised in
xonsh#5050.

If users (or `xontribs`) make use of `subprocess`, the `PATH` available
to `subprocess` is the value of `PATH` in `os.environ`, which is set at
the first import of `os.environ`.

This means (meant) that if a user updates their `PATH` in `xonshrc`,
those changes aren't visible to a bare `subprocess` call.
(This is what `UPDATE_OS_ENVIRON` is nominally for, but since changes to
`PATH` are mutating a mutable object, we don't hit any of the
`__setitem__` checks in the env object).

So, instead, I've added an explicit call to update the `os.environ`
value of `PATH` after each mutating call to our `EnvPath` class, so this
should also work for the various `_PATH` variables (e.g. `LDD_LIBRARY_PATH`).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants