Skip to content

fix: PYTHONPATH values set in host can break pdm run#3746

Open
frostming wants to merge 2 commits intomainfrom
frostming/issue3742
Open

fix: PYTHONPATH values set in host can break pdm run#3746
frostming wants to merge 2 commits intomainfrom
frostming/issue3742

Conversation

@frostming
Copy link
Collaborator

Fixes #3742

Signed-off-by: Frost Ming me@frostming.com

Pull Request Checklist

  • A news fragment is added in news/ describing what is new.
  • Test cases added for changed code.

Describe what you have changed in this PR.

Fixes #3742

Signed-off-by: Frost Ming <me@frostming.com>
@frostming frostming force-pushed the frostming/issue3742 branch from 04faaff to 8f97794 Compare March 5, 2026 09:41
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Copy link
Collaborator Author

@frostming frostming Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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
Copy link

codecov bot commented Mar 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.88%. Comparing base (b3114cb) to head (cfc1aff).

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     
Flag Coverage Δ
unittests 85.74% <100.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

PYTHONPATH values set in host can break pdm run

1 participant