-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.py
93 lines (72 loc) · 2.47 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
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
85
86
87
88
89
90
91
92
93
import os
from pathlib import Path
import setuptools
from setuptools import Extension
import numpy
curr_file = Path(__file__).parent.absolute()
version = "0.6.1"
USE_CYTHON = True # command line option, try-import, ...
ext = ".pyx" if USE_CYTHON else ".c"
targ_path = curr_file / "src" / "SBART" / "utils" / "cython_codes"
pyx_files = list(targ_path.glob(f"**/*{ext}"))
targets = {}
for entry in pyx_files:
parts = entry.relative_to(curr_file).parts
parts = parts[1:-1] + (parts[-1].split(".")[0],)
targets[".".join(parts)] = (entry.relative_to(curr_file)).as_posix()
# https://cython.readthedocs.io/en/latest/src/userguide/source_files_and_compilation.html#distributing-cython-modules
def no_cythonize(extensions, **_ignore):
for extension in extensions:
sources = []
for sfile in extension.sources:
path, ext = os.path.splitext(sfile)
if ext in (".pyx", ".py"):
if extension.language == "c++":
ext = ".cpp"
else:
ext = ".c"
sfile = path + ext
sources.append(sfile)
extension.sources[:] = sources
return extensions
ext_modules = [
Extension(
key,
[value],
extra_compile_args=["-fopenmp"],
extra_link_args=["-fopenmp"],
)
for key, value in targets.items()
]
compiler_directives = {"language_level": 3, "embedsignature": True}
if USE_CYTHON:
import Cython.Compiler.Options
from Cython.Build import cythonize
Cython.Compiler.Options.annotate = True
from Cython.Build import cythonize
ext_modules = cythonize(
ext_modules,
compiler_directives=compiler_directives,
)
from distutils.core import setup
all_packages = setuptools.find_packages(where="src", include=["SBART*"])
requ_path = Path(__file__).parent
with open(requ_path / "requirements.txt") as f:
required = f.read().splitlines()
setup(
name="SBART",
package_dir={"": "src"},
version=version,
description="Python Distribution Utilities",
packages=all_packages,
include_package_data=True,
ext_modules=ext_modules,
install_requires=required,
include_dirs=[numpy.get_include()],
# package_data={"SBART": ["utils/tapas_downloader",
# "resources/*",
# "outside_tools/*",
# "utils/cython_codes/cubic_interpolation/__init__.py"
# ]
# }
)