Skip to content

Commit e290d1c

Browse files
committed
TST: fix: using meson with windows, MSVC
1 parent 0a14016 commit e290d1c

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

numpy/core/tests/test_array_interface.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sys
22
import pytest
33
import numpy as np
4-
from numpy.testing import extbuild
4+
from numpy.testing import extbuild, IS_WASM
55

66

77
@pytest.fixture
@@ -12,6 +12,8 @@ def get_module(tmp_path):
1212

1313
if not sys.platform.startswith('linux'):
1414
pytest.skip('link fails on cygwin')
15+
if IS_WASM:
16+
pytest.skip("Can't build module inside Wasm")
1517

1618
prologue = '''
1719
#include <Python.h>
@@ -128,9 +130,6 @@ def get_module(tmp_path):
128130
more_init=more_init)
129131

130132

131-
# FIXME: numpy.testing.extbuild uses `numpy.distutils`, so this won't work on
132-
# Python 3.12 and up.
133-
@pytest.mark.skipif(sys.version_info >= (3, 12), reason="no numpy.distutils")
134133
@pytest.mark.slow
135134
def test_cstruct(get_module):
136135

numpy/random/tests/test_extending.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import shutil
66
import subprocess
77
import sys
8+
import sysconfig
89
import textwrap
910
import warnings
1011

@@ -105,8 +106,17 @@ def test_cython(tmp_path):
105106
"""))
106107
target_dir = build_dir / "build"
107108
os.makedirs(target_dir, exist_ok=True)
108-
subprocess.check_call(["meson", "setup", str(build_dir)], cwd=target_dir)
109-
subprocess.check_call(["meson", "compile"], cwd=target_dir)
109+
if sys.platform == "win32":
110+
subprocess.check_call(["meson", "setup",
111+
"--buildtype=release",
112+
"--vsenv", str(build_dir)],
113+
cwd=target_dir,
114+
)
115+
else:
116+
subprocess.check_call(["meson", "setup", str(build_dir)],
117+
cwd=target_dir
118+
)
119+
subprocess.check_call(["meson", "compile", "-vv"], cwd=target_dir)
110120

111121
# gh-16162: make sure numpy's __init__.pxd was used for cython
112122
# not really part of this test, but it is a convenient place to check
@@ -121,8 +131,9 @@ def test_cython(tmp_path):
121131
assert False, ("Could not find '{}' in C file, "
122132
"wrong pxd used".format(txt_to_find))
123133
# import without adding the directory to sys.path
124-
so1 = sorted(glob.glob(str(target_dir / "extending.*")))[0]
125-
so2 = sorted(glob.glob(str(target_dir / "extending_distributions.*")))[0]
134+
suffix = sysconfig.get_config_var('EXT_SUFFIX')
135+
so1 = (target_dir / "extending").with_suffix(suffix)
136+
so2 = (target_dir / "extending_distributions").with_suffix(suffix)
126137
spec1 = spec_from_file_location("extending", so1)
127138
spec2 = spec_from_file_location("extending_distributions", so2)
128139
extending = module_from_spec(spec1)

numpy/testing/_private/extbuild.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,16 @@ def build(cfile, outputfilename, compile_extra, link_extra,
229229
name_suffix: 'dummy',
230230
)
231231
"""))
232-
subprocess.check_call(["meson", "setup", "--vsenv", ".."], cwd=build_dir)
232+
if sys.platform == "win32":
233+
subprocess.check_call(["meson", "setup",
234+
"--buildtype=release",
235+
"--vsenv", ".."],
236+
cwd=build_dir,
237+
)
238+
else:
239+
subprocess.check_call(["meson", "setup", "--vsenv", ".."],
240+
cwd=build_dir
241+
)
233242
subprocess.check_call(["meson", "compile"], cwd=build_dir)
234243
os.rename(str(build_dir / so_name) + ".dummy", cfile.parent / so_name)
235244

0 commit comments

Comments
 (0)