Skip to content

Commit 1884c5e

Browse files
committed
build: getattr fallback for cuda-pathfinder < 1.5
cuda-pathfinder 1.4.x (currently on PyPI) does not expose get_cuda_path_or_home yet. Fall back to os.environ.get via getattr so the namespace fix can be tested on CI now. Made-with: Cursor
1 parent 9f7793c commit 1884c5e

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

cuda_bindings/build_hooks.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ def _import_get_cuda_path_or_home():
4747
except ModuleNotFoundError:
4848
pass
4949
else:
50-
return pathfinder.get_cuda_path_or_home
50+
return getattr(
51+
pathfinder,
52+
"get_cuda_path_or_home",
53+
lambda: os.environ.get("CUDA_PATH", os.environ.get("CUDA_HOME")),
54+
)
5155

5256
import cuda
5357

@@ -57,9 +61,13 @@ def _import_get_cuda_path_or_home():
5761
cuda.__path__ = list(cuda.__path__) + [sp_cuda]
5862
break
5963

60-
from cuda.pathfinder import get_cuda_path_or_home
64+
from cuda import pathfinder
6165

62-
return get_cuda_path_or_home
66+
return getattr(
67+
pathfinder,
68+
"get_cuda_path_or_home",
69+
lambda: os.environ.get("CUDA_PATH", os.environ.get("CUDA_HOME")),
70+
)
6371

6472

6573
@functools.cache

cuda_core/build_hooks.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ def _import_get_cuda_path_or_home():
4242
except ModuleNotFoundError:
4343
pass
4444
else:
45-
return pathfinder.get_cuda_path_or_home
45+
return getattr(
46+
pathfinder,
47+
"get_cuda_path_or_home",
48+
lambda: os.environ.get("CUDA_PATH", os.environ.get("CUDA_HOME")),
49+
)
4650

4751
import cuda
4852

@@ -52,9 +56,13 @@ def _import_get_cuda_path_or_home():
5256
cuda.__path__ = list(cuda.__path__) + [sp_cuda]
5357
break
5458

55-
from cuda.pathfinder import get_cuda_path_or_home
59+
from cuda import pathfinder
5660

57-
return get_cuda_path_or_home
61+
return getattr(
62+
pathfinder,
63+
"get_cuda_path_or_home",
64+
lambda: os.environ.get("CUDA_PATH", os.environ.get("CUDA_HOME")),
65+
)
5866

5967

6068
@functools.cache

0 commit comments

Comments
 (0)