Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cuda_pathfinder/cuda/pathfinder/_dynamic_libs/search_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
find_lib_in_dir,
find_lib_in_site_packages,
)
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
from cuda.pathfinder._utils.found_via import (
FOUND_VIA_CONDA,
FOUND_VIA_CUDA_PATH,
Expand Down Expand Up @@ -146,8 +146,8 @@ def find_in_site_packages(ctx: SearchContext) -> FindResult | NotFound:

def find_in_conda(ctx: SearchContext) -> FindResult | NotFound:
"""Search ``$CONDA_PREFIX``."""
conda_prefix = os.environ.get("CONDA_PREFIX")
if not conda_prefix:
conda_prefix = get_conda_prefix()
if conda_prefix is None:
return NotFound()
anchor = ctx.conda_anchor_point(conda_prefix)
return _find_under_anchor_root(ctx, anchor, FOUND_VIA_CONDA)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
system_install_dir_patterns,
)
from cuda.pathfinder._utils.ctk_root_canary import CTK_ROOT_CANARY_ANCHOR_LIBNAMES
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
from cuda.pathfinder._utils.find_sub_dirs import find_sub_dirs_all_sitepackages
from cuda.pathfinder._utils.found_via import (
FOUND_VIA_CONDA,
Expand Down Expand Up @@ -97,8 +97,8 @@ def find_in_site_packages(desc: HeaderDescriptor) -> LocatedHeaderDir | None:

def find_in_conda(desc: HeaderDescriptor) -> LocatedHeaderDir | None:
"""Search ``$CONDA_PREFIX``."""
conda_prefix = os.environ.get("CONDA_PREFIX")
if not conda_prefix:
conda_prefix = get_conda_prefix()
if conda_prefix is None:
return None
anchor_point = resolve_conda_anchor(desc, conda_prefix)
if anchor_point is None:
Expand Down
7 changes: 3 additions & 4 deletions cuda_pathfinder/cuda/pathfinder/_static_libs/locate_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

"""Search shared by the static-library and bitcode-library finders."""

import os
from pathlib import Path

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
from cuda.pathfinder._utils.find_sub_dirs import find_sub_dirs_all_sitepackages
from cuda.pathfinder._utils.found_via import FOUND_VIA_CONDA, FOUND_VIA_CUDA_PATH, FOUND_VIA_SITE_PACKAGES
from cuda.pathfinder._utils.platform_aware import IS_WINDOWS
Expand Down Expand Up @@ -44,8 +43,8 @@ def locate_file(
if abs_path is not None:
return abs_path, FOUND_VIA_SITE_PACKAGES

conda_prefix = os.environ.get("CONDA_PREFIX")
if conda_prefix:
conda_prefix = get_conda_prefix()
if conda_prefix is not None:
anchor = Path(conda_prefix, "Library") if IS_WINDOWS else Path(conda_prefix)
for rel_path in conda_rel_paths:
abs_path = _resolved_if_file(anchor / rel_path, filename)
Expand Down
8 changes: 8 additions & 0 deletions cuda_pathfinder/cuda/pathfinder/_utils/env_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,11 @@ def get_cuda_path_or_home() -> str | None:

# Return the first (highest priority) set variable
return next(iter(set_vars.values()))


def get_conda_prefix() -> str | None:
"""Return ``$CONDA_PREFIX``, or ``None`` if it is unset or empty.

Not cached: every call reads the environment.
"""
return os.environ.get("CONDA_PREFIX") or None
11 changes: 11 additions & 0 deletions cuda_pathfinder/tests/test_utils_env_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from cuda.pathfinder._utils.env_vars import (
_paths_differ,
get_conda_prefix,
get_cuda_path_or_home,
)

Expand Down Expand Up @@ -248,3 +249,13 @@ def test_caching_behavior(monkeypatch, tmp_path):
get_cuda_path_or_home.cache_clear()
result3 = get_cuda_path_or_home()
assert pathlib.Path(result3) == second_dir


@pytest.mark.agent_authored(model="claude-fable-5-2")
def test_get_conda_prefix_treats_empty_as_unset(monkeypatch):
monkeypatch.delenv("CONDA_PREFIX", raising=False)
assert get_conda_prefix() is None
monkeypatch.setenv("CONDA_PREFIX", "")
assert get_conda_prefix() is None
monkeypatch.setenv("CONDA_PREFIX", "/opt/conda")
assert get_conda_prefix() == "/opt/conda"
Loading