-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix test 3 native extension build for Python >= 3.12
- Loading branch information
1 parent
0d50e02
commit 99cdd77
Showing
4 changed files
with
44 additions
and
36 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
Godot Engine .* - https://godotengine.org | ||
Pythonscript .* \(CPython .*\) | ||
|
||
|
||
MY initialize | ||
Hello, World ! | ||
MY deinitialize |
This file contains 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 |
---|---|---|
@@ -1,40 +1,18 @@ | ||
import os | ||
import platform | ||
from setuptools import setup | ||
from setuptools import Extension, setup | ||
from Cython.Build import cythonize | ||
from pathlib import Path | ||
|
||
|
||
# Retrieve `Python.h`'s include dir. | ||
# In theory setuptools rely on `sysconfig` to find this information, `sysconfig` being | ||
# generated when Python is installed (typically `make install` after it compilation). | ||
# However we use python-build-standalone which (as it name imply) provide us with a | ||
# standalone Python distribution, hence the install step is part of the build process | ||
# and `sysconfig` provide irrelevant include paths (e.g. on Linux it is done on Docker | ||
# with install in `/install`) | ||
# See: | ||
# - https://github.com/indygreg/python-build-standalone/issues/152 | ||
# - https://gregoryszorc.com/docs/python-build-standalone/main/quirks.html#references-to-build-time-paths | ||
if platform.system() in ("Linux", "Darwin"): | ||
python_include_dir = next(Path(".").parent.glob("addons/pythonscript/*-*/include/python*")) | ||
elif platform.system() == "Windows": | ||
python_include_dir = next(Path(".").parent.glob("addons/pythonscript/*-*/include")) | ||
else: | ||
raise RuntimeError(f"Unsupported platform `{platform.system()}`") | ||
# Same idea: `sysconfig` defines CC=clang, but who knows if the current machine has it ! | ||
os.environ.setdefault("CC", "cc") | ||
|
||
|
||
# Work around cythonize's `include_path` parameter not configuring the C compiler | ||
# (see: https://github.com/cython/cython/issues/1480) | ||
gdextension_api_include_dir = Path("gdextension_api") | ||
|
||
|
||
ext_modules = cythonize("my.pyx") | ||
ext_modules[0].include_dirs = [ | ||
python_include_dir, | ||
gdextension_api_include_dir, | ||
extensions = [ | ||
Extension( | ||
"*", | ||
["my.pyx"], | ||
# C/C++ includes | ||
include_dirs=[str(gdextension_api_include_dir.absolute())], | ||
), | ||
] | ||
setup( | ||
ext_modules=ext_modules, | ||
name="My hello app", | ||
ext_modules=cythonize(extensions), | ||
) |
This file contains 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