Skip to content

Commit cb5ffbb

Browse files
committed
build: revert to sys.path scan, importlib.metadata finds wrong dist-info
See #1817 (comment) See #1817 (comment) Made-with: Cursor
1 parent a9995ac commit cb5ffbb

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

cuda_bindings/build_hooks.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,21 @@ def _import_get_cuda_path_or_home():
4444
except ModuleNotFoundError as exc:
4545
if exc.name not in ("cuda", "cuda.pathfinder"):
4646
raise
47-
from importlib.metadata import PackageNotFoundError, distribution
48-
from pathlib import Path
49-
5047
try:
51-
dist = distribution("cuda-pathfinder")
52-
except PackageNotFoundError:
48+
import cuda
49+
except ModuleNotFoundError:
50+
cuda = None
51+
52+
for p in sys.path:
53+
sp_cuda = os.path.join(p, "cuda")
54+
if os.path.isdir(os.path.join(sp_cuda, "pathfinder")):
55+
cuda.__path__ = list(cuda.__path__) + [sp_cuda]
56+
break
57+
else:
5358
raise ModuleNotFoundError(
5459
"cuda-pathfinder is not installed in the build environment. "
5560
"Ensure 'cuda-pathfinder>=1.5' is in build-system.requires."
56-
) from None
57-
import cuda
58-
59-
site_cuda = str(dist.locate_file(Path("cuda")))
60-
cuda_paths = list(cuda.__path__)
61-
if site_cuda not in cuda_paths:
62-
cuda.__path__ = cuda_paths + [site_cuda]
61+
)
6362
import cuda.pathfinder
6463

6564
return cuda.pathfinder.get_cuda_path_or_home

cuda_core/build_hooks.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,21 @@ def _import_get_cuda_path_or_home():
3939
except ModuleNotFoundError as exc:
4040
if exc.name not in ("cuda", "cuda.pathfinder"):
4141
raise
42-
from importlib.metadata import PackageNotFoundError, distribution
43-
from pathlib import Path
44-
4542
try:
46-
dist = distribution("cuda-pathfinder")
47-
except PackageNotFoundError:
43+
import cuda
44+
except ModuleNotFoundError:
45+
cuda = None
46+
47+
for p in sys.path:
48+
sp_cuda = os.path.join(p, "cuda")
49+
if os.path.isdir(os.path.join(sp_cuda, "pathfinder")):
50+
cuda.__path__ = list(cuda.__path__) + [sp_cuda]
51+
break
52+
else:
4853
raise ModuleNotFoundError(
4954
"cuda-pathfinder is not installed in the build environment. "
5055
"Ensure 'cuda-pathfinder>=1.5' is in build-system.requires."
51-
) from None
52-
import cuda
53-
54-
site_cuda = str(dist.locate_file(Path("cuda")))
55-
cuda_paths = list(cuda.__path__)
56-
if site_cuda not in cuda_paths:
57-
cuda.__path__ = cuda_paths + [site_cuda]
56+
)
5857
import cuda.pathfinder
5958

6059
return cuda.pathfinder.get_cuda_path_or_home

0 commit comments

Comments
 (0)