Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathsetup.py
More file actions
Latest commit
84 lines (69 loc) · 2.38 KB
/
Copy pathsetup.py
File metadata and controls
84 lines (69 loc) · 2.38 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# Copyright python-stratify contributors
#
# This file is part of python-stratify and is released under the BSD license.
# See LICENSE in the root of the repository for full licensing details.
importos
frompathlibimportPath
importsys
importwarnings
# safe to import numpy here thanks to pep518
importnumpyasnp
fromsetuptoolsimportCommand, Extension, setup
try:
fromCython.Buildimportcythonize# isort:skip
exceptImportError:
wmsg="Cython unavailable, unable to build stratify extensions!"
warnings.warn(wmsg)
cythonize=None
BASE_DIR=Path(__file__).resolve().parent
PACKAGE_NAME="stratify"
SRC_DIR=BASE_DIR/"src"
STRATIFY_DIR=SRC_DIR/PACKAGE_NAME
CMDS_NOCYTHONIZE= ["clean", "sdist"]
FLAG_COVERAGE="--cython-coverage"# custom flag enabling Cython line tracing
classCleanCython(Command):
description="Purge artifacts built by Cython"
user_options= []
definitialize_options(self):
pass
deffinalize_options(self):
pass
defrun(self):
forpathinSTRATIFY_DIR.rglob("*"):
ifpath.suffixin (".pyc", ".pyo", ".c", ".so"):
msg=f"clean: removing file {path}"
print(msg)
path.unlink()
cython_coverage_enabled= (
os.environ.get("CYTHON_COVERAGE", None) orFLAG_COVERAGEinsys.argv
)
cython_directives= {}
define_macros= []
extensions= []
ifcythonizeandcython_coverage_enabled:
define_macros.extend(
[
("CYTHON_TRACE", "1"),
("CYTHON_TRACE_NOGIL", "1"),
]
)
cython_directives.update({"linetrace": True})
ifFLAG_COVERAGEinsys.argv:
sys.argv.remove(FLAG_COVERAGE)
print('enabled "linetrace" Cython compiler directive')
forfnameinSRC_DIR.glob(f"{PACKAGE_NAME}/*.pyx"):
# ref: https://setuptools.pypa.io/en/latest/userguide/ext_modules.html
extension=Extension(
f"{PACKAGE_NAME}.{fname.stem}",
sources=[str(fname.relative_to(BASE_DIR))],
include_dirs=[np.get_include()],
define_macros=define_macros,
)
extensions.append(extension)
ifcythonizeandnotany([arginCMDS_NOCYTHONIZEforarginsys.argv]):
extensions=cythonize(
extensions, compiler_directives=cython_directives, language_level=3
)
cmdclass= {"clean_cython": CleanCython}
kwargs= {"cmdclass": cmdclass, "ext_modules": extensions}
setup(**kwargs)