This repository has been archived by the owner on Apr 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 132
/
setup.py
134 lines (114 loc) · 4.5 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
import os
import platform
import sys
import Cython
import pkg_resources
from Cython.Distutils import build_ext as _build_ext
from setuptools import Extension, find_packages, setup
if Cython.__version__ < "0.29":
raise Exception("Please upgrade to Cython 0.29 or newer")
setup_dir = os.path.abspath(os.path.dirname(__file__))
def read_file(filename):
filepath = os.path.join(setup_dir, filename)
with open(filepath) as file:
return file.read()
class build_ext(_build_ext):
def build_extensions(self):
print("Running custom build_ext")
numpy_incl = pkg_resources.resource_filename("numpy", "core/include")
if sys.platform == "darwin":
# Platform: Mac OS
version, _, _ = platform.mac_ver()
parts = version.split(".")
# major = int(parts[0])
minor = int(parts[1])
# patch = int(parts[2]) if len(parts) == 3 else None
if minor >= 15:
# Greater than Mac OS: 10.15
extra_compile_args = [
"-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Accelerate.framework/Versions/Current/Frameworks/vecLib.framework/Headers/"
]
elif minor >= 10:
# Greater than Mac OS: 10.10
extra_compile_args = [
"-I/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/Current/Headers"
]
else:
extra_compile_args = [
"-I/System/Library/Frameworks/vecLib.framework/Headers"
]
ext_module = Extension(
name="bh_sne",
sources=[
"tsne/includes/bh_tsne/quadtree.cpp",
"tsne/includes/bh_tsne/tsne.cpp",
"tsne/bh_sne.pyx",
],
include_dirs=["tsne/includes/bh_tsne/"],
extra_compile_args=extra_compile_args,
extra_link_args=["-Wl,-framework", "-Wl,Accelerate", "-lcblas"],
language="c++",
)
self.extensions.append(ext_module)
else:
# Platform: Linux
extra_link_args = ["-lcblas"]
ext_module = Extension(
name="bh_sne",
sources=[
"tsne/includes/bh_tsne/quadtree.cpp",
"tsne/includes/bh_tsne/tsne.cpp",
"tsne/bh_sne.pyx",
],
include_dirs=[
"/usr/local/include",
"tsne/includes/bh_tsne/",
],
library_dirs=["/usr/local/lib"],
extra_compile_args=["-msse2", "-O3", "-fPIC", "-w"],
extra_link_args=extra_link_args,
language="c++",
)
self.extensions.append(ext_module)
self.extensions = [ext for ext in self.extensions if ext.name != "__dummy__"]
for ext in self.extensions:
if hasattr(ext, "include_dirs") and numpy_incl not in ext.include_dirs:
ext.include_dirs.append(numpy_incl)
_build_ext.build_extensions(self)
# Dummy extension to trigger build_ext
ext_module = Extension("__dummy__", sources=[])
setup(
name="tsne",
use_scm_version=True,
packages=find_packages(),
# package_dir={"": "src"},
zip_safe=False,
include_package_data=True,
package_data={"tsne": ["includes/*"]},
# data_files=data_files,
ext_modules=[ext_module],
cmdclass={"build_ext": build_ext},
# entry_points = {},
options={"bdist_wheel": {"universal": "1"}},
python_requires=">=3.7",
setup_requires=["setuptools_scm"],
install_requires=read_file("requirements.txt").splitlines(),
extras_require={
"test": ["pytest", "pytest-cov", "toml"],
"dev": read_file("requirements-dev.txt").splitlines(),
},
description="TSNE algorithms",
long_description=read_file("README.md"),
long_description_content_type="text/markdown",
license="Apache License, Version 2.0",
maintainer="Daniel Rodriguez",
maintainer_email="[email protected]",
url="https://github.com/danielfrg/tsne",
keywords=["TSNE", "algorithms", "numpy", "cython"],
classifiers=[
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
],
)