-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsetup.py
198 lines (177 loc) · 6.56 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import sys
import os
import pathlib
import setuptools # noqa, importing this had some side effect?
from distutils.core import setup, Extension
from distutils.command.clean import clean as Clean
import distutils.util
import shutil
from Cython.Build import cythonize
import numpy
# The directory containing this file
HERE = pathlib.Path(__file__).parent
# The text of the README file
README = (HERE / "README.md").read_text(encoding="utf-8")
COMPILE_OPTIONS = list()
LINK_OPTIONS = list()
COMPILER_DIRECTIVES = dict()
DEFINE_MACROS = [("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")]
COMPILER_DIRECTIVES["profile"] = True
COMPILER_DIRECTIVES["linetrace"] = True
# To allow coverage analysis for Cython modules
if os.environ.get("CYTHON_TRACE") == "1":
DEFINE_MACROS.append(("CYTHON_TRACE", "1"))
if os.name == "nt":
# This is for Windows.
# Assumes MSVC, which doesn't seem to support c++11:
# https://docs.microsoft.com/en-us/cpp/build/reference/std-specify-language-standard-version?view=msvc-160
COMPILE_OPTIONS += ["/std:c++14", "/W4", "/O2", "/Zc:__cplusplus"]
if os.name == "posix":
# This is for OS X and Linux.
# Assumes GNU (compatible?) compiler.
# Trying to use the oldest possible standard for maximum
# compatibility. Maybe even older would be possible with current
# extensions.
COMPILE_OPTIONS += ["-std=c++14", "-Wall", "-O3"]
def is_new_osx():
"""Check whether we're on OSX >= 10.10"""
name = distutils.util.get_platform()
if sys.platform != "darwin":
return False
elif name.startswith("macosx-10"):
minor_version = int(name.split("-")[1].split(".")[1])
if minor_version >= 7:
return True
else:
return False
else:
return False
if is_new_osx():
# On Mac, use libc++ because Apple deprecated use of libstdc
COMPILE_OPTIONS.append("-stdlib=libc++")
LINK_OPTIONS.append("-lc++")
# g++ (used by unix compiler on mac) links to libstdc++ as a default lib.
# See: https://stackoverflow.com/questions/1653047/avoid-linking-to-libstdc
LINK_OPTIONS.append("-nodefaultlibs")
try:
numpy_include = numpy.get_include()
except AttributeError:
numpy_include = numpy.get_numpy_include()
# Copied from scikit-learn
class CleanCommand(Clean):
description = "Remove build artifacts from the source tree"
def run(self):
Clean.run(self)
# Remove c files if we are not within a sdist package
cwd = os.path.abspath(os.path.dirname(__file__))
remove_c_files = not os.path.exists(os.path.join(cwd, "PKG-INFO"))
if remove_c_files:
print("Will remove generated .c files")
if os.path.exists("build"):
shutil.rmtree("build")
for dirpath, dirnames, filenames in os.walk("sumu"):
for filename in filenames:
if any(
filename.endswith(suffix)
for suffix in (".so", ".pyd", ".dll", ".pyc")
):
os.unlink(os.path.join(dirpath, filename))
continue
extension = os.path.splitext(filename)[1]
if remove_c_files and extension in [".c", ".cpp"]:
pyx_file = str.replace(filename, extension, ".pyx")
if os.path.exists(os.path.join(dirpath, pyx_file)):
os.unlink(os.path.join(dirpath, filename))
for dirname in dirnames:
if dirname == "__pycache__":
shutil.rmtree(os.path.join(dirpath, dirname))
cmdclass = {"clean": CleanCommand}
exts = [
Extension(
"sumu.scorer",
sources=["sumu/scores/_scorer.pyx"],
include_dirs=["sumu/scores", numpy_include],
language="c++",
define_macros=DEFINE_MACROS,
extra_compile_args=COMPILE_OPTIONS,
extra_link_args=LINK_OPTIONS,
),
Extension(
name="sumu.weight_sum",
sources=[
"sumu/weight_sum/_weight_sum.pyx",
"sumu/weight_sum/CandidateRestrictedScore.cpp",
"sumu/weight_sum/GroundSetIntersectSums.cpp",
"sumu/weight_sum/IntersectSums.cpp",
"sumu/weight_sum/Breal.cpp",
"sumu/weight_sum/common.cpp",
],
include_dirs=["sumu/weight_sum", numpy_include],
language="c++",
define_macros=DEFINE_MACROS,
extra_compile_args=COMPILE_OPTIONS,
extra_link_args=LINK_OPTIONS,
),
Extension(
"sumu.mcmc_moves",
sources=["sumu/_mcmc_moves.pyx"],
include_dirs=[numpy_include],
language="c++",
define_macros=DEFINE_MACROS,
extra_compile_args=COMPILE_OPTIONS,
extra_link_args=LINK_OPTIONS,
),
Extension(
name="sumu.aps",
sources=[
"sumu/aps/_aps.pyx",
"sumu/aps/aps-0.9.1/aps/simple_modular.cpp",
],
include_dirs=["sumu/aps/aps-0.9.1/aps", numpy_include],
language="c++",
define_macros=DEFINE_MACROS,
extra_compile_args=COMPILE_OPTIONS,
extra_link_args=LINK_OPTIONS,
),
]
setup(
name="sumu",
description=(
"Library for working with probabilistic and causal graphical models"
),
long_description=README,
long_description_content_type="text/markdown",
classifiers=[
"Intended Audience :: Science/Research",
"Intended Audience :: Developers",
"License :: OSI Approved",
"Programming Language :: C++",
"Programming Language :: Cython",
"Programming Language :: Python",
"Topic :: Software Development",
"Topic :: Scientific/Engineering",
"Development Status :: 2 - Pre-Alpha",
# How do I know if only POSIX or Unix applies?
"Operating System :: POSIX",
"Operating System :: Unix",
"Operating System :: MacOS",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: Implementation :: CPython",
],
url="https://github.com/jussiviinikka/sumu",
author="Jussi Viinikka",
author_email="jussi.viinikka@helsinki.fi",
license="BSD",
packages=["sumu", "sumu.utils", "sumu.scores"],
install_requires=["numpy", "scipy>=1.6", "psutil"],
package_data={"sumu": ["sources.bib"]},
include_package_data=True,
extras_require={"plotext": ["plotext==4.1.3"]},
cmdclass=cmdclass,
ext_modules=cythonize(
exts, language_level="3", compiler_directives=COMPILER_DIRECTIVES
),
)