Skip to content

Commit

Permalink
TST: convert test_limited_api to meson
Browse files Browse the repository at this point in the history
  • Loading branch information
mattip committed Jul 18, 2023
1 parent bc0087e commit 506b280
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 53 deletions.
21 changes: 21 additions & 0 deletions numpy/core/tests/examples/limited_api/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
project('limited_api', 'c', 'cython')

py_mod = import('python')
py3 = py_mod.find_installation(pure: false)

cc = meson.get_compiler('c')

npy_include_path = run_command(py3, ['-c',
'import os; os.chdir(".."); import numpy; print(os.path.abspath(numpy.get_include()))'],
check: true).stdout().strip()

py3.extension_module(
'limited_api',
'limited_api.c',
install: false,
c_args: [
'-DNPY_NO_DEPRECATED_API=0', # Cython still uses old NumPy C API
'-DPy_LIMITED_API=0x03060000',
],
include_directories: [npy_include_path],
)
22 changes: 0 additions & 22 deletions numpy/core/tests/examples/limited_api/setup.py

This file was deleted.

20 changes: 8 additions & 12 deletions numpy/core/tests/test_cython.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,22 @@ def install_temp(tmp_path):
if IS_WASM:
pytest.skip("No subprocess")

import glob
# build the examples in a temporary directory
srcdir = os.path.join(os.path.dirname(__file__), 'examples', 'cython')
build_dir = tmp_path / "cython"
shutil.copytree(srcdir, build_dir)
target_dir = build_dir / "build"
os.makedirs(target_dir, exist_ok=True)
build_dir = tmp_path / "build"
os.makedirs(build_dir, exist_ok=True)
if sys.platform == "win32":
subprocess.check_call(["meson", "setup",
"--buildtype=release",
"--vsenv", str(build_dir)],
cwd=target_dir,
"--vsenv", str(srcdir)],
cwd=build_dir,
)
else:
subprocess.check_call(["meson", "setup", str(build_dir)],
cwd=target_dir
subprocess.check_call(["meson", "setup", str(srcdir)],
cwd=build_dir
)
subprocess.check_call(["meson", "compile", "-vv"], cwd=target_dir)
subprocess.check_call(["meson", "compile", "-vv"], cwd=build_dir)

sys.path.append(str(target_dir))
sys.path.append(str(build_dir))

def test_is_timedelta64_object(install_temp):
print(sys.path)
Expand Down
33 changes: 14 additions & 19 deletions numpy/core/tests/test_limited_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,17 @@ def test_limited_api(tmp_path):
here = os.path.dirname(__file__)
ext_dir = os.path.join(here, "examples", "limited_api")

cytest = str(tmp_path / "limited_api")

shutil.copytree(ext_dir, cytest)
# build the examples and "install" them into a temporary directory

install_log = str(tmp_path / "tmp_install_log.txt")
subprocess.check_output(
[
sys.executable,
"setup.py",
"build",
"install",
"--prefix", str(tmp_path / "installdir"),
"--single-version-externally-managed",
"--record",
install_log,
],
cwd=cytest,
)
target_dir = tmp_path / "build"
os.makedirs(target_dir, exist_ok=True)

if sys.platform == "win32":
subprocess.check_call(["meson", "setup",
"--buildtype=release",
"--vsenv", ext_dir],
cwd=target_dir,
)
else:
subprocess.check_call(["meson", "setup", ext_dir], cwd=target_dir)
subprocess.check_call(["meson", "compile", "-vv"], cwd=target_dir)


0 comments on commit 506b280

Please sign in to comment.