-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathsetup.py
More file actions
63 lines (49 loc) · 1.76 KB
/
Copy pathsetup.py
File metadata and controls
63 lines (49 loc) · 1.76 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import builtins
import os
import sys
from pathlib import Path
from setuptools import Extension, setup
from setuptools.command.build_ext import build_ext
try:
from Cython.Build import cythonize # isort:skip
except ImportError:
wmsg = "WARNING: Cython unavailable, unable to build stratify extensions"
print(wmsg)
cythonize = None
PACKAGE_NAME = "stratify"
CMDS_NOCYTHONIZE = ["clean", "sdist"]
class NumpyBuildExt(build_ext):
# Delay numpy import so that setup.py can be run
# without numpy already being installed.
def finalize_options(self):
build_ext.finalize_options(self)
builtins.__NUMPY_SETUP__ = False
import numpy
self.include_dirs.append(numpy.get_include())
cython_coverage_enabled = os.environ.get("CYTHON_COVERAGE", None)
cython_directives = {}
# TODO: investigate "'PyArrayObject' has no member named 'dimensions'" cython error
# https://cython.readthedocs.io/en/latest/src/userguide/source_files_and_compilation.html#configuring-the-c-build
# define_macros = [("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")]
define_macros = []
extensions = []
if cythonize and cython_coverage_enabled:
define_macros.append(("CYTHON_TRACE_NOGIL", "1"))
cython_directives.update({"linetrace": True})
for fname in Path.cwd().glob(f"{PACKAGE_NAME}/*.pyx"):
extensions.append(
Extension(
f"{PACKAGE_NAME}.{fname.stem}",
sources=[str(fname)],
define_macros=define_macros,
)
)
if cythonize and not any([arg in CMDS_NOCYTHONIZE for arg in sys.argv]):
extensions = cythonize(
extensions, compiler_directives=cython_directives, language_level=3
)
kwargs = dict(
cmdclass={"build_ext": NumpyBuildExt},
ext_modules=extensions,
)
setup(**kwargs)