fix: PYTHONPATH values set in host can break pdm run#3746
fix: PYTHONPATH values set in host can break pdm run#3746
pdm run#3746Conversation
Fixes #3742 Signed-off-by: Frost Ming <me@frostming.com>
04faaff to
8f97794
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 04faaff97a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| check_project_file(project) | ||
| project_env = project.environment | ||
| this_path = project_env.get_paths()["scripts"] | ||
| os.environ.pop("PYTHONPATH", None) # Don't inherit PYTHONPATH from the parent process |
There was a problem hiding this comment.
Avoid clearing PYTHONPATH for non-local environments
This unconditional PYTHONPATH removal changes pdm run behavior for virtualenv/system projects: PythonEnvironment.process_env only adds PATH/venv vars and does not restore PYTHONPATH (src/pdm/environments/python.py), so shell-provided paths are now silently discarded. That breaks common workflows like PYTHONPATH=src pdm run pytest (or scripts that expand ${PYTHONPATH}) where imports relied on inherited paths, even though the original bug only concerned PEP 582 leakage.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
@cgranade Do you think this is a breaking change? I assume there are use cases that rely on PYTHONPATH to run a script correctly, although I personally don't recommend manipulating PYTHONPATH manually.
…ent, and PYTHONPATH handling Signed-off-by: Frost Ming <me@frostming.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3746 +/- ##
==========================================
- Coverage 85.89% 85.88% -0.02%
==========================================
Files 118 118
Lines 12374 12372 -2
Branches 2060 2060
==========================================
- Hits 10629 10626 -3
Misses 1173 1173
- Partials 572 573 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Fixes #3742
Signed-off-by: Frost Ming me@frostming.com
Pull Request Checklist
news/describing what is new.Describe what you have changed in this PR.