Skip to content

Commit 4cbd55f

Browse files
ngoldbaumcharris
andauthored
TST: add 3.15t win32 CI and fix issues seen in that build (numpy#31607)
Co-authored-by: Charles Harris <[email protected]>
1 parent 218d297 commit 4cbd55f

12 files changed

Lines changed: 126 additions & 95 deletions

File tree

‎.github/workflows/windows.yml‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,19 @@ jobs:
6969
7070
7171
#=======================================================================================
72-
msvc_python32bit_no_openblas:
73-
name: MSVC, ${{ matrix.architecture }}, fast, no BLAS
72+
msvc_python_x86_arm64_no_openblas:
73+
name: MSVC, ${{ matrix.os }} ${{ matrix.architecture }}, full, no BLAS, ${{ matrix.python_version }}
7474
runs-on: ${{ matrix.os }}
7575
strategy:
7676
fail-fast: false
7777
matrix:
7878
include:
7979
- os: windows-2022
8080
architecture: x86
81+
python_version: '3.15t-dev'
8182
- os: windows-11-arm
8283
architecture: arm64
84+
python_version: '3.12'
8385
# To enable this job on a fork, comment out:
8486
if: github.repository == 'numpy/numpy'
8587
steps:
@@ -93,7 +95,7 @@ jobs:
9395
- name: Setup Python
9496
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
9597
with:
96-
python-version: '3.12'
98+
python-version: ${{ matrix.python_version }}
9799
architecture: ${{ matrix.architecture }}
98100

99101
- name: Setup MSVC
@@ -116,10 +118,10 @@ jobs:
116118
run: |
117119
python -m pip install -r requirements/test_requirements.txt
118120
119-
- name: Run test suite (fast)
121+
- name: Run test suite (full)
120122
run: |
121123
cd tools
122-
python -m pytest --pyargs numpy -m "not slow" -n2 --timeout=600 --durations=10
124+
python -m pytest --pyargs numpy -n auto --timeout=600 --durations=10
123125
124126
#=======================================================================================
125127
msvc_python64bit_openblas:

‎numpy/_core/tests/examples/cython/meson.build‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ if cy.version().version_compare('>=3.1.0')
1515
cython_args += ['-Xfreethreading_compatible=True']
1616
endif
1717

18+
extra_c_args = []
19+
if host_machine.system() == 'windows' and host_machine.cpu_family() == 'x86'
20+
# Cython's constant immortalization passes UINT32_MAX through a Py_ssize_t,
21+
# which aborts module init on 32-bit free-threaded builds when asserts are
22+
# enabled. See https://github.com/cython/cython/issues/7742; this should be
23+
# fixed in Cython 3.2.6, after which the workaround can be removed.
24+
extra_c_args += ['-DCYTHON_IMMORTAL_CONSTANTS=0']
25+
endif
26+
1827
npy_include_path = run_command(py, [
1928
'-c',
2029
'import os; os.chdir(".."); import numpy; print(os.path.abspath(numpy.get_include()))'
@@ -37,7 +46,7 @@ py.extension_module(
3746
'-DNPY_NO_DEPRECATED_API=0', # Cython still uses old NumPy C API
3847
# Require 1.25+ to test datetime additions
3948
'-DNPY_TARGET_VERSION=NPY_2_0_API_VERSION',
40-
],
49+
] + extra_c_args,
4150
include_directories: [npy_include_path],
4251
cython_args: cython_args,
4352
)

‎numpy/_core/tests/test_cython.py‎

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import shutil
23
import subprocess
34
import sys
45
import sysconfig
@@ -8,6 +9,7 @@
89

910
import numpy as np
1011
from numpy.testing import IS_EDITABLE, IS_WASM, assert_array_equal
12+
from numpy.testing._private.utils import run_subprocess
1113

1214
# This import is copied from random.tests.test_extending
1315
try:
@@ -40,8 +42,17 @@ def install_temp(tmpdir_factory):
4042
if IS_WASM:
4143
pytest.skip("No subprocess")
4244

43-
srcdir = os.path.join(os.path.dirname(__file__), 'examples', 'cython')
44-
build_dir = tmpdir_factory.mktemp("cython_test") / "build"
45+
# Build against a copy of the sources placed next to the build dir:
46+
# meson refers to sources via paths relative to the build dir, and on
47+
# Windows the unnormalized cwd + `..` chain joining the deeply nested
48+
# pytest tmp dir and site-packages can exceed MAX_PATH, failing the
49+
# compile with "Cannot open source file".
50+
tmp_root = tmpdir_factory.mktemp("cython_test")
51+
srcdir = str(tmp_root / "src")
52+
shutil.copytree(
53+
os.path.join(os.path.dirname(__file__), 'examples', 'cython'),
54+
srcdir)
55+
build_dir = tmp_root / "build"
4556
os.makedirs(build_dir, exist_ok=True)
4657
# Ensure we use the correct Python interpreter even when `meson` is
4758
# installed in a different Python environment (see gh-24956)
@@ -58,27 +69,16 @@ def install_temp(tmpdir_factory):
5869
if sysconfig.get_platform() == "win-arm64":
5970
pytest.skip("Meson unable to find MSVC linker on win-arm64")
6071
if sys.platform == "win32":
61-
subprocess.check_call(["meson", "setup",
62-
"--buildtype=release",
63-
"--vsenv", "--native-file", native_file,
64-
str(srcdir)],
65-
cwd=build_dir,
66-
)
72+
run_subprocess(["meson", "setup",
73+
"--buildtype=release",
74+
"--vsenv", "--native-file", native_file,
75+
str(srcdir)],
76+
build_dir)
6777
else:
68-
subprocess.check_call(["meson", "setup",
69-
"--native-file", native_file, str(srcdir)],
70-
cwd=build_dir
71-
)
72-
try:
73-
subprocess.check_call(["meson", "compile", "-vv"], cwd=build_dir)
74-
except subprocess.CalledProcessError:
75-
print("----------------")
76-
print("meson build failed when doing")
77-
print(f"'meson setup --native-file {native_file} {srcdir}'")
78-
print("'meson compile -vv'")
79-
print(f"in {build_dir}")
80-
print("----------------")
81-
raise
78+
run_subprocess(["meson", "setup",
79+
"--native-file", native_file, str(srcdir)],
80+
build_dir)
81+
run_subprocess(["meson", "compile", "-vv"], build_dir)
8282

8383
sys.path.append(str(build_dir))
8484

‎numpy/_core/tests/test_limited_api.py‎

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import os
2+
import shutil
23
import subprocess
34
import sys
45
import sysconfig
56

67
import pytest
78

89
from numpy.testing import IS_EDITABLE, IS_WASM, NOGIL_BUILD
10+
from numpy.testing._private.utils import run_subprocess
911

1012
# This import is copied from random.tests.test_extending
1113
try:
@@ -38,8 +40,17 @@ def install_temp(tmpdir_factory):
3840
if IS_WASM:
3941
pytest.skip("No subprocess")
4042

41-
srcdir = os.path.join(os.path.dirname(__file__), 'examples', 'limited_api')
42-
build_dir = tmpdir_factory.mktemp("limited_api") / "build"
43+
# Build against a copy of the sources placed next to the build dir:
44+
# meson refers to sources via paths relative to the build dir, and on
45+
# Windows the unnormalized cwd + `..` chain joining the deeply nested
46+
# pytest tmp dir and site-packages can exceed MAX_PATH, failing the
47+
# compile with "Cannot open source file".
48+
tmp_root = tmpdir_factory.mktemp("limited_api")
49+
srcdir = str(tmp_root / "src")
50+
shutil.copytree(
51+
os.path.join(os.path.dirname(__file__), 'examples', 'limited_api'),
52+
srcdir)
53+
build_dir = tmp_root / "build"
4354
os.makedirs(build_dir, exist_ok=True)
4455
# Ensure we use the correct Python interpreter even when `meson` is
4556
# installed in a different Python environment (see gh-24956)
@@ -56,25 +67,17 @@ def install_temp(tmpdir_factory):
5667
if sysconfig.get_platform() == "win-arm64":
5768
pytest.skip("Meson unable to find MSVC linker on win-arm64")
5869
if sys.platform == "win32":
59-
subprocess.check_call(["meson", "setup",
60-
"--werror",
61-
"--buildtype=release",
62-
"--vsenv", "--native-file", native_file,
63-
str(srcdir)],
64-
cwd=build_dir,
65-
)
70+
run_subprocess(["meson", "setup",
71+
"--werror",
72+
"--buildtype=release",
73+
"--vsenv", "--native-file", native_file,
74+
str(srcdir)],
75+
build_dir)
6676
else:
67-
subprocess.check_call(["meson", "setup", "--werror",
68-
"--native-file", native_file, str(srcdir)],
69-
cwd=build_dir
70-
)
71-
try:
72-
subprocess.check_call(
73-
["meson", "compile", "-vv"], cwd=build_dir)
74-
except subprocess.CalledProcessError as p:
75-
print(f"{p.stdout=}")
76-
print(f"{p.stderr=}")
77-
raise
77+
run_subprocess(["meson", "setup", "--werror",
78+
"--native-file", native_file, str(srcdir)],
79+
build_dir)
80+
run_subprocess(["meson", "compile", "-vv"], build_dir)
7881

7982
sys.path.append(str(build_dir))
8083

‎numpy/linalg/tests/test_linalg.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"""
44
import itertools
55
import os
6-
import subprocess
76
import sys
87
import textwrap
98
import threading
@@ -44,6 +43,7 @@
4443
assert_raises,
4544
assert_raises_regex,
4645
)
46+
from numpy.testing._private.utils import run_subprocess
4747

4848
try:
4949
import numpy.linalg.lapack_lite
@@ -2096,12 +2096,12 @@ def test_sdot_bug_8577():
20962096
for bad_lib in bad_libs:
20972097
code = template.format(before="import numpy as np", after="",
20982098
bad_lib=bad_lib)
2099-
subprocess.check_call([sys.executable, "-c", code])
2099+
run_subprocess([sys.executable, "-c", code])
21002100

21012101
# Swapped import order
21022102
code = template.format(after="import numpy as np", before="",
21032103
bad_lib=bad_lib)
2104-
subprocess.check_call([sys.executable, "-c", code])
2104+
run_subprocess([sys.executable, "-c", code])
21052105

21062106

21072107
class TestMultiDot:

‎numpy/random/tests/test_extending.py‎

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import os
22
import shutil
3-
import subprocess
43
import sys
54
import sysconfig
65
import warnings
@@ -10,6 +9,7 @@
109

1110
import numpy as np
1211
from numpy.testing import IS_EDITABLE, IS_WASM
12+
from numpy.testing._private.utils import run_subprocess
1313

1414
try:
1515
import cffi
@@ -77,18 +77,16 @@ def test_cython(tmp_path):
7777
f.write(f"python = '{sys.executable}'\n")
7878
f.write(f"python3 = '{sys.executable}'")
7979
if sys.platform == "win32":
80-
subprocess.check_call(["meson", "setup",
81-
"--buildtype=release",
82-
"--vsenv", "--native-file", native_file,
83-
str(build_dir)],
84-
cwd=target_dir,
85-
)
80+
run_subprocess(["meson", "setup",
81+
"--buildtype=release",
82+
"--vsenv", "--native-file", native_file,
83+
str(build_dir)],
84+
target_dir)
8685
else:
87-
subprocess.check_call(["meson", "setup",
88-
"--native-file", native_file, str(build_dir)],
89-
cwd=target_dir
90-
)
91-
subprocess.check_call(["meson", "compile", "-vv"], cwd=target_dir)
86+
run_subprocess(["meson", "setup",
87+
"--native-file", native_file, str(build_dir)],
88+
target_dir)
89+
run_subprocess(["meson", "compile", "-vv"], target_dir)
9290

9391
# gh-16162: make sure numpy's __init__.pxd was used for cython
9492
# not really part of this test, but it is a convenient place to check

‎numpy/random/tests/test_generator_mt19937.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from numpy.linalg import LinAlgError
1111
from numpy.random import MT19937, Generator, RandomState, SeedSequence
1212
from numpy.testing import (
13+
IS_64BIT,
1314
IS_WASM,
1415
assert_,
1516
assert_allclose,
@@ -1267,6 +1268,10 @@ def test_dirichlet_small_alpha(self):
12671268

12681269
@pytest.mark.slow
12691270
@pytest.mark.thread_unsafe(reason="crashes with low memory")
1271+
@pytest.mark.skipif(
1272+
not IS_64BIT,
1273+
reason="the 458 MiB sample array may not fit in a 32-bit "
1274+
"address space fragmented by earlier tests")
12701275
def test_dirichlet_moderately_small_alpha(self):
12711276
# Use alpha.max() < 0.1 to trigger stick breaking code path
12721277
alpha = np.array([0.02, 0.04, 0.03])

‎numpy/testing/_private/extbuild.py‎

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66

77
import os
88
import pathlib
9-
import subprocess
109
import sys
1110
import sysconfig
1211
import textwrap
1312

13+
from .utils import run_subprocess
14+
1415
__all__ = ['build_and_import_extension', 'compile_extension_module']
1516

1617

@@ -225,19 +226,17 @@ def build(cfile, outputfilename, compile_extra, link_extra,
225226
python = '{sys.executable}'
226227
"""))
227228
if sys.platform == "win32":
228-
subprocess.check_call(["meson", "setup",
229-
"--buildtype=release",
230-
"--vsenv", ".."],
231-
cwd=build_dir,
232-
)
229+
run_subprocess(["meson", "setup",
230+
"--buildtype=release",
231+
"--vsenv", ".."],
232+
build_dir)
233233
else:
234-
subprocess.check_call(["meson", "setup", "--vsenv",
235-
"..", f'--native-file={os.fspath(native_file_name)}'],
236-
cwd=build_dir
237-
)
234+
run_subprocess(["meson", "setup", "--vsenv",
235+
"..", f'--native-file={os.fspath(native_file_name)}'],
236+
build_dir)
238237

239238
so_name = outputfilename.parts[-1] + get_so_suffix()
240-
subprocess.check_call(["meson", "compile"], cwd=build_dir)
239+
run_subprocess(["meson", "compile"], build_dir)
241240
os.rename(str(build_dir / so_name), cfile.parent / so_name)
242241
return cfile.parent / so_name
243242

‎numpy/testing/_private/utils.py‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2868,3 +2868,32 @@ def wrapper(*args, **kwargs):
28682868
"deep recursion")
28692869
return func(*args, **kwargs)
28702870
return wrapper
2871+
2872+
2873+
def run_subprocess(cmd, cwd=None, **kwargs):
2874+
"""Run ``cmd`` in a subprocess, failing the test with its captured output
2875+
if it exits with a nonzero status.
2876+
2877+
Output that a subprocess merely inherits is lost in pytest-xdist workers
2878+
when a test fails, making CI failures hard to debug. Routing a
2879+
build/compile/run step through this helper captures the child's stdout and
2880+
stderr and folds them into the failure message so they reach the report.
2881+
Returns the ``subprocess.CompletedProcess`` for callers that want to
2882+
inspect the output. Extra keyword arguments are passed to
2883+
``subprocess.run``.
2884+
"""
2885+
import subprocess
2886+
2887+
import pytest
2888+
2889+
res = subprocess.run(cmd, cwd=cwd, capture_output=True, text=True,
2890+
errors="replace", **kwargs)
2891+
if res.returncode != 0:
2892+
cmd_str = cmd if isinstance(cmd, str) else " ".join(map(str, cmd))
2893+
in_dir = f" in {cwd}" if cwd is not None else ""
2894+
pytest.fail(
2895+
f"`{cmd_str}` failed (exit {res.returncode}){in_dir}\n"
2896+
f"----- stdout -----\n{res.stdout}\n"
2897+
f"----- stderr -----\n{res.stderr}",
2898+
pytrace=False)
2899+
return res

0 commit comments

Comments
 (0)