-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.py
39 lines (35 loc) · 1.2 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import os
import sys
from distutils.extension import Extension
from pathlib import Path
import numpy as np
from Cython.Build import cythonize
from setuptools import setup
SRC_DIR = Path(__file__).parent / "src" / "gpgi"
if os.getenv("GPGI_PY_LIB", "0").lower() in ("1", "true"):
if not SRC_DIR.joinpath("_lib.py").exists():
raise RuntimeError(
"GPGI's pure Python implementation can only be built "
"from the development version in editable mode."
)
ext_modules = []
pattern = "*.pyd" if sys.platform.startswith("win") else "*.so"
for sofile in SRC_DIR.glob(pattern):
os.remove(sofile)
else:
ext_modules = cythonize(
[
Extension(
"gpgi._lib",
sources=["src/gpgi/_lib.pyx"],
include_dirs=[np.get_include()],
define_macros=[
# keep in sync with runtime requirements (pyproject.toml)
("NPY_TARGET_VERSION", "NPY_1_25_API_VERSION"),
("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION"),
],
)
],
compiler_directives={"language_level": 3},
)
setup(ext_modules=ext_modules)