Include PYTHONPATH directories in package scanning#6
Merged
zackverham merged 6 commits intoposit-dev:mainfrom Apr 27, 2026
Merged
Conversation
When PYTHONPATH is set (e.g., via supervisor.sh environment modules), packages installed in those directories are visible to pip but not to picopip's get_site_package_paths(). This causes false "missing packages" errors when picopip is used to validate that a venv contains all required packages. This extends get_site_package_paths() to also scan directories from the PYTHONPATH environment variable, gated behind the existing include_system_packages flag for consistency with system site-packages. Ref: posit-dev/connect#38951 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Rename unused `site` to `_site` in test destructuring (RUF059) - Move `import os` to module level (PLC0415) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Extract PYTHONPATH scanning into a dedicated helper function to stay within ruff's complexity limits (C901 max 12, PLR0912 max 12 branches). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The for/if dedup loops for system packages and PYTHONPATH each count as 2 branches. Extract into a shared _extend_unique helper to bring get_site_package_paths under ruff's C901/PLR0912 limits. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
edavidaja
reviewed
Apr 24, 2026
edavidaja
approved these changes
Apr 24, 2026
Co-authored-by: E. David Aja <edavidaja@hey.com>
tdstein
reviewed
Apr 27, 2026
Comment on lines
+145
to
+146
| if pp.exists() and pp.is_dir(): | ||
| scan_paths.append(pp) |
There was a problem hiding this comment.
Latest docs says...
In addition to normal directories, individual PYTHONPATH entries may refer to zipfiles containing pure Python modules (in either source or compiled form). Extension modules cannot be imported from zipfiles.
Do we need to support zipfiles here?
https://docs.python.org/3/using/cmdline.html#environment-variables
Contributor
Author
There was a problem hiding this comment.
potentially - though I'd prefer to follow-up w/ a new issue and get this merged, we just tested in their dev environment and the patch worked.
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
When
PYTHONPATHis set (e.g., viasupervisor.shenvironment modules in Posit Connect), packages installed in those directories are visible topipbut not to picopip'sget_site_package_paths(). This causes false "missing packages" errors when picopip is used to validate that a venv contains all required packages.This extends
get_site_package_paths()to also scan directories from thePYTHONPATHenvironment variable, gated behind the existinginclude_system_packagesflag for consistency with how system site-packages are handled.Context
This fixes a regression in Posit Connect where Python apps fail after upgrade when packages exist in global
PYTHONPATHdirectories.Changes
src/picopip.py: After scanning system site-packages, also iterate overPYTHONPATHentries and include any that exist as directories. UsesPath.resolve()to normalize paths for deduplication.tests/test_packages_discovery.py: 9 new tests covering inclusion, exclusion, empty/unset/nonexistent/multiple PYTHONPATH values, and end-to-end package discovery.Test results
All 56 tests pass (17 existing discovery + 9 new PYTHONPATH + 30 other).
🤖 Generated with Claude Code