forked from menpo/cyvlfeat
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsetup.py
90 lines (77 loc) · 3.01 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
from setuptools import setup, find_packages, Extension
import pkg_resources
from Cython.Build import cythonize
import os.path as op
import os
import platform
import fnmatch
import versioneer
INCLUDE_DIRS = [pkg_resources.resource_filename('numpy', 'core/include')]
LIBRARY_DIRS = []
SYS_PLATFORM = platform.system().lower()
IS_WIN = platform.system() == 'Windows'
IS_LINUX = 'linux' in SYS_PLATFORM
IS_OSX = 'darwin' == SYS_PLATFORM
IS_UNIX = IS_LINUX or IS_OSX
IS_CONDA = os.environ.get('CONDA_BUILD', False)
def walk_for_package_data(ext_pattern):
paths = []
for root, dirnames, filenames in os.walk('cyvlfeat'):
for filename in fnmatch.filter(filenames, ext_pattern):
# Slice cyvlfeat off the beginning of the path
paths.append(
op.relpath(os.path.join(root, filename), 'cyvlfeat'))
return paths
def gen_extension(path_name, sources):
kwargs = {
'sources': sources,
'include_dirs': INCLUDE_DIRS,
'library_dirs': LIBRARY_DIRS,
'libraries': ['vl'],
'language': 'c'
}
if IS_UNIX:
kwargs['extra_compile_args'] = ['-Wno-unused-function']
return Extension(path_name, **kwargs)
# If we are building from the conda folder,
# then we know we can manually copy some files around
# because we have control of the setup. If you are
# building this manually or pip installing, you must satisfy
# that the vlfeat vl folder is on the PATH (for the headers)
# and that the vl.dll file is visible to the build system
# as well.
if IS_WIN and IS_CONDA:
conda_bin_dir = os.environ['LIBRARY_BIN']
conda_vl_dll_path = op.join(conda_bin_dir, 'vl.dll')
INCLUDE_DIRS.append(os.environ['LIBRARY_INC'])
LIBRARY_DIRS.append(conda_bin_dir)
vl_extensions = [
gen_extension('cyvlfeat.quickshift.cyquickshift',
[op.join('cyvlfeat', 'quickshift', 'cyquickshift.pyx')]),
gen_extension('cyvlfeat.sift.cysift',
[op.join('cyvlfeat', 'sift', 'cysift.pyx')]),
gen_extension('cyvlfeat.fisher.cyfisher',
[op.join('cyvlfeat', 'fisher', 'cyfisher.pyx')]),
gen_extension('cyvlfeat.hog.cyhog',
[op.join('cyvlfeat', 'hog', 'cyhog.pyx')]),
gen_extension('cyvlfeat.kmeans.cykmeans',
[op.join('cyvlfeat', 'kmeans', 'cykmeans.pyx')]),
gen_extension('cyvlfeat.generic.generic',
[op.join('cyvlfeat', 'generic', 'generic.pyx')]),
gen_extension('cyvlfeat.gmm.cygmm',
[op.join('cyvlfeat', 'gmm', 'cygmm.pyx')])
]
# Grab all the pyx and pxd Cython files for uploading to pypi
cython_files = walk_for_package_data('*.p[xy][xd]')
setup(
name='cyvlfeat',
version=versioneer.get_version(),
cmdclass=versioneer.get_cmdclass(),
description='Cython wrapper of the VLFeat toolkit',
url='https://github.com/menpo/cyvlfeat',
author='Patrick Snape',
author_email='[email protected]',
ext_modules=cythonize(vl_extensions),
packages=find_packages(),
package_data={'cyvlfeat': cython_files}
)