-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
BUG: Fix build of third-party extensions with Py_LIMITED_API #20818
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
Merged
seberg
merged 3 commits into
numpy:main
from
lpsinger:test-third-party-c-extensions-limited-api
Jan 14, 2022
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#define Py_LIMITED_API 0x03060000 | ||
|
||
#include <Python.h> | ||
#include <numpy/arrayobject.h> | ||
#include <numpy/ufuncobject.h> | ||
|
||
static PyModuleDef moduledef = { | ||
.m_base = PyModuleDef_HEAD_INIT, | ||
.m_name = "limited_api" | ||
}; | ||
|
||
PyMODINIT_FUNC PyInit_limited_api(void) | ||
{ | ||
import_array(); | ||
import_umath(); | ||
return PyModule_Create(&moduledef); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.