8000 TST: Split example package, skip limited API test for debug · numpy/numpy@1edd640 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1edd640

Browse files
committed
TST: Split example package, skip limited API test for debug
1 parent a61474e commit 1edd640

File tree

6 files changed

+68
-18
lines changed

6 files changed

+68
-18
lines changed

numpy/core/tests/examples/setup.py renamed to numpy/core/tests/examples/cython/setup.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,16 @@
99
from setuptools.extension import Extension
1010
import os
1111

12-
include_dirs = [np.get_include()]
1312
macros = [("NPY_NO_DEPRECATED_API", 0)]
1413

1514
checks = Extension(
1615
"checks",
1716
sources=[os.path.join('.', "checks.pyx")],
18-
include_dirs=include_dirs,
17+
include_dirs=[np.get_include()],
1918
define_macros=macros,
2019
)
2120

22-
example_limited_api = Extension(
23-
"example_limited_api",
24-
sources=[os.path.join('.', "example_limited_api.c")],
25-
include_dirs=include_dirs,
26-
define_macros=macros,
27-
)
28-
29-
extensions = [checks, example_limited_api]
21+
extensions = [checks]
3022

3123
setup(
3224
ext_modules=cythonize(extensions)

numpy/core/tests/examples/example_limited_api.c renamed to numpy/core/tests/examples/limited_api/limited_api.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
/*
2-
* Test that third-party extensions that use the Numpy C API can be built with
3-
* the limited Python C API (see https://docs.python.org/3/c-api/stable.html).
4-
*/
5-
61
#define Py_LIMITED_API 0x03060000
72

83
#include <Python.h>
@@ -11,10 +6,10 @@
116

127
static PyModuleDef moduledef = {
138
.m_base = PyModuleDef_HEAD_INIT,
14-
.m_name = "example_limited_api"
9+
.m_name = "limited_api"
1510
};
1611

17-
PyMODINIT_FUNC PyInit_example_limited_api(void)
12+
PyMODINIT_FUNC PyInit_limited_api(void)
1813
{
1914
import_array();
2015
import_umath();
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""
2+
Build an example package using the limited Python C API.
3+
"""
4+
5+
import numpy as np
6+
from setuptools import setup, Extension
7+
import os
8+
9+
macros = [("NPY_NO_DEPRECATED_API", 0), ("Py_LIMITED_API", "0x03060000")]
10+
11+
limited_api = Extension(
12+
"limited_api",
13+
sources=[os.path.join('.', "limited_api.c")],
14+
include_dirs=[np.get_include()],
15+
define_macros=macros,
16+
)
17+
18+
extensions = [limited_api]
19+
20+
setup(
21+
ext_modules=extensions
22+
)

numpy/core/tests/test_cython.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def install_temp(request, tmp_path):
3232
# Based in part on test_cython from random.tests.test_extending
3333

3434
here = os.path.dirname(__file__)
35-
ext_dir = os.path.join(here, "examples")
35+
ext_dir = os.path.join(here, "examples", "cython")
3636

3737
cytest = str(tmp_path / "cytest")
3838

numpy/core/tests/test_limited_api.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import os
2+
import shutil
3+
import subprocess
4+
import sys
5+
import sysconfig
6+
import pytest
7+
8+
9+
@pytest.mark.xfail(
10+
sysconfig.get_config_var("Py_DEBUG"),
11+
reason=(
12+
"Py_LIMITED_API is incompatible with Py_DEBUG, Py_TRACE_REFS, "
13+
"and Py_REF_DEBUG"
14+
),
15+
)
16+
def test_limited_api(tmp_path):
17+
"""Test building a third-party C extension with the limited API."""
18+
# Based in part on test_cython from random.tests.test_extending
19+
20+
here = os.path.dirname(__file__)
21+
ext_dir = os.path.join(here, "examples", "limited_api")
22+
23+
cytest = str(tmp_path / "limited_api")
24+
25+
shutil.copytree(ext_dir, cytest)
26+
# build the examples and "install" them into a temporary directory
27+
28+
install_log = str(tmp_path / "tmp_install_log.txt")
29+
subprocess.check_call(
30+
[
31+
sys.executable,
32+
"setup.py",
33+
"build",
34+
"install",
35+
"--prefix", str(tmp_path / "installdir"),
36+
"--single-version-externally-managed",
37+
"--record",
38+
install_log,
39+
],
40+
cwd=cytest,
41+
)

0 commit comments

Comments
 (0)
0