Skip to content

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

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

rwgk merged 1 commit into
NVIDIA:mainfrom
rwgk:pathfinder_site_packages_search_order_fix

Conversation

@rwgk

@rwgk rwgk commented Mar 4, 2026

Copy link
Copy Markdown
Contributor

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-pr-bot Bot commented Mar 4, 2026

Copy link
Copy Markdown
Contributor

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

rwgk commented Mar 4, 2026

Copy link
Copy Markdown
Contributor Author

/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.

@cpcloud cpcloud left a comment

Copy link
Copy Markdown
Contributor

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

github-actions Bot commented Mar 4, 2026

Copy link
Copy Markdown
Contributor
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