forked from chainer/chainercv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
118 lines (88 loc) · 2.96 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env python
"""
Parts of this file were taken from Pandas project,
(https://github.com/pandas-dev/pandas)
which have released under BSD 3-clause "New" or "Revised" License.
"""
from distutils.core import setup
import os
import pkg_resources
from setuptools.command import sdist
from setuptools import find_packages
from distutils.extension import Extension
description = """
Collection of Deep Learning Computer Vision Algorithms implemented in Chainer
"""
setup_requires = ['numpy']
install_requires = [
'chainer>=6.0',
'Pillow'
]
ext_data = {
'utils.bbox._nms_gpu_post': {'pyxfile': 'utils/bbox/_nms_gpu_post'}
}
try:
from Cython.Distutils import build_ext as _build_ext
use_cython = True
except ImportError:
from distutils.command.build_ext import build_ext as _build_ext
use_cython = False
for name, data in ext_data.items():
src = os.path.join('chainercv', data['pyxfile'] + '.pyx')
if not os.path.exists(src):
use_cython = False
break
suffix = '.pyx' if use_cython else '.c'
extensions = []
for name, data in ext_data.items():
sources = [os.path.join('chainercv', data['pyxfile'] + suffix)]
extensions.append(
Extension('chainercv.{}'.format(name),
sources=sources)
)
class CheckingBuildExt(_build_ext):
def check_cython_extensions(self, extensions):
for ext in extensions:
for src in ext.sources:
if not os.path.exists(src):
print("{}: -> [{}]".format(ext.name, ext.sources))
raise Exception("""Cython-generated file '{}' not found.
Cython is required to compile chainercv from a development
branch. Please install Cython or
download a release package of chainercv.
""".format(src))
def build_extensions(self):
self.check_cython_extensions(self.extensions)
# Include NumPy
numpy_incl = pkg_resources.resource_filename('numpy', 'core/include')
for ext in self.extensions:
if (hasattr(ext, 'include_dirs') and
numpy_incl not in ext.include_dirs):
ext.include_dirs.append(numpy_incl)
_build_ext.build_extensions(self)
class Sdist(sdist.sdist):
def __init__(self, *args, **kwargs):
assert use_cython
from Cython.Build import cythonize
for e in extensions:
for src in e.sources:
cythonize(src)
super(sdist.sdist, self).__init__(*args, **kwargs)
cmdclass = {
'build_ext': CheckingBuildExt,
'sdist': Sdist,
}
setup(
name='chainercv',
version='0.13.1',
packages=find_packages(),
author='Yusuke Niitani, Toru Ogawa',
author_email='niitani@preferred.jp, ogawa@preferred.jp',
license='MIT',
description=description,
setup_requires=setup_requires,
install_requires=install_requires,
include_package_data=True,
ext_modules=extensions,
cmdclass=cmdclass,
)