-
Notifications
You must be signed in to change notification settings - Fork 8
/
setup.py
executable file
·84 lines (73 loc) · 2.95 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
import os
import setuptools
from setuptools import Extension, setup
from setuptools.command.build_ext import build_ext
# We use Python's Limited API, for wheel compatibility across Python minor release versions
# (e.g., compatibility across 3.7 and 3.8, but not 4.0). Here we specify the minimum supported
# version.
PY_LIMITED_API_MAJOR = 3
PY_LIMITED_API_MINOR = 2
class BuildExt(build_ext):
"""A custom build extension for adding -stdlib arguments for clang++."""
def build_extensions(self):
# '-std=c++11' is added to `extra_compile_args` so the code can compile
# with clang++. This works across compilers (ignored by MSVC).
for extension in self.extensions:
extension.extra_compile_args.append('-std=c++11')
try:
build_ext.build_extensions(self)
except setuptools.distutils.errors.CompileError:
# Workaround Issue #2.
# '-stdlib=libc++' is added to `extra_compile_args` and `extra_link_args`
# so the code can compile on macOS with Anaconda.
for extension in self.extensions:
extension.extra_compile_args.append('-stdlib=libc++')
extension.extra_link_args.append('-stdlib=libc++')
build_ext.build_extensions(self)
extension = Extension(
'kmeans1d._core',
['kmeans1d/_core.cpp'],
define_macros=[
('Py_LIMITED_API', f'0x{PY_LIMITED_API_MAJOR:02x}{PY_LIMITED_API_MINOR:02x}0000')
],
py_limited_api=True,
)
version_txt = os.path.join(os.path.dirname(__file__), 'kmeans1d', 'version.txt')
with open(version_txt, 'r') as f:
version = f.read().strip()
with open('README.md') as f:
long_description = f.read()
setup(
author='Daniel Steinberg',
author_email='ds@dannyadam.com',
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'Intended Audience :: Science/Research',
'Topic :: Scientific/Engineering',
'Topic :: Scientific/Engineering :: Artificial Intelligence',
'Topic :: Scientific/Engineering :: Information Analysis',
'License :: OSI Approved :: MIT License',
'Operating System :: Unix',
'Operating System :: POSIX :: Linux',
'Operating System :: MacOS',
'Operating System :: Microsoft :: Windows',
'Programming Language :: Python :: 3',
],
cmdclass={'build_ext': BuildExt},
description='A Python package for optimal 1D k-means clustering',
ext_modules=[extension],
keywords=['k-means', 'machine learning', 'optimization'],
license='MIT',
long_description=long_description,
long_description_content_type='text/markdown',
name='kmeans1d',
options={'bdist_wheel':
{'py_limited_api': f'cp{PY_LIMITED_API_MAJOR}{PY_LIMITED_API_MINOR}'}
},
package_data={'kmeans1d': ['version.txt']},
packages=['kmeans1d'],
python_requires='>=3.6',
url='https://github.com/dstein64/kmeans1d',
version=version,
)