Skip to content

Use pathlib in cuda.pathfinder._static_libs (part 2 of #2410) - #2493

Open
LeSingh1 wants to merge 2 commits into
NVIDIA:mainfrom
LeSingh1:pathlib/static-libs
Open

Use pathlib in cuda.pathfinder._static_libs (part 2 of #2410)#2493
LeSingh1 wants to merge 2 commits into
NVIDIA:mainfrom
LeSingh1:pathlib/static-libs

Conversation

@LeSingh1

@LeSingh1 LeSingh1 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Follow-up to the review on #2489: the str-compatibility constraint applies only to the public API, so the finder internals now pass and return Path. str() is applied once, where abs_path is stored on LocatedStaticLib / LocatedBitcodeLib.

The rel-path constants are now forward-slash literals, matching site_packages_dirs in the same dicts.

One behaviour change: a CUDA_PATH or CONDA_PREFIX containing redundant separators now gives a normalized abs_path, because Path collapses them.

Verified on Linux CI: full pytest output byte-identical to the base commit apart from elapsed time (1276 passed, 4 skipped, 0 errors). Differential fuzzing against the previous revision — 16k lookups over randomized trees, comparing located paths and error text — shows no other difference.

Part 2 of #2410.

@copy-pr-bot

copy-pr-bot Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions Bot added the cuda.pathfinder Everything related to the cuda.pathfinder module label Aug 4, 2026
@mdboom mdboom self-assigned this Aug 7, 2026
@mdboom mdboom added enhancement Any code-related improvements P2 Low priority - Nice to have labels Aug 7, 2026
@mdboom mdboom added this to the cuda.pathfinder next milestone Aug 7, 2026
@mdboom
mdboom enabled auto-merge (squash) August 7, 2026 13:59
@mdboom

mdboom commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

/ok to test 8ed361d

@mdboom

mdboom commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

@LeSingh1: This PR has a non-trivial merge conflict. Would you mind resolving it?

Part 2 of the series proposed in NVIDIA#2410, following the same conversion
style as part 1 (NVIDIA#2489).

Path construction, joining, and filesystem predicates in
find_static_lib.py and find_bitcode_lib.py now go through pathlib.Path
instead of os.path string manipulation. Both modules keep importing os
solely for os.environ.get("CONDA_PREFIX").

Compatibility is preserved: every entry point still accepts str, and
every function that documents or returns str still returns str. Path is
used strictly as the internal representation and converted back with
str() at each return, so LocatedStaticLib.abs_path, LocatedBitcodeLib
.abs_path, find_static_lib() and find_bitcode_lib() are unchanged in
both type and value. No signature changes.

Signed-off-by: LeSingh1 <sshaurya914@gmail.com>
Follow-up to the review feedback on NVIDIA#2489: the str-compatibility constraint
applies only to the public API.

The try_* methods and _no_such_file_in_dir now work in Path throughout. str()
is applied once, where abs_path is stored on the public LocatedStaticLib and
LocatedBitcodeLib. The relative-path constants go from os.path.join(...) to
forward-slash literals, matching how site_packages_dirs is already written in
the same dicts; Path normalizes the separator on Windows.

One behavior change: a CUDA_PATH or CONDA_PREFIX containing redundant
separators ("//", "/.") now produces a normalized abs_path, because Path
collapses them. Differential fuzzing against the pre-revision code (16k lookups
over randomized trees, comparing located paths and full error text) shows no
other difference, and none at all when those variables are free of redundant
separators.

Signed-off-by: LeSingh1 <sshaurya914@gmail.com>
auto-merge was automatically disabled August 7, 2026 22:53

Head branch was pushed to by a user without write access

@LeSingh1
LeSingh1 force-pushed the pathlib/static-libs branch from 8ed361d to 11916d6 Compare August 7, 2026 22:53
@LeSingh1

LeSingh1 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main — conflict resolved in 11916d6.

The conflict was _SUPPORTED_STATIC_LIBS_INFO["cudadevrt"]. main replaced the static dict with _cudadevrt_info(), which resolves the Windows arch at call time via windows_python_arch() and adds the non-x64 fallbacks. I kept that version and applied only this PR's conversion to it:

"ctk_rel_paths": (str(Path("lib", arch_dir)),),
"conda_rel_paths": (str(Path("lib", arch_dir)), *conda_fallback_dirs),

so the arch-aware behaviour from main is preserved and the os.path.join calls inside it are gone. import os stays — os.environ is still used further down.

One thing I should flag rather than let you assume otherwise: I could not run the test suite locally to confirm. cuda_pathfinder cannot be imported on macOS at all — load_dl_linux.py binds dlinfo, which does not exist in libc here, so collection fails before any test runs. I verified the resolution by reading it and with py_compile; CI is the real check.

Happy to adjust if you would rather the helper stay on os.path.join and this PR skip that function.

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 enhancement Any code-related improvements P2 Low priority - Nice to have

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants