Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TST: convert remaining setup.py tests to meson instead #24206

Merged
merged 5 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 27 additions & 0 deletions numpy/core/tests/examples/cython/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
project('checks', 'c', 'cython')

py = import('python').find_installation(pure: false)

cc = meson.get_compiler('c')
cy = meson.get_compiler('cython')

if not cy.version().version_compare('>=0.29.35')
error('tests requires Cython >= 0.29.35')
endif

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

py.extension_module(
'checks',
'checks.pyx',
install: false,
c_args: [
'-DNPY_NO_DEPRECATED_API=0', # Cython still uses old NumPy C API
# Require 1.25+ to test datetime additions
'-DNPY_TARGET_VERSION=NPY_2_0_API_VERSION',
],
include_directories: [npy_include_path],
)
55 changes: 21 additions & 34 deletions numpy/core/tests/test_cython.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,44 +31,31 @@


@pytest.fixture
def install_temp(request, tmp_path):
def install_temp(tmp_path):
# Based in part on test_cython from random.tests.test_extending
if IS_WASM:
pytest.skip("No subprocess")

here = os.path.dirname(__file__)
ext_dir = os.path.join(here, "examples", "cython")

cytest = str(tmp_path / "cytest")

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,
)

# In order to import the built module, we need its path to sys.path
# so parse that out of the record
with open(install_log) as fid:
for line in fid:
if "checks" in line:
sys.path.append(os.path.dirname(line))
break
else:
raise RuntimeError(f'could not parse "{install_log}"')

srcdir = os.path.join(os.path.dirname(__file__), 'examples', 'cython')
build_dir = tmp_path / "build"
os.makedirs(build_dir, exist_ok=True)
try:
subprocess.check_call(["meson", "--version"])
except FileNotFoundError:
pytest.skip("No usable 'meson' found")
if sys.platform == "win32":
subprocess.check_call(["meson", "setup",
"--buildtype=release",
"--vsenv", str(srcdir)],
cwd=build_dir,
)
else:
subprocess.check_call(["meson", "setup", str(srcdir)],
cwd=build_dir
)
subprocess.check_call(["meson", "compile", "-vv"], cwd=build_dir)

sys.path.append(str(build_dir))

def test_is_timedelta64_object(install_temp):
import checks
Expand Down