-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsetup.py
103 lines (88 loc) · 3.13 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
from copy import deepcopy
import os
import sys
import versioneer
if sys.version_info[0] < 3:
import __builtin__ as builtins
else:
import builtins
try:
import numpy
except ImportError as e:
raise ImportError("cyflann requires numpy to be installed:\n{}".format(e))
# Don't do this in the setup() requirements, because otherwise pip and
# friends get too eager about updating numpy.
try:
from setuptools import setup, Command
from setuptools.extension import Extension
from setuptools.command.build_ext import build_ext
from pprint import pprint
class PrintInfoCommand(Command):
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
global flann_info
pprint(flann_info)
except ImportError:
from distutils.core import setup
from distutils.extension import Extension
from distutils.command.build_ext import build_ext
class PrintInfoCommand():
pass
# A hack, following sklearn: set a global variable so that cyflann.__init__
# knows not to try to import compiled extensions that aren't built yet during
# the setup process.
builtins.__CYFLANN_SETUP__ = True
from cyflann.flann_info import get_flann_info
flann_info = get_flann_info()
try:
from Cython.Build import cythonize
except ImportError:
src_path = os.path.join(os.path.dirname(__file__), 'cyflann')
if not os.path.exists(os.path.join(src_path, 'index.c')):
msg = "index extension needs to be compiled but cython isn't available"
raise ImportError(msg)
ext_modules = [
Extension("cyflann.index", ["cyflann/index.c"]),
]
else:
ext_modules = cythonize([
Extension("cyflann.index", ["cyflann/index.pyx"],
depends=["cyflann/index.pxd", "cyflann/flann.pxd"])
])
for ext in ext_modules:
ext.__dict__.update(deepcopy(flann_info))
ext.include_dirs.append(numpy.get_include())
cmdclass = versioneer.get_cmdclass()
cmdclass['flann_info'] = PrintInfoCommand
setup(
name='cyflann',
version=versioneer.get_version(),
author='Dougal J. Sutherland',
author_email='dougal@gmail.com',
packages=['cyflann', 'cyflann.tests'],
package_data={'cyflann': ['*.pyx', '*.pxd']},
url='https://github.com/dougalsutherland/cyflann',
description='A Cython-based interface to the FLANN nearest neighbors '
'library.',
long_description=open('README.rst').read(),
license='BSD 3-clause',
ext_modules=ext_modules,
cmdclass=cmdclass,
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.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Cython",
"Programming Language :: Python :: Implementation :: CPython",
],
zip_safe=False, # not unsafe but no point, since it's just a c ext
)