forked from symbolic-kg/PyClause
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
80 lines (62 loc) · 2.44 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
from setuptools import setup, Extension, find_packages, find_namespace_packages
from setuptools.command.build_ext import build_ext
import setuptools
import pybind11
from glob import glob
import shutil
# (c) Sylvain Corlay, https://github.com/pybind/python_example
def has_flag(compiler, flagname):
import tempfile
with tempfile.NamedTemporaryFile("w", suffix=".cpp") as f:
f.write("int main (int argc, char **argv) { return 0; }")
try:
compiler.compile([f.name], extra_postargs=[flagname])
except setuptools.distutils.errors.CompileError:
return False
return True
# (c) Sylvain Corlay, https://github.com/pybind/python_example
def cpp_flag(compiler):
if has_flag(compiler,"-std=c++14"): return "-std=c++14"
raise RuntimeError("Unsupported compiler: at least C++14 support is needed")
# (c) Sylvain Corlay, https://github.com/pybind/python_example
class BuildExt(build_ext):
c_opts = {
"msvc": ["/EHsc", "/O2"],
"unix": ["-O3", "-march=native"],
}
def build_extensions(self):
ct = self.compiler.compiler_type
opts = self.c_opts.get(ct, [])
if ct == "unix":
opts.append('-DVERSION_INFO="%s"' % self.distribution.get_version())
opts.append(cpp_flag(self.compiler))
opts.append("-fopenmp") # assumes openmp is supported
# opts.append("-w") # uncommment to suppress warnings
elif ct == "msvc":
opts.append('/DVERSION_INFO=\\"%s\\"' % self.distribution.get_version())
opts.append("/openmp")
for ext in self.extensions:
ext.extra_compile_args = opts
ext.extra_link_args = ["-fopenmp"] # assumes openmp is supported
build_ext.build_extensions(self)
ext_modules = [
Extension(
"c_clause", # needs to match module name in cpp bindings
["bindings.cpp"] + glob("src/c_clause/core/*.cpp") + glob("src/c_clause/features/*.cpp") + glob("src/c_clause/*.cpp") + glob("src/c_clause/api/*.cpp"),
include_dirs=[
pybind11.get_include(False),
pybind11.get_include(True ),
],
language="c++",
),
]
setup(
name = "PyClause",
ext_modules = ext_modules,
install_requires = ["pybind11>=2.2.0", "numpy", "flatdict", "pyyaml"],
cmdclass = {"build_ext": BuildExt},
zip_safe = False,
packages = find_packages(),
package_data = {"clause": ["config-default.yaml", "bin/amie-anyburl-integration.jar", "bin/AnyBURL-23-1.jar"]},
python_requires = ">=3.7"
)