Skip to content

Use pathlib in cuda.pathfinder._headers (part 8 of #2410) - #2536

Open
LeSingh1 wants to merge 1 commit into
NVIDIA:mainfrom
LeSingh1:pathlib-headers-part8
Open

Use pathlib in cuda.pathfinder._headers (part 8 of #2410)#2536
LeSingh1 wants to merge 1 commit into
NVIDIA:mainfrom
LeSingh1:pathlib-headers-part8

Conversation

@LeSingh1

@LeSingh1 LeSingh1 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Part 8 of #2410 (os.path -> pathlib.Path), covering cuda_pathfinder/cuda/pathfinder/_headers.

This is the last un-migrated corner of cuda.pathfinder runtime code that isn't already
covered by an open part of the series.

What changed

  • _locate_in_anchor_layout() and resolve_conda_anchor() build and return Path
    objects, and their anchor arguments accept str or any os.PathLike[str] (per your
    note on Migrate from os.path to pathlib.Path #2410 about widening what we accept).
  • The os.path.isfile(os.path.join(...)) probes become (dir / name).is_file(), which
    makes the _joined_isfile helper unnecessary.
  • LocatedHeaderDir.abs_path stays a str: it is public API (LocatedHeaderDir is
    re-exported from cuda.pathfinder), so the find steps convert at the boundary, the
    same way Use pathlib in cuda.pathfinder._static_libs (part 2 of #2410) #2493 does for LocatedBitcodeLib/LocatedStaticLib.

Two deliberate exceptions, flagged for review

  1. _abs_norm() keeps os.path.abspath(). pathlib has no purely lexical
    normalization: Path.resolve() follows symlinks, which would change the reported
    header directory under the very common /usr/local/cuda -> /usr/local/cuda-<ver>
    layout, and Path.absolute() does not collapse ... I'd rather leave one clearly
    commented os.path call here than silently change what the public API returns.

    While there, the wrapping os.path.normpath() is dropped as redundant: both
    posixpath.abspath and ntpath.abspath already normalize.

  2. glob.glob() stays for the descriptor catalog's glob patterns. Only the
    os.path parts of those expressions move to Path. Path.glob() is not a drop-in
    replacement (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 a
    behavior change unrelated to this issue.

Following your call on #2410, the single-file is_file() probes keep pathlib's error
behavior rather than being wrapped to mimic os.path.isfile()'s "any stat error means
False".

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.py exercises all five find
steps, including the conda targets/*/include layout and the CTK-root canary fallback.

  • pytest cuda_pathfinder/tests — same pass/fail set as upstream/main on this machine
    (the only failures are the ones that need a real CUDA install).
  • mypy cuda/pathfinder/_headers/ — no new errors (the two pre-existing
    redundant-cast errors in header_descriptor.py are untouched and out of scope).
  • ruff check and ruff format --check clean on both files.

Refs #2410.

@copy-pr-bot

copy-pr-bot Bot commented Aug 9, 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 9, 2026
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
LeSingh1 force-pushed the pathlib-headers-part8 branch from 22d2309 to 50c51d4 Compare August 9, 2026 01:22
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.

1 participant