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 accidental changes to PYTHONPATH in os.environ #639

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

xavth
Copy link

@xavth xavth commented Jan 4, 2024

When generating an environment dict for subprocess calls to pip, os.environ was accidentally modified despite efforts to copy it and modify only the copy, as copy.copy(os.environ) is not enough.

Quick proof in a python shell:

>>> import os
>>> import copy
>>> env = copy.copy(os.environ)
>>> 'abc' in os.environ
False
>>> env['abc'] = 'xyz'
>>> 'abc' in os.environ
True

When generating an environment dict for subprocess calls to pip,
os.environ was accidentally modified despite efforts to copy it
and modify only the copy, as copy.copy(os.environ) is not enough.
@perrinjerome
Copy link
Contributor

That's true. pylint has a linter rule for this https://pylint.readthedocs.io/en/latest/user_guide/messages/warning/shallow-copy-environ.html

BTW, in the discussions from https://bugs.python.org/issue15373 this nice approach is discussed:

    exit_code = subprocess.call(list(args), env=dict(os.environ, PYTHONPATH=python_path))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants