-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.py
133 lines (117 loc) · 3.35 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
from Cython.Build import cythonize
from Cython.Distutils import build_ext
from Cython import Build
from setuptools import setup
from setuptools.extension import Extension
import numpy, multiprocessing as mp, os
import re, os
from subprocess import run
add = []
compiler = "g++"
cppv = "11"
if not "g14" in os.uname():
compiler = "g++"
cppv = "2a"
os.environ["CXX"] = compiler
os.environ["CC"] = compiler
optFlag = "-Ofast"
flags = (
f"{optFlag} -march=native -std=c++{cppv} -flto "
"-frename-registers -funroll-loops -fno-wrapv "
"-fopenmp-simd -fopenmp -Wfatal-errors"
)
# collect pyx files
exts = []
# baseDir = os.getcwd() + os.path.sep +
BASE = "imi"
nums = numpy.get_include()
import plexsim
plex = plexsim.get_include()
print("-" * 32)
print(plex)
print("-" * 32)
for (root, dirs, files) in os.walk(BASE):
for file in files:
fileName = os.path.join(root, file)
if file.endswith(".pyx"):
# some cython shenanigans
# extPath = fileName.replace(baseDir, '') # make relative
extPath = os.path.join(root, file)
extName, extension = os.path.splitext(
extPath.replace(os.path.sep, ".")
) # remove extension
print(extension, extName)
# extName = extName.replace("core.", '')
sources = [extPath]
ex = Extension(
extName,
sources=sources,
include_dirs=[nums, ".", plex],
extra_compile_args=flags.split(),
language="c++",
extra_link_args=[
"-fopenmp",
f"-std=c++{cppv}",
# '-g'
]
+ add,
define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")],
)
exts.append(ex)
def find_pxd(base) -> list:
"""
package pxd files
"""
data_files = []
for root, dirs, files in os.walk(base):
for file in files:
if file.split(".")[-1] in "cpp hpp h c pxd".split():
# base = os.path.basename(base)
file = os.path.join(root, file)
print(root, file)
data_files.append([root, [file]])
return data_files
data_files = find_pxd("imi")
cdirectives = dict(
boundscheck=False,
cdivision=True,
initializedcheck=False,
overflowcheck=False,
nonecheck=False,
binding=True,
# embedsignature = True,
)
from setuptools import find_packages, find_namespace_packages
__version__ = 2.0
pbase = "imi"
# todo: make prettier
package_data = {
"": "*.pxd *.pyx *.cpp *.hpp".split(),
"models": "*.pxd *.pyx".split(),
# "plexsim": "*.pxd *.pyx *.cpp *.hpp".split(),
# "imi.core" : "*.pxd *.pyx".split(),
}
exclude = [""]
# exclude = []
packages = find_packages(exclude=exclude)
print(packages)
for package in packages:
print(f"found {package}")
setup(
name="imi",
version=__version__,
author="Casper van Elteren",
author_email="[email protected]",
url="cvanelteren.github.io",
zip_safe=False,
# namespace_packages = namespaces,
include_package_data=True,
data_files=data_files,
package_data=package_data,
packages=packages,
ext_modules=cythonize(
exts,
compiler_directives=cdirectives,
nthreads=mp.cpu_count(),
),
)