Skip to content

Commit 3247072

Browse files
committed
Avoid Windows architecture detection on Linux
1 parent 8c55ee1 commit 3247072

2 files changed

Lines changed: 27 additions & 10 deletions

File tree

‎cuda_pathfinder/cuda/pathfinder/_dynamic_libs/search_platform.py‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import glob
1414
import os
1515
from collections.abc import Sequence
16-
from dataclasses import dataclass, field
16+
from dataclasses import dataclass
1717
from pathlib import PurePath
1818
from typing import Protocol, cast
1919

@@ -175,19 +175,19 @@ def find_in_lib_dir(
175175

176176
@dataclass(frozen=True, slots=True)
177177
class WindowsSearchPlatform:
178-
target_arch: str = field(default_factory=windows_python_arch)
178+
target_arch: str
179179

180180
def lib_searched_for(self, libname: str) -> str:
181181
return f"{libname}*.dll"
182182

183183
def site_packages_rel_dirs(self, desc: LibDescriptor) -> tuple[str, ...]:
184-
return desc.site_packages_windows.for_arch(self.target_arch)
184+
return cast(tuple[str, ...], desc.site_packages_windows.for_arch(self.target_arch))
185185

186186
def conda_anchor_point(self, conda_prefix: str) -> str:
187187
return os.path.join(conda_prefix, "Library")
188188

189189
def anchor_rel_dirs(self, desc: LibDescriptor) -> tuple[str, ...]:
190-
return desc.anchor_rel_dirs_windows.for_arch(self.target_arch)
190+
return cast(tuple[str, ...], desc.anchor_rel_dirs_windows.for_arch(self.target_arch))
191191

192192
def find_in_site_packages(
193193
self,
@@ -220,4 +220,10 @@ def find_in_lib_dir(
220220
return None
221221

222222

223-
PLATFORM: SearchPlatform = WindowsSearchPlatform() if IS_WINDOWS else LinuxSearchPlatform()
223+
def _platform_for_current_system() -> SearchPlatform:
224+
if IS_WINDOWS:
225+
return WindowsSearchPlatform(target_arch=windows_python_arch())
226+
return LinuxSearchPlatform()
227+
228+
229+
PLATFORM = _platform_for_current_system()

‎cuda_pathfinder/tests/test_search_steps.py‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import pytest
1111

1212
from cuda.pathfinder import UnsupportedWindowsArchError
13+
from cuda.pathfinder._dynamic_libs import search_platform as search_platform_mod
1314
from cuda.pathfinder._dynamic_libs.descriptor_catalog import WindowsSearchDir, WindowsSearchDirs
1415
from cuda.pathfinder._dynamic_libs.lib_descriptor import LIB_DESCRIPTORS, LibDescriptor
1516
from cuda.pathfinder._dynamic_libs.load_dl_common import DynamicLibNotFoundError
@@ -78,7 +79,7 @@ def test_lib_searched_for_linux(self):
7879
assert ctx.lib_searched_for == "libcublas.so"
7980

8081
def test_lib_searched_for_windows(self):
81-
ctx = SearchContext(_make_desc(name="cublas"), platform=WindowsSearchPlatform())
82+
ctx = SearchContext(_make_desc(name="cublas"), platform=WindowsSearchPlatform(target_arch="x64"))
8283
assert ctx.lib_searched_for == "cublas*.dll"
8384

8485
def test_raise_not_found_includes_messages(self):
@@ -100,6 +101,16 @@ def test_raise_not_found_empty_messages(self):
100101

101102

102103
class TestWindowsPythonArch:
104+
@pytest.mark.agent_authored(model="gpt-5")
105+
def test_linux_platform_does_not_detect_windows_arch(self, mocker):
106+
mocker.patch.object(search_platform_mod, "IS_WINDOWS", False)
107+
get_windows_arch = mocker.patch.object(search_platform_mod, "windows_python_arch")
108+
109+
platform = search_platform_mod._platform_for_current_system()
110+
111+
assert isinstance(platform, LinuxSearchPlatform)
112+
get_windows_arch.assert_not_called()
113+
103114
def test_detects_sysconfig_x64(self, mocker):
104115
mocker.patch.object(windows_arch_mod.sysconfig, "get_platform", return_value="win-amd64")
105116

@@ -167,7 +178,7 @@ def test_found_windows(self, mocker, tmp_path):
167178
name="cudart",
168179
site_packages_windows=WindowsSearchDirs.common(os.path.join("nvidia", "cuda_runtime", "bin")),
169180
)
170-
result = find_in_site_packages(_ctx(desc, platform=WindowsSearchPlatform()))
181+
result = find_in_site_packages(_ctx(desc, platform=WindowsSearchPlatform(target_arch="x64")))
171182
assert result is not None
172183
assert result.abs_path == str(dll)
173184
assert result.found_via == "site-packages"
@@ -338,7 +349,7 @@ def test_found_windows(self, mocker, tmp_path):
338349

339350
mocker.patch.dict(os.environ, {"CONDA_PREFIX": str(tmp_path)})
340351

341-
result = find_in_conda(_ctx(platform=WindowsSearchPlatform()))
352+
result = find_in_conda(_ctx(platform=WindowsSearchPlatform(target_arch="x64")))
342353
assert result is not None
343354
assert result.abs_path == str(dll)
344355
assert result.found_via == "conda"
@@ -439,7 +450,7 @@ def test_found_windows(self, mocker, tmp_path):
439450

440451
mocker.patch(f"{_STEPS_MOD}.get_cuda_path_or_home", return_value=str(tmp_path))
441452

442-
result = find_in_cuda_path(_ctx(platform=WindowsSearchPlatform()))
453+
result = find_in_cuda_path(_ctx(platform=WindowsSearchPlatform(target_arch="x64")))
443454
assert result is not None
444455
assert result.abs_path == str(dll)
445456
assert result.found_via == "CUDA_PATH"
@@ -575,7 +586,7 @@ def test_find_lib_dir_uses_descriptor_windows(self, tmp_path):
575586
)
576587
),
577588
)
578-
result = _find_lib_dir_using_anchor(desc, WindowsSearchPlatform(), str(tmp_path))
589+
result = _find_lib_dir_using_anchor(desc, WindowsSearchPlatform(target_arch="x64"), str(tmp_path))
579590
assert result is not None
580591
assert result.endswith(os.path.join("nvvm", "bin"))
581592

0 commit comments

Comments
 (0)