Skip to content

refactor(pathfinder): read CONDA_PREFIX in one place - #3630

Open
rparolin wants to merge 1 commit into
pathfinder-readability/20-remove-dead-dll-filterfrom
pathfinder-readability/21-one-conda-prefix-reader
Open

rparolin wants to merge 1 commit into
pathfinder-readability/20-remove-dead-dll-filterfrom
pathfinder-readability/21-one-conda-prefix-reader

Conversation

@rparolin

@rparolin rparolin commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

— codex on behalf of Ralf —

Description

Part 21 of 23 of a readability stack for cuda.pathfinder (stack: #3623 → #3602 → #3603 → #3604 → #3605 → #3606 → #3607 → #3608 → #3609 → #3610 → #3611 → #3613 → #3618 → #3619 → #3620 → #3621 → #3622 → #3627 → #3628 → #3629 → #3630 → #3631 → #3632). No behavior change.

Three finders read CONDA_PREFIX on their own, and each treated an empty value as unset: dynamic libraries, headers, and the shared static and bitcode search. get_conda_prefix() in _utils/env_vars.py now holds that rule, and the three call it.

It is not cached. Like the code it replaces, it reads the environment on every call.

The binary finder is left alone on purpose. It treats an empty CONDA_PREFIX as set, so switching it over would change behavior.

This PR adds a few lines instead of removing them. The gain is one place for the rule.

No behavior change.

Testing

  • Full cuda_pathfinder test suite at this commit: 1299 passed, 6 skipped (Linux, Python 3.14).
  • pre-commit clean, including mypy-pathfinder. mypy also passes with --platform win32.
  • The step-by-step comparisons against main are still byte-identical (Linux, simulated Windows x64 and arm64), and all 526 public-API scenarios give the same result as fix(pathfinder): check for an already-loaded library before searching the disk #3623.
  • Not run on Windows. Windows rules are exercised by tests that simulate Windows on Linux.

PLC Local Security Evidence (Advisory)

Local advisory checks only, run over the whole stack. Not release-gate results.

Check Status Tool Details
Secrets SKIP Pulse Secret Scanner scanner image not available locally (registry login); the repo trufflehog pre-commit hook passed
SAST WARN Semgrep 1 finding, not from this stack: the existing subprocess.run call in the canary probe, now in canary_probe.py
Dependencies WARN pip-audit / osv-scanner no manifest or lockfile in scope, so the local scan could not run; this stack changes no dependencies
License N/A - no dependencies changed
Container N/A - no container changed

Checklist

  • I have read the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

🤖 Generated with Claude Code

@copy-pr-bot

copy-pr-bot Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

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

Contributors can view more details about this message here.

@rparolin
rparolin added this pull request to stack #3616 November 26, 2026 18:40
@github-actions github-actions Bot added the cuda.pathfinder Everything related to the cuda.pathfinder module label Nov 26, 2026
@rparolin rparolin added the enhancement Any code-related improvements label Nov 26, 2026
@rparolin rparolin added this to the cuda.pathfinder next milestone Nov 26, 2026
@rparolin rparolin self-assigned this Nov 26, 2026
@rparolin
rparolin requested review from juenglin and rwgk November 26, 2026 18:42
This was referenced Nov 26, 2026
@rparolin
rparolin marked this pull request as ready for review November 26, 2026 18:47
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

Commits

Reviewing files that changed from the base of the PR and between d529b49 and 7d1a579.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • CUDA library, header, and search-path lookups now consistently use the current Conda prefix. When the prefix is unset or empty, Conda-based lookups are skipped instead of searching from an invalid location. Changes to the configured prefix are picked up on subsequent lookups, helping ensure searches reflect the active environment.

Added get_conda_prefix() to read CONDA_PREFIX and return None when it is unset or empty. Updated three Conda search paths to use the helper and added tests for its return values.

Changes: Conda Prefix Lookup

Layer / File(s) Summary
Add and test Conda prefix helper
cuda_pathfinder/cuda/pathfinder/_utils/env_vars.py, cuda_pathfinder/tests/test_utils_env_vars.py
Added an uncached helper that returns the current CONDA_PREFIX value or None when it is unset or empty. Tests cover these cases and a configured path.
Use helper in Conda searches
cuda_pathfinder/cuda/pathfinder/_dynamic_libs/search_steps.py, cuda_pathfinder/cuda/pathfinder/_headers/find_nvidia_headers.py, cuda_pathfinder/cuda/pathfinder/_static_libs/locate_file.py
Updated the dynamic library, NVIDIA header, and static library Conda searches to get the prefix through get_conda_prefix().

Change: Refactor

Merge Risk: Minimal · previous review 6203d

This refactor centralizes how the CONDA_PREFIX environment variable is read, and behavior is unchanged. Nothing was found that should block merging.

Architecture risk: Low · up to 6203d

CUDA Pathfinder’s three Conda lookup paths now use one shared prefix contract, which normalizes unset and empty CONDA_PREFIX values to None before each path applies its existing miss behavior.

The Conda lookup callers can rely on get_conda_prefix() returning the current nonempty CONDA_PREFIX or None for an unset or empty value, and apply their existing miss behavior when it returns None.

Changed areas: cuda_pathfinder

Review details

Systems and components

  • observed — 5 changed files mapped to cuda_pathfinder.
- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between ed73fd6 and 6203d39.

Files selected for processing: 3

  • cuda_pathfinder/cuda/pathfinder/_dynamic_libs/search_steps.py
  • cuda_pathfinder/cuda/pathfinder/_headers/find_nvidia_headers.py
  • cuda_pathfinder/tests/test_utils_env_vars.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 7 remain after this review.

@github-actions

Copy link
Copy Markdown
Contributor

@rwgk
rwgk removed this pull request from stack #3616 November 26, 2026 19:19
@rwgk
rwgk force-pushed the pathfinder-readability/21-one-conda-prefix-reader branch from 56ba83d to 5d5f816 Compare November 26, 2026 19:19
@copy-pr-bot

copy-pr-bot Bot commented Nov 26, 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.

@rwgk
rwgk added this pull request to stack #3633 November 26, 2026 19:19

@juenglin juenglin 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.

No blocking issues. One non-blocking follow-up is noted inline.


Not cached: every call reads the environment.
"""
return os.environ.get("CONDA_PREFIX") or None

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.

This confirms that the three call sites converted here treat an empty CONDA_PREFIX as unset, as before.

One non-blocking, pre-existing inconsistency, which I'd suggest fixing in a separate small PR rather than here. _binaries/find_nvidia_binary_utility.py (step 2, "Search in Conda environment") reads the variable itself and only checks for None:

if (conda_prefix := os.environ.get("CONDA_PREFIX")) is not None:
    ...
    dirs.append(os.path.join(conda_prefix, "bin"))

With CONDA_PREFIX="" this appends the relative directory "bin". It passes the assert directory check, because the string is non-empty. The executable lookup then resolves it against the current working directory. That contradicts the docstring's "Lookup is restricted to the trusted directories". This helper makes the fix a one-liner:

-from cuda.pathfinder._utils.env_vars import get_cuda_path_or_home
+from cuda.pathfinder._utils.env_vars import get_conda_prefix, get_cuda_path_or_home
@@
-    if (conda_prefix := os.environ.get("CONDA_PREFIX")) is not None:
+    if (conda_prefix := get_conda_prefix()) is not None:

A regression test would plant an executable at <cwd>/bin/<name>, then monkeypatch.chdir(tmp_path) and setenv("CONDA_PREFIX", ""). It would assert that find_nvidia_binary_utility(name) is None when the wheel, CUDA_PATH and canary steps all miss. It fails today and passes with the change.

I left it out of this PR on purpose, since the PR says it changes no behavior. It also deserves a one-line release note, because it changes behavior in that edge case.

@rparolin

rparolin commented Dec 4, 2026

Copy link
Copy Markdown
Collaborator Author

/ok to test 6203d39

@rparolin
rparolin force-pushed the pathfinder-readability/21-one-conda-prefix-reader branch from 6203d39 to d529b49 Compare December 4, 2026 17:54
Three finders read `CONDA_PREFIX` on their own and each treated an empty
value as unset: dynamic libraries, headers, and the shared static and
bitcode search. `get_conda_prefix()` in `_utils/env_vars.py` now holds
that rule, and the three call it.

It is not cached. Like the code it replaces, it reads the environment on
every call.

The binary finder is left alone on purpose. It treats an empty
`CONDA_PREFIX` as set, so switching it over would change behavior.

No behavior change.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Rob Parolin <rparolin@nvidia.com>
@rparolin
rparolin force-pushed the pathfinder-readability/21-one-conda-prefix-reader branch from d529b49 to 7d1a579 Compare December 4, 2026 20:44

This branch has not been deployed

No deployments
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants