Use pathlib in cuda.pathfinder._headers (part 8 of #2410) - #2536
Open
LeSingh1 wants to merge 1 commit into
Open
Conversation
Contributor
Converts the header search modules to pathlib.Path: - `_locate_in_anchor_layout` and `resolve_conda_anchor` now build and return `Path` objects; the anchor arguments accept `str` or any `os.PathLike[str]`. - `os.path.isfile` / `os.path.join` probes become `(dir / name).is_file()`, which lets the `_joined_isfile` helper go away. - `LocatedHeaderDir.abs_path` stays a `str` (it is public API), so the find steps convert at the boundary. Two deliberate exceptions: - `_abs_norm` keeps `os.path.abspath`. pathlib has no purely lexical normalization: `Path.resolve()` follows symlinks, which would change the reported header directory for the common `/usr/local/cuda -> /usr/local/cuda-<ver>` layout. `os.path.normpath` around `os.path.abspath` was redundant (posixpath/ntpath `abspath` already normalize), so that call is dropped. - `glob.glob` stays for the catalog's glob patterns; only the `os.path` parts of those expressions move to `Path`. Per the discussion on NVIDIA#2410, single-file `is_file()` probes are left with pathlib's error behavior rather than wrapped to mimic `os.path.isfile`'s "any stat error means False". No behavior change intended; the existing cuda_pathfinder test suite covers these paths (`tests/test_find_nvidia_headers.py`).
LeSingh1
force-pushed
the
pathlib-headers-part8
branch
from
August 9, 2026 01:22
22d2309 to
50c51d4
Compare
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.
Part 8 of #2410 (
os.path->pathlib.Path), coveringcuda_pathfinder/cuda/pathfinder/_headers.This is the last un-migrated corner of
cuda.pathfinderruntime code that isn't alreadycovered by an open part of the series.
What changed
_locate_in_anchor_layout()andresolve_conda_anchor()build and returnPathobjects, and their anchor arguments accept
stror anyos.PathLike[str](per yournote on Migrate from os.path to pathlib.Path #2410 about widening what we accept).
os.path.isfile(os.path.join(...))probes become(dir / name).is_file(), whichmakes the
_joined_isfilehelper unnecessary.LocatedHeaderDir.abs_pathstays astr: it is public API (LocatedHeaderDirisre-exported from
cuda.pathfinder), so the find steps convert at the boundary, thesame way Use pathlib in cuda.pathfinder._static_libs (part 2 of #2410) #2493 does for
LocatedBitcodeLib/LocatedStaticLib.Two deliberate exceptions, flagged for review
_abs_norm()keepsos.path.abspath(). pathlib has no purely lexicalnormalization:
Path.resolve()follows symlinks, which would change the reportedheader directory under the very common
/usr/local/cuda -> /usr/local/cuda-<ver>layout, and
Path.absolute()does not collapse... I'd rather leave one clearlycommented
os.pathcall here than silently change what the public API returns.While there, the wrapping
os.path.normpath()is dropped as redundant: bothposixpath.abspathandntpath.abspathalready normalize.glob.glob()stays for the descriptor catalog's glob patterns. Only theos.pathparts of those expressions move toPath.Path.glob()is not a drop-inreplacement (it needs a separate base directory for absolute patterns, and it does
not skip dot-entries the way
glob.glob()does), so swapping it in would be abehavior change unrelated to this issue.
Following your call on #2410, the single-file
is_file()probes keep pathlib's errorbehavior rather than being wrapped to mimic
os.path.isfile()'s "any stat error meansFalse".Verification
No behavior change is intended, so there is no new test; the existing suite is the
check.
cuda_pathfinder/tests/test_find_nvidia_headers.pyexercises all five findsteps, including the conda
targets/*/includelayout and the CTK-root canary fallback.pytest cuda_pathfinder/tests— same pass/fail set asupstream/mainon this machine(the only failures are the ones that need a real CUDA install).
mypy cuda/pathfinder/_headers/— no new errors (the two pre-existingredundant-casterrors inheader_descriptor.pyare untouched and out of scope).ruff checkandruff format --checkclean on both files.Refs #2410.