8000 Merge pull request #24616 from charris/backport-24206 · numpy/numpy@ab467f6 · GitHub
[go: up one dir, main page]

Skip to content

Commit ab467f6

Browse files
authored
Merge pull request #24616 from charris/backport-24206
TST: convert cython test from setup.py to meson
2 parents fb3c76f + ed0ba4d commit ab467f6

File tree

2 files changed

+48
-34
lines changed

2 files changed

+48
-34
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
project('checks', 'c', 'cython')
2+
3+
py = import('python').find_installation(pure: false)
4+
5+
cc = meson.get_compiler('c')
6+
cy = meson.get_compiler('cython')
7+
8+
if not cy.version().version_compare('>=0.29.35')
9+
error('tests requires Cython >= 0.29.35')
10+
endif
11+
12+
npy_include_path = run_command(py, [
13+
'-c',
14+
'import os; os.chdir(".."); import numpy; print(os.path.abspath(numpy.get_include()))'
15+
], check: true).stdout().strip()
16+
17+
py.extension_module(
18+
'checks',
19+
'checks.pyx',
20+
install: false,
21+
c_args: [
22+
'-DNPY_NO_DEPRECATED_API=0', # Cython still uses old NumPy C API
23+
# Require 1.25+ to test datetime additions
24+
'-DNPY_TARGET_VERSION=NPY_2_0_API_VERSION',
25+
],
26+
include_directories: [npy_include_path],
27+
)

numpy/core/tests/test_cython.py

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,44 +29,31 @@
2929

3030

3131
@pytest.fixture
32-
def install_temp(request, tmp_path):
32+
def install_temp(tmp_path):
3333
# Based in part on test_cython from random.tests.test_extending
3434
if IS_WASM:
3535
pytest.skip("No subprocess")
3636

37-
here = os.path.dirname(__file__)
38-
ext_dir = os.path.join(here, "examples", "cython")
39-
40-
cytest = str(tmp_path / "cytest")
41-
42-
shutil.copytree(ext_dir, cytest)
43-
# build the examples and "install" them into a temporary directory
44-
45-
install_log = str(tmp_path / "tmp_install_log.txt")
46-
subprocess.check_output(
47-
[
48-
sys.executable,
49-
"setup.py",
50-
"build",
51-
"install",
52-
"--prefix", str(tmp_path / "installdir"),
53-
"--single-version-externally-managed",
54-
"--record",
55-
install_log,
56-
],
57-
cwd=cytest,
58-
)
59-
60-
# In order to import the built module, we need its path to sys.path
61-
# so parse that out of the record
62-
with open(install_log) as fid:
63-
for line in fid:
64-
if "checks" in line:
65-
sys.path.append(os.path.dirname(line))
66-
break
67-
else:
68-
raise RuntimeError(f'could not parse "{install_log}"')
69-
37+
srcdir = os.path.join(os.path.dirname(__file__), 'examples', 'cython')
38+
build_dir = tmp_path / "build"
39+
os.makedirs(build_dir, exist_ok=True)
40+
try:
41+
subprocess.check_call(["meson", "--version"])
42+
except FileNotFoundError:
43+
pytest.skip("No usable 'meson' found")
44+
if sys.platform == "win32":
45+
subprocess.check_call(["meson", "setup",
46+
"--buildtype=release",
47+
"--vsenv", str(srcdir)],
48+
cwd=build_dir,
49+
)
50+
else:
51+
subprocess.check_call(["meson", "setup", str(srcdir)],
52+
cwd=build_dir
53+
)
54+
subprocess.check_call(["meson", "compile", "-vv"], cwd=build_dir)
55+
56+
sys.path.append(str(build_dir))
7057

7158
def test_is_timedelta64_object(install_temp):
7259
import checks

0 commit comments

Comments
 (0)
0