setup.py 3.1 KB
Newer Older
Kai Chen's avatar
Kai Chen committed
1
import platform
Rinat Shigapov's avatar
Rinat Shigapov committed
2
import re
3
import sys
4
from io import open  # for Python 2 (identical to builtin in Python 3)
Rinat Shigapov's avatar
Rinat Shigapov committed
5
from pkg_resources import DistributionNotFound, get_distribution
lizz's avatar
lizz committed
6
from setuptools import Extension, dist, find_packages, setup
7

8
9
dist.Distribution().fetch_build_eggs(['Cython', 'numpy>=1.11.1'])

lizz's avatar
lizz committed
10
11
import numpy  # NOQA: E402  # isort:skip
from Cython.Distutils import build_ext  # NOQA: E402  # isort:skip
12

Rinat Shigapov's avatar
Rinat Shigapov committed
13
14
15
16
17
18
19
20
21
22
23
24
25
26

def choose_requirement(primary, secondary):
    """If some version of primary requirement installed, return primary,
    else return secondary.
    """
    try:
        name = re.split(r'[!<>=]', primary)[0]
        get_distribution(name)
    except DistributionNotFound:
        return secondary

    return str(primary)


Kai Chen's avatar
Kai Chen committed
27
install_requires = [
Rinat Shigapov's avatar
Rinat Shigapov committed
28
29
30
31
32
    'numpy>=1.11.1',
    'pyyaml',
    'six',
    'addict',
    'requests',
Kai Chen's avatar
Kai Chen committed
33
]
Rinat Shigapov's avatar
Rinat Shigapov committed
34
35
36
37
38
39
# If first not installed install second package
CHOOSE_INSTALL_REQUIRES = [('opencv-python-headless>=3', 'opencv-python>=3')]

for main, secondary in CHOOSE_INSTALL_REQUIRES:
    install_requires.append(choose_requirement(main, secondary))

40
41
42
43
44
45
46
if sys.version_info < (3, 3):
    install_requires.append('backports.shutil_get_terminal_size')
if sys.version_info < (3, 4):
    install_requires.extend(['enum34', 'pathlib'])


def readme():
47
    with open('README.rst', encoding='utf-8') as f:
48
49
50
51
52
53
        content = f.read()
    return content


def get_version():
    version_file = 'mmcv/version.py'
54
    with open(version_file, 'r', encoding='utf-8') as f:
55
56
57
58
        exec(compile(f.read(), version_file, 'exec'))
    return locals()['__version__']


Kai Chen's avatar
Kai Chen committed
59
60
61
62
63
64
65
if platform.system() == 'Darwin':
    extra_compile_args = ['-stdlib=libc++']
    extra_link_args = ['-stdlib=libc++']
else:
    extra_compile_args = []
    extra_link_args = []

66
67
68
69
70
71
72
EXT_MODULES = [
    Extension(
        name='mmcv._ext',
        sources=[
            './mmcv/video/optflow_warp/flow_warp.cpp',
            './mmcv/video/optflow_warp/flow_warp_module.pyx'
        ],
73
        include_dirs=[numpy.get_include()],
Kai Chen's avatar
Kai Chen committed
74
75
76
        language='c++',
        extra_compile_args=extra_compile_args,
        extra_link_args=extra_link_args,
77
78
79
    ),
]

80
81
82
83
84
85
86
87
88
setup(
    name='mmcv',
    version=get_version(),
    description='Open MMLab Computer Vision Foundation',
    long_description=readme(),
    keywords='computer vision',
    packages=find_packages(),
    classifiers=[
        'Development Status :: 4 - Beta',
Kai Chen's avatar
Kai Chen committed
89
        'License :: OSI Approved :: Apache Software License',
90
91
92
93
94
95
96
        'Operating System :: OS Independent',
        'Programming Language :: Python :: 2',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.4',
        'Programming Language :: Python :: 3.5',
        'Programming Language :: Python :: 3.6',
97
        'Programming Language :: Python :: 3.7',
98
99
100
101
102
103
104
105
        'Topic :: Utilities',
    ],
    url='https://github.com/open-mmlab/mmcv',
    author='Kai Chen',
    author_email='chenkaidev@gmail.com',
    setup_requires=['pytest-runner'],
    tests_require=['pytest'],
    install_requires=install_requires,
106
107
    ext_modules=EXT_MODULES,
    cmdclass={'build_ext': build_ext},
108
    zip_safe=False)