-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathsetup.py
146 lines (124 loc) · 4.08 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
#!/usr/bin/python
import sys
import codecs
import setuptools
from setuptools import Extension
from setuptools.command.build_ext import build_ext
with codecs.open("README.md", encoding="utf-8") as f:
long_description = f.read()
ext_modules = [
Extension(
"mrptlib",
["cpp/mrptmodule.cpp"],
language="c++",
)
]
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
class BuildExt(build_ext):
"""A custom build extension for adding compiler-specific options.
Assume that C++14 is available.
"""
c_opts = {
"unix": [
"-std=c++14",
"-O3",
"-fPIC",
"-DNDEBUG",
"-DEIGEN_DONT_PARALLELIZE",
"-Wl,--no-undefined",
],
"msvc": [
"/std:c++14",
"/O2",
"/EHsc",
"/DNDEBUG",
"/DEIGEN_DONT_PARALLELIZE",
"/wd4244",
],
}
link_opts = {
"unix": ["-pthread"],
"msvc": [],
}
def build_extensions(self):
ct = self.compiler.compiler_type
opts = self.c_opts.get(ct, [])
link_opts = self.link_opts.get(ct, [])
if ct == "unix":
opts.extend(
[
"-fassociative-math",
"-fno-signaling-nans",
"-fno-trapping-math",
"-fno-signed-zeros",
"-freciprocal-math",
"-fno-math-errno",
]
)
for flag in ["-fvisibility=hidden", "-march=native", "-mcpu=native"]:
if has_flag(self.compiler, flag):
opts.append(flag)
if sys.platform == "darwin":
opts.extend(["-stdlib=libc++", "-mmacosx-version-min=11.0"])
link_opts.extend(["-stdlib=libc++", "-mmacosx-version-min=11.0"])
if has_flag(self.compiler, "-fopenmp"):
opts.append("-fopenmp")
link_opts.append("-lomp")
else:
opts.append("-fopenmp")
link_opts.append("-lgomp")
elif ct == "msvc":
opts.append("/openmp")
import numpy as np
for ext in self.extensions:
ext.extra_compile_args.extend(opts)
ext.extra_link_args.extend(link_opts)
ext.include_dirs.extend(
[
"cpp/lib",
# Path to numpy headers
np.get_include(),
]
)
build_ext.build_extensions(self)
setuptools.setup(
name="mrpt",
author="Ville Hyvönen",
author_email="ville.o.hyvonen@helsinki.fi",
version="2.0.1",
description="Fast nearest neighbor search with random projection",
long_description=long_description,
long_description_content_type="text/markdown",
url="http://github.com/vioshyvo/mrpt",
license="MIT",
classifiers=[
"Development Status :: 5 - Production/Stable",
"License :: OSI Approved :: MIT License",
"Programming Language :: C++",
"Programming Language :: Python",
"Topic :: Database :: Database Engines/Servers",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Operating System :: MacOS",
"Operating System :: POSIX :: Linux",
"Operating System :: Microsoft :: Windows",
],
keywords="vector search, approximate nearest neighbor search",
packages={".": "mrpt"},
zip_safe=False,
ext_modules=ext_modules,
install_requires=["numpy"],
test_suite="py.test",
cmdclass={"build_ext": BuildExt},
)