-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsetup_accel.py
104 lines (93 loc) · 3.34 KB
/
setup_accel.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
#!/usr/bin/env python
import os
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
import versiontools_support
DESCRIPTION = "Compiled components to speed up skl-groups."
with open('README.rst') as f:
LONG_DESCRIPTION = f.read()
NAME = "skl-groups-accel"
AUTHOR = MAINTAINER = "Dougal J. Sutherland"
AUTHOR_EMAIL = MAINTAINER_EMAIL = "dsutherl@cs.cmu.edu"
URL = DOWNLOAD_URL = "https://github.com/dougalsutherland/skl-groups-accel"
LICENSE = "BSD"
CLASSIFIERS = [
"Development Status :: 2 - Pre-Alpha",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: Implementation :: CPython",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"Topic :: Scientific/Engineering :: Image Recognition",
"Topic :: Scientific/Engineering :: Information Analysis",
]
def cython_ext(extension, **kw):
assert len(extension.sources) == 1
base, ext = os.path.splitext(extension.sources[0])
# setuptools sometimes "nicely" turns .pyx into .c for us
assert ext in {'.pyx', '.c'}
pyx_path = base + '.pyx'
c_path = base + '.c'
try:
from Cython.Build import cythonize
except ImportError:
try:
pyx_time = os.path.getmtime(pyx_path)
c_time = os.path.getmtime(c_path)
if pyx_time > c_time:
import datetime
msg = "{pyx_name} file has mtime {pyx_t}, {c_name} has {c_t}"
raise ValueError(msg.format(
pyx_name=os.path.basename(pyx_path),
c_name=os.path.basename(c_path),
pyx_t=datetime.datetime.fromtimestamp(pyx_time),
c_t=datetime.datetime.fromtimestamp(c_time),
))
except (OSError, ValueError) as e:
msg = "{} extension needs to be compiled, but cython not available:"
raise ImportError(msg.format(extension.name) + '\n' + str(e))
else:
extension.sources[0] = c_path
return extension
else:
return cythonize([extension])[0]
# TODO: don't do this for egg_info, etc
import numpy
from cyflann.extensions import FLANNExtension, build_ext_flann
ext_modules = [
cython_ext(FLANNExtension('skl_groups_accel.knn_divs',
['skl_groups_accel/knn_divs.pyx'],
include_dirs=[numpy.get_include()],
extra_compile_args=['-fopenmp'],
extra_link_args=['-fopenmp'])),
]
setup(
name=NAME,
version=':versiontools:skl_groups_accel',
description=DESCRIPTION,
long_description=LONG_DESCRIPTION,
author=AUTHOR,
author_email=AUTHOR_EMAIL,
maintainer=MAINTAINER,
maintainer_email=MAINTAINER_EMAIL,
url=URL,
download_url=DOWNLOAD_URL,
license=LICENSE,
classifiers=CLASSIFIERS,
packages=[
'skl_groups_accel',
],
ext_modules=ext_modules,
cmdclass={'build_ext': build_ext_flann},
install_requires=[
'cyflann >= 0.1.22',
],
zip_safe=False,
)