From aea750051f7660cf61dbd2360a25ea0bd13efa3b Mon Sep 17 00:00:00 2001 From: Rinat Shigapov Date: Thu, 21 Nov 2019 09:34:26 -0600 Subject: [PATCH] fix dependencies (#146) * fix requirements * don't reuse build dependencies between different envs * minor fix * change the order of opencv and opencv-headless --- .dockerignore | 6 ++++++ .travis.yml | 2 +- Dockerfile | 7 +++++++ README.rst | 4 ++++ requirements.txt | 6 ------ setup.py | 32 +++++++++++++++++++++++++++++--- 6 files changed, 47 insertions(+), 10 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile delete mode 100644 requirements.txt diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..8c22f226d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +.git +.gitignore +*.egg-info +.eggs/ +.mypy-cache +pip-wheel-metadata diff --git a/.travis.yml b/.travis.yml index 4bffded0e..77a5c788f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ before_install: - sudo apt-get install -y ffmpeg install: - - pip install Cython opencv-python pyyaml codecov flake8 yapf isort + - rm -rf .eggs && pip install -e . codecov flake8 yapf isort cache: pip: true diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..e163b312c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.7 + +WORKDIR /mmcv + +COPY . /mmcv + +RUN pip install -e . diff --git a/README.rst b/README.rst index bcf56745d..b2fb2e8ed 100644 --- a/README.rst +++ b/README.rst @@ -48,3 +48,7 @@ or install from source git clone https://github.com/open-mmlab/mmcv.git cd mmcv pip install -e . + +Note: If you would like to use :code:`opencv-python-headless` instead of :code:`opencv-python`, +e.g., in a minimum container environment or servers without GUI, +you can first install it before installing MMCV to skip the installation of :code:`opencv-python`. \ No newline at end of file diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 3d3b616ca..000000000 --- a/requirements.txt +++ /dev/null @@ -1,6 +0,0 @@ -addict -numpy>=1.11.1 -pyyaml -six -requests -opencv-python diff --git a/setup.py b/setup.py index f07d49b21..85911a4cb 100644 --- a/setup.py +++ b/setup.py @@ -1,17 +1,43 @@ import platform +import re import sys from io import open # for Python 2 (identical to builtin in Python 3) -from setuptools import Extension, find_packages, setup, dist +from setuptools import Extension, dist, find_packages, setup + +from pkg_resources import DistributionNotFound, get_distribution dist.Distribution().fetch_build_eggs(['Cython', 'numpy>=1.11.1']) import numpy # noqa: E402 from Cython.Distutils import build_ext # noqa: E402 + +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) + + install_requires = [ - 'numpy>=1.11.1', 'pyyaml', 'six', 'addict', 'requests', 'opencv-python', - 'Cython' + 'numpy>=1.11.1', + 'pyyaml', + 'six', + 'addict', + 'requests', ] +# 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)) + if sys.version_info < (3, 3): install_requires.append('backports.shutil_get_terminal_size') if sys.version_info < (3, 4):