-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py
147 lines (123 loc) · 3.93 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import sys
import os.path
import itertools
from glob import iglob
import os
from setuptools import setup, Extension
import pybind11
pkgname = "scarf"
version = "0.1.0"
user_cflags = os.getenv("DUCC0_CFLAGS", "").split(" ")
user_cflags = [x for x in user_cflags if x != ""]
user_lflags = os.getenv("DUCC0_LFLAGS", "").split(" ")
user_lflags = [x for x in user_lflags if x != ""]
compilation_strategy = os.getenv("SCARF_OPTIMIZATION", "native")
if compilation_strategy not in [
"none",
"none-debug",
"portable",
"portable-debug",
"native",
"native-debug",
]:
raise RuntimeError("unknown compilation strategy")
do_debug = compilation_strategy in ["none-debug", "portable-debug", "native-debug"]
do_optimize = compilation_strategy not in ["none", "none-debug"]
do_native = compilation_strategy in ["native", "native-debug"]
def _get_files_by_suffix(directory, suffix):
path = directory
iterable_sources = (
iglob(os.path.join(root, "*." + suffix)) for root, dirs, files in os.walk(path)
)
return list(itertools.chain.from_iterable(iterable_sources))
include_dirs = [
".",
"ducc/src/",
pybind11.get_include(True),
pybind11.get_include(False),
]
extra_compile_args = ["-std=c++17"]
if do_debug:
extra_compile_args += ["-g"]
else:
extra_compile_args += ["-g0"]
if do_optimize:
extra_compile_args += ["-ffast-math", "-O3"]
else:
extra_compile_args += ["-O0"]
if do_native:
extra_compile_args += ["-march=native"]
python_module_link_args = []
define_macros = [("PKGNAME", pkgname), ("PKGVERSION", '"%s"' % version)]
if sys.platform == "darwin":
import distutils.sysconfig
extra_compile_args += ["-mmacosx-version-min=10.14"]
python_module_link_args += ["-mmacosx-version-min=10.14", "-bundle"]
cfg_vars = distutils.sysconfig.get_config_vars()
cfg_vars["LDSHARED"] = cfg_vars["LDSHARED"].replace("-bundle", "")
elif sys.platform == "win32":
extra_compile_args = ["/EHsc", "/std:c++17"]
if do_optimize:
extra_compile_args += ["/Ox"]
else:
if do_optimize:
extra_compile_args += [
"-Wfatal-errors",
"-Wfloat-conversion",
"-W",
"-Wall",
"-Wstrict-aliasing=2",
"-Wwrite-strings",
"-Wredundant-decls",
"-Woverloaded-virtual",
"-Wcast-qual",
"-Wcast-align",
"-Wpointer-arith",
]
python_module_link_args += ["-Wl,-rpath,$ORIGIN"]
if do_native:
python_module_link_args += ["-march=native"]
extra_compile_args += user_cflags
python_module_link_args += user_lflags
# if you want debugging info, remove the "-s" from python_module_link_args
depfiles = (
_get_files_by_suffix(".", "h") + _get_files_by_suffix(".", "cc") + ["setup.py"]
)
extensions = [
Extension(
pkgname,
language="c++",
sources=["scarf/scarf.cc"],
depends=depfiles,
include_dirs=include_dirs,
define_macros=define_macros,
extra_compile_args=extra_compile_args,
extra_link_args=python_module_link_args,
)
]
this_directory = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(this_directory, "README.rst"), encoding="utf-8") as f:
long_description = f.read()
setup(
name=pkgname,
version=version,
description="Spherical Harmonic Transforms for CMB lensing",
long_description=long_description,
long_description_content_type="text/x-rst",
include_package_data=True,
url="https://github.com/samuelsimko/scarf",
author="Samuel Simko",
author_email="[email protected]",
packages=[],
ext_modules=extensions,
install_requires=["numpy>=1.17.0"],
license="MIT",
project_urls={
"Bug Tracker": "https://github.com/samuelsimko/scarf/issues",
},
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
)