diff options
-rw-r--r-- | numpy/core/tests/examples/cython/checks.pyx (renamed from numpy/core/tests/examples/checks.pyx) | 0 | ||||
-rw-r--r-- | numpy/core/tests/examples/cython/setup.py (renamed from numpy/core/tests/examples/setup.py) | 12 | ||||
-rw-r--r-- | numpy/core/tests/examples/limited_api/limited_api.c (renamed from numpy/core/tests/examples/example_limited_api.c) | 9 | ||||
-rw-r--r-- | numpy/core/tests/examples/limited_api/setup.py | 22 | ||||
-rw-r--r-- | numpy/core/tests/test_cython.py | 2 | ||||
-rw-r--r-- | numpy/core/tests/test_limited_api.py | 41 |
6 files changed, 68 insertions, 18 deletions
diff --git a/numpy/core/tests/examples/checks.pyx b/numpy/core/tests/examples/cython/checks.pyx index 151979db7..151979db7 100644 --- a/numpy/core/tests/examples/checks.pyx +++ b/numpy/core/tests/examples/cython/checks.pyx diff --git a/numpy/core/tests/examples/setup.py b/numpy/core/tests/examples/cython/setup.py index 6ec0b4197..6e34aa778 100644 --- a/numpy/core/tests/examples/setup.py +++ b/numpy/core/tests/examples/cython/setup.py @@ -9,24 +9,16 @@ from Cython.Build import cythonize from setuptools.extension import Extension import os -include_dirs = [np.get_include()] macros = [("NPY_NO_DEPRECATED_API", 0)] checks = Extension( "checks", sources=[os.path.join('.', "checks.pyx")], - include_dirs=include_dirs, + include_dirs=[np.get_include()], define_macros=macros, ) -example_limited_api = Extension( - "example_limited_api", - sources=[os.path.join('.', "example_limited_api.c")], - include_dirs=include_dirs, - define_macros=macros, -) - -extensions = [checks, example_limited_api] +extensions = [checks] setup( ext_modules=cythonize(extensions) diff --git a/numpy/core/tests/examples/example_limited_api.c b/numpy/core/tests/examples/limited_api/limited_api.c index e811800b4..698c54c57 100644 --- a/numpy/core/tests/examples/example_limited_api.c +++ b/numpy/core/tests/examples/limited_api/limited_api.c @@ -1,8 +1,3 @@ -/* - * Test that third-party extensions that use the Numpy C API can be built with - * the limited Python C API (see https://docs.python.org/3/c-api/stable.html). - */ - #define Py_LIMITED_API 0x03060000 #include <Python.h> @@ -11,10 +6,10 @@ static PyModuleDef moduledef = { .m_base = PyModuleDef_HEAD_INIT, - .m_name = "example_limited_api" + .m_name = "limited_api" }; -PyMODINIT_FUNC PyInit_example_limited_api(void) +PyMODINIT_FUNC PyInit_limited_api(void) { import_array(); import_umath(); diff --git a/numpy/core/tests/examples/limited_api/setup.py b/numpy/core/tests/examples/limited_api/setup.py new file mode 100644 index 000000000..18747dc80 --- /dev/null +++ b/numpy/core/tests/examples/limited_api/setup.py @@ -0,0 +1,22 @@ +""" +Build an example package using the limited Python C API. +""" + +import numpy as np +from setuptools import setup, Extension +import os + +macros = [("NPY_NO_DEPRECATED_API", 0), ("Py_LIMITED_API", "0x03060000")] + +limited_api = Extension( + "limited_api", + sources=[os.path.join('.', "limited_api.c")], + include_dirs=[np.get_include()], + define_macros=macros, +) + +extensions = [limited_api] + +setup( + ext_modules=extensions +) diff --git a/numpy/core/tests/test_cython.py b/numpy/core/tests/test_cython.py index a1f09d0fe..9896de0ec 100644 --- a/numpy/core/tests/test_cython.py +++ b/numpy/core/tests/test_cython.py @@ -32,7 +32,7 @@ def install_temp(request, tmp_path): # Based in part on test_cython from random.tests.test_extending here = os.path.dirname(__file__) - ext_dir = os.path.join(here, "examples") + ext_dir = os.path.join(here, "examples", "cython") cytest = str(tmp_path / "cytest") diff --git a/numpy/core/tests/test_limited_api.py b/numpy/core/tests/test_limited_api.py new file mode 100644 index 000000000..0bb543d59 --- /dev/null +++ b/numpy/core/tests/test_limited_api.py @@ -0,0 +1,41 @@ +import os +import shutil +import subprocess +import sys +import sysconfig +import pytest + + +@pytest.mark.xfail( + sysconfig.get_config_var("Py_DEBUG"), + reason=( + "Py_LIMITED_API is incompatible with Py_DEBUG, Py_TRACE_REFS, " + "and Py_REF_DEBUG" + ), +) +def test_limited_api(tmp_path): + """Test building a third-party C extension with the limited API.""" + # Based in part on test_cython from random.tests.test_extending + + 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_call( + [ + sys.executable, + "setup.py", + "build", + "install", + "--prefix", str(tmp_path / "installdir"), + "--single-version-externally-managed", + "--record", + install_log, + ], + cwd=cytest, + ) |