Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
yt-project
GitHub Repository: yt-project/yt
Path: blob/main/setup.py
925 views
1
import glob
2
import os
3
import sys
4
from collections import defaultdict
5
from distutils.ccompiler import get_default_compiler
6
from importlib import resources as importlib_resources
7
8
from setuptools import Distribution, setup
9
10
# ensure enclosing directory is in PYTHON_PATH to allow importing from setupext.py
11
if (script_dir := os.path.dirname(__file__)) not in sys.path:
12
sys.path.insert(0, script_dir)
13
14
from setupext import (
15
NUMPY_MACROS,
16
check_CPP14_flags,
17
check_for_openmp,
18
check_for_pyembree,
19
create_build_ext,
20
get_python_include_dirs,
21
install_ccompiler,
22
)
23
24
install_ccompiler()
25
26
if os.path.exists("MANIFEST"):
27
os.remove("MANIFEST")
28
29
with open("README.md") as file:
30
long_description = file.read()
31
32
CPP14_CONFIG = defaultdict(
33
lambda: check_CPP14_flags(["-std=c++14", "-std=c++1y", "-std=gnu++0x"]),
34
{"msvc": ["/std:c++14"]},
35
)
36
CPP11_CONFIG = defaultdict(lambda: ["-std=c++11"], {"msvc": ["/std:c++11"]})
37
38
_COMPILER = get_default_compiler()
39
40
omp_args, _ = check_for_openmp()
41
42
if os.name == "nt":
43
std_libs = []
44
else:
45
std_libs = ["m"]
46
47
CPP14_FLAG = CPP14_CONFIG[_COMPILER]
48
CPP11_FLAG = CPP11_CONFIG[_COMPILER]
49
50
FIXED_INTERP = "fixed_interpolator"
51
52
cythonize_aliases = {
53
"LIB_DIR": "yt/utilities/lib/",
54
"LIB_DIR_GEOM": ["yt/utilities/lib/", "yt/geometry/"],
55
"LIB_DIR_GEOM_ARTIO": [
56
"yt/utilities/lib/",
57
"yt/geometry/",
58
"yt/frontends/artio/artio_headers/",
59
],
60
"STD_LIBS": std_libs,
61
"EWAH_LIBS": std_libs
62
+ [os.path.abspath(importlib_resources.files("ewah_bool_utils"))],
63
"OMP_ARGS": omp_args,
64
"FIXED_INTERP": FIXED_INTERP,
65
"ARTIO_SOURCE": sorted(glob.glob("yt/frontends/artio/artio_headers/*.c")),
66
"CPP14_FLAG": CPP14_FLAG,
67
"CPP11_FLAG": CPP11_FLAG,
68
}
69
70
lib_exts = [
71
"yt/geometry/*.pyx",
72
"yt/utilities/cython_fortran_utils.pyx",
73
"yt/frontends/ramses/io_utils.pyx",
74
"yt/frontends/gamer/cfields.pyx",
75
"yt/utilities/lib/cykdtree/kdtree.pyx",
76
"yt/utilities/lib/cykdtree/utils.pyx",
77
"yt/frontends/artio/_artio_caller.pyx",
78
"yt/utilities/lib/*.pyx",
79
]
80
81
embree_libs, embree_aliases = check_for_pyembree(std_libs)
82
cythonize_aliases.update(embree_aliases)
83
lib_exts += embree_libs
84
85
# This overrides using lib_exts, so it has to happen after lib_exts is fully defined
86
build_ext, sdist, bdist_wheel = create_build_ext(lib_exts, cythonize_aliases)
87
88
89
# Force setuptools to consider that there are ext modules, even if empty.
90
# See https://github.com/yt-project/yt/issues/2922 and
91
# https://stackoverflow.com/a/62668026/2601223 for the fix.
92
class BinaryDistribution(Distribution):
93
"""Distribution which always forces a binary package with platform name."""
94
95
def has_ext_modules(self):
96
return True
97
98
99
if __name__ == "__main__":
100
# Avoid a race condition on fixed_interpolator.o during parallel builds by
101
# building it only once and storing it in a static library.
102
# See https://github.com/yt-project/yt/issues/4278 and
103
# https://github.com/pypa/setuptools/issues/3119#issuecomment-2076922303
104
# for the inspiration for this fix.
105
106
# build_clib doesn't add the Python include dirs (for Python.h) by default,
107
# as opposed to build_ext, so we need to add them manually.
108
clib_include_dirs = get_python_include_dirs()
109
110
# fixed_interpolator.cpp uses Numpy types
111
import numpy
112
113
clib_include_dirs.append(numpy.get_include())
114
115
fixed_interp_lib = (
116
FIXED_INTERP,
117
{
118
"sources": ["yt/utilities/lib/fixed_interpolator.cpp"],
119
"include_dirs": clib_include_dirs,
120
"define_macros": NUMPY_MACROS,
121
},
122
)
123
124
setup(
125
cmdclass={"sdist": sdist, "build_ext": build_ext, "bdist_wheel": bdist_wheel},
126
distclass=BinaryDistribution,
127
libraries=[fixed_interp_lib],
128
ext_modules=[], # !!! We override this inside build_ext above
129
)
130
131