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