-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.py
More file actions
152 lines (126 loc) · 4.28 KB
/
Copy pathsetup.py
File metadata and controls
152 lines (126 loc) · 4.28 KB
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
import os
import sysconfig
import tempfile
from distutils.errors import CompileError
from setuptools import Extension, find_packages, setup
from setuptools.command.build_ext import build_ext
from typing import List, Optional, Tuple
from Cython.Build import cythonize
from Cython.Compiler import Options
import numpy as np
def has_flag(compiler, flagname):
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 CompileError:
return False
return True
def flag_filter(compiler, *flags):
result = []
for flag in flags:
if has_flag(compiler, flag):
result.append(flag)
return result
class BuildExt(build_ext):
compile_flags = {"msvc": ['/std:c++14'], "unix": ["-std=c++14"]}
def build_extensions(self):
ct = self.compiler.compiler_type
opts = self.compile_flags.get(ct, [])
if ct == 'unix':
# Only add flags which pass the `flag_filter`
opts += flag_filter(
self.compiler,
"-Wno-misleading-indentation",
"-fno-var-tracking-assignments"
)
for ext in self.extensions:
ext.extra_compile_args = list(set(opts) | set(ext.extra_compile_args))
build_ext.build_extensions(self)
Options.fast_fail = True
PYTHON_REQUIRES = ">=3.6"
TRACE_CYTHON = bool(int(os.getenv("TRACE_CYTHON", 0)))
cython_macros: List[Tuple[str, Optional[str]]] = [
("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")
]
if TRACE_CYTHON:
cython_macros.append(("CYTHON_TRACE_NOGIL", None))
cflags_base = sysconfig.get_config_var('CFLAGS') or ""
cflags_env = os.getenv("CFLAGS", "")
cflags_set = set(cflags_base.split() + cflags_env.split())
cflags_set.discard('-Wstrict-prototypes') # not valid for C++
ldflags_base = sysconfig.get_config_var('LDFLAGS') or ""
ldflags_env = os.getenv("LDFLAGS", "")
ldflags_set = set(ldflags_base.split() + ldflags_env.split())
extensions = [
Extension(
"*",
["src/commonnn/*.pyx"],
define_macros=cython_macros,
language="c++",
include_dirs=[np.get_include()],
extra_compile_args=list(cflags_set),
extra_link_args=list(ldflags_set)
)
]
compiler_directives = {
"language_level": 3,
"binding": True,
"embedsignature": True,
"boundscheck": False,
"wraparound": False,
"cdivision": True,
"nonecheck": False,
"linetrace": True,
"annotation_typing": False
}
extensions = cythonize(extensions, compiler_directives=compiler_directives)
with open("README.md", "r") as readme:
desc = readme.read()
sdesc = "A Python package for common-nearest-neighbours clustering"
requirements_map = {
"mandatory": "",
"optional": "-optional",
"dev": "-dev",
"docs": "-docs",
"test": "-test",
}
requirements = {}
for category, fname in requirements_map.items():
with open(f"requirements{fname}.txt") as fp:
requirements[category] = fp.read().strip().split("\n")
setup(
name="commonnn-clustering",
version="0.0.4",
keywords=["density-based clustering"],
author="Jan-Oliver Joswig",
author_email="jan.joswig@fu-berlin.de",
description=sdesc,
long_description=desc,
long_description_content_type="text/markdown",
url="https://github.com/bkellerlab/CommonNNClustering",
packages=find_packages("src"),
package_dir={"": "src"},
package_data={"cnnclustering": ["*.pxd"]},
classifiers=[
"Development Status :: 3 - Alpha",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
cmdclass={'build_ext': BuildExt},
ext_modules=extensions,
install_requires=requirements["mandatory"],
extras_require={
"optional": requirements["optional"],
"dev": requirements["dev"],
"docs": requirements["docs"],
"test": requirements["test"],
},
zip_safe=False,
)