Skip to content

[pathfinder] Fix site-packages search order for venv created with --system-site-packages#1717

Merged
rwgk merged 1 commit intoNVIDIA:mainfrom
rwgk:pathfinder_site_packages_search_order_fix
Mar 4, 2026
Merged

[pathfinder] Fix site-packages search order for venv created with --system-site-packages#1717
rwgk merged 1 commit intoNVIDIA:mainfrom
rwgk:pathfinder_site_packages_search_order_fix

Conversation

@rwgk
Copy link
Collaborator

@rwgk rwgk commented Mar 4, 2026

Fixes #1716

Fix

Updated find_sub_dirs_all_sitepackages() to detect when running in a virtual environment (by checking if sys.prefix != sys.base_prefix) and insert user-site-packages at the correct position:

  • In a venv: Insert user-site-packages at index 1 (after venv site-packages, before system site-packages) per PEP 405
  • Outside a venv: Insert user-site-packages at index 0 (before system site-packages) per PEP 370

Testing

Added three test cases to test_utils_find_sub_dirs.py:

  1. test_find_sub_dirs_all_sitepackages_venv_order: Verifies correct ordering (venv → user → system) in a venv with --system-site-packages
  2. test_find_sub_dirs_all_sitepackages_non_venv_order: Verifies correct ordering (user → system) outside a venv
  3. test_find_sub_dirs_all_sitepackages_venv_first_match: Ensures venv site-packages are searched before user site-packages

…ixes NVIDIA#1716)

In a venv created with --system-site-packages, user-site-packages were
being searched before the virtual environment's site-packages, which
violates PEP 405.

The fix ensures that:
- In a venv: venv site-packages come first, then user-site-packages,
  then system site-packages (PEP 405)
- Outside a venv: user-site-packages come before system site-packages
  (PEP 370)

Added tests to verify the correct ordering in both scenarios.

Made-with: Cursor
@copy-pr-bot
Copy link
Contributor

copy-pr-bot bot commented Mar 4, 2026

Auto-sync is disabled for ready for review pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@rwgk
Copy link
Collaborator Author

rwgk commented Mar 4, 2026

/ok to test

@rwgk rwgk self-assigned this Mar 4, 2026
@rwgk rwgk added the cuda.pathfinder Everything related to the cuda.pathfinder module label Mar 4, 2026
@rwgk rwgk requested a review from cpcloud March 4, 2026 08:27
@github-actions

This comment has been minimized.

Copy link
Contributor

@cpcloud cpcloud left a comment

Choose a reason for hiding this comment

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

Looks good: fixes the venv (PEP 405) vs user-site (PEP 370) site-packages ordering for #1716 and adds targeted tests. Local Pixi run for cuda_pathfinder is clean. The aarch64 failures appear infra-related (apt mirror sync / GitHub API 502) rather than caused by this change.

@rwgk rwgk merged commit 244738a into NVIDIA:main Mar 4, 2026
168 of 171 checks passed
@rwgk rwgk deleted the pathfinder_site_packages_search_order_fix branch March 4, 2026 16:37
@github-actions
Copy link

github-actions bot commented Mar 4, 2026

Doc Preview CI
Preview removed because the pull request was closed or merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cuda.pathfinder Everything related to the cuda.pathfinder module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG][pathfinder] Incorrect site-packages search order for venv created with --system-site-packages

2 participants