You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
refactor(pathfinder): read CONDA_PREFIX in one place - #3630
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.
Reviewing files that changed from the base of the PR and between 56ba83d and ed73fd6.
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.
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 56ba8
This refactor centralizes how CONDA_PREFIX is read and is described as behavior-preserving. No concrete risk was found, and the new helper has tests, so the change looks ready to merge.
Security architecture risk: Minimal · up to 56ba8
The three affected lookups still read the current Conda prefix and treat an empty or unset value the same way. The binary finder retains its separate behavior. No material change in security exposure was identified.
- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 6 remain after this review.
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>
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")) isnotNone:
...
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.
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
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.
— 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_PREFIXon 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.pynow 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_PREFIXas 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
cuda_pathfindertest suite at this commit: 1299 passed, 6 skipped (Linux, Python 3.14).mypy-pathfinder. mypy also passes with--platform win32.mainare 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.PLC Local Security Evidence (Advisory)
Local advisory checks only, run over the whole stack. Not release-gate results.
subprocess.runcall in the canary probe, now incanary_probe.pyChecklist
🤖 Generated with Claude Code