-
Notifications
You must be signed in to change notification settings - Fork 123
/
setup.py
86 lines (73 loc) · 2.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
import os.path
from setuptools import setup, find_packages, Extension
from setuptools.command.build_ext import build_ext as _build_ext
import sys
import warnings
try:
from Cython.Build import cythonize
USE_CYTHON = True
except ImportError:
USE_CYTHON = False
# numpy path is needed for building with and without cython:
try:
import numpy
numpy_includes = [numpy.get_include()]
HAVE_NUMPY = True
except ImportError:
# "python setup.py build" will not work and trigger fallback to pure python later on,
# but "python setup.py clean" will be successful with the first call of setup(...)
numpy_includes = []
HAVE_NUMPY = False
classifiers = [
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 3',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: MIT License',
'Topic :: Scientific/Engineering'
]
class build_ext(_build_ext):
def finalize_options(self):
_build_ext.finalize_options(self)
# Prevent numpy from thinking it is still in its setup process:
__builtins__.__NUMPY_SETUP__ = False
import numpy
self.include_dirs.append(numpy.get_include())
ext = '.pyx' if USE_CYTHON else '.cpp'
extensions = [Extension(
'fastdtw._fastdtw',
[os.path.join('fastdtw', '_fastdtw' + ext)],
language="c++",
include_dirs=numpy_includes,
libraries=["stdc++"]
)]
if USE_CYTHON:
extensions = cythonize(extensions)
dir_path = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(dir_path, 'README.rst')) as f:
long_description = f.read()
needs_pytest = set(['pytest', 'test', 'ptr']).intersection(sys.argv)
pytest_runner = ['pytest-runner'] if needs_pytest else []
kwargs = {
'name': 'fastdtw',
'version': '0.3.4',
'author': 'Kazuaki Tanida',
'url': 'https://github.com/slaypni/fastdtw',
'description': 'Dynamic Time Warping (DTW) algorithm with an O(N) time and memory complexity.',
'long_description': long_description,
'license': 'MIT',
'keywords': ['dtw'],
'install_requires': ['numpy'],
'packages': find_packages(),
'ext_modules': extensions,
'test_suite': 'tests',
'setup_requires': pytest_runner,
'tests_require': ['pytest'],
'classifiers': classifiers
}
try:
setup(**kwargs)
except SystemExit:
del kwargs['ext_modules']
reason = 'numpy missing, ' if not HAVE_NUMPY else ''
warnings.warn(reason+'compilation failed. Installing pure python package')
setup(**kwargs)