Fix transitive dependencies skipped from project environments - #6700
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a regression where Pipenv’s vendored pipdeptree initialization could leak Pipenv host paths into bundled pip subprocesses, causing pipenv install/sync to incorrectly skip locked transitive dependencies (e.g., packaging) in fresh project virtualenvs.
Changes:
- Guard vendored
pipdeptree/__main__.pypath bootstrapping behindif __name__ == "__main__"to prevent sys.path pollution on import while preservingpipenv graphbehavior. - Add/adjust unit + integration coverage to ensure import isolation and that a locked transitive dependency is installed into the project environment.
- Persist the fix in the vendoring patch and add a news fragment documenting the bugfix.
Reviewed changes
Copilot reviewed 3 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/test_vendor.py | Adds a regression test to ensure importing vendored pipdeptree does not extend sys.path. |
| tests/integration/test_install_basic.py | Updates an integration test to validate transitive packaging is present in the lock and importable in the venv. |
| tasks/vendoring/patches/vendor/pipdeptree-update-import.patch | Updates the vendoring patch so regenerated vendored sources keep the import-isolation fix (and related vendoring adjustments). |
| pipenv/vendor/pipdeptree/main.py | Applies the runtime fix by only extending sys.path when executed as __main__. |
| news/6698.bugfix.rst | Adds release-note entry describing the dependency-skipping regression and fix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+18
to
+32
| main_path = Path(pipenv.__file__).parent / "vendor" / "pipdeptree" / "__main__.py" | ||
| vendor_root = main_path.parents[1] | ||
| pipenv_install_root = vendor_root.parents[1] | ||
| paths = [str(vendor_root), str(pipenv_install_root)] | ||
| code = f""" | ||
| import json | ||
| import runpy | ||
| import sys | ||
|
|
||
| paths = {json.dumps(paths)} | ||
| before = {{path: sys.path.count(path) for path in paths}} | ||
| runpy.run_path({str(main_path)!r}, run_name="pipdeptree_import_test") | ||
| after = {{path: sys.path.count(path) for path in paths}} | ||
| print(json.dumps({{"before": before, "after": after}})) | ||
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
pipenv graphpackaginginstallThe pipdeptree 3.1.0 update made its package initializer import
__main__. Pipenv’s vendoring patch added host paths unconditionally in that module, so bundled pip could see distributions installed alongside Pipenv and incorrectly report them as already satisfied in a fresh project virtualenv.Validation
packaging==26.2pytestinto a fresh project environment and verified project-localpackagingpipenv graphstill succeedsFixes #6698.
Fixes #6699.