From f9bacff6de9bfad802012c3cb00407b58dd8a3dc Mon Sep 17 00:00:00 2001 From: Florient CHOUTEAU Date: Mon, 20 Jan 2020 13:39:55 +0100 Subject: [PATCH 1/4] Add check in setup.py that replaces `opencv-python-headless` by `opencv-python` if `opencv-python` is already installed --- setup.py | 58 +++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 47 insertions(+), 11 deletions(-) diff --git a/setup.py b/setup.py index 2968b9b70..84c819155 100644 --- a/setup.py +++ b/setup.py @@ -1,9 +1,55 @@ +import re + +from pkg_resources import get_distribution, DistributionNotFound from setuptools import setup, find_packages long_description = """A library for image augmentation in machine learning experiments, particularly convolutional neural networks. Supports the augmentation of images, keypoints/landmarks, bounding boxes, heatmaps and segmentation maps in a variety of different ways.""" +install_requires = [ + "six", + "numpy>=1.15", + "scipy", + "Pillow", + "matplotlib", + "scikit-image>=0.14.2", + "opencv-python-headless", + "imageio", + "Shapely", +] + +alternative_install_requires = {"opencv-python-headless": "opencv-python"} + + +def check_alternative_installation(install_require, alternative_install_require): + """If some version version of alternative requirement installed, return alternative, + else return main. + """ + try: + alternative_pkg_name = re.split(r"[!<>=]", alternative_install_require)[0] + get_distribution(alternative_pkg_name) + except DistributionNotFound: + return install_require + + return str(alternative_install_require) + + +def get_install_requirements(main_requires, alternative_requires): + """Iterates over all install requires + If an install require has an alternative option, check if this option is installed + If that is the case, replace the install require by the alternative to not install dual package""" + new_install_requires = [] + for main_require in main_requires: + if main_require in alternative_requires.keys(): + main_require = check_alternative_installation(main_require, alternative_requires.get(main_require)) + new_install_requires.append(main_require) + + return new_install_requires + + +install_requires = get_install_requirements(install_requires, alternative_install_requires) + setup( name="imgaug", version="0.3.0", @@ -11,17 +57,7 @@ author_email="kontakt@ajung.name", url="https://github.com/aleju/imgaug", download_url="https://github.com/aleju/imgaug/archive/0.3.0.tar.gz", - install_requires=[ - "six", - "numpy>=1.15", - "scipy", - "Pillow", - "matplotlib", - "scikit-image>=0.14.2", - "opencv-python-headless", - "imageio", - "Shapely", - ], + install_requires=install_requires, packages=find_packages(), include_package_data=True, package_data={ From b0e2b9b1459f5c19c2775af0a1f00e62df1ff8df Mon Sep 17 00:00:00 2001 From: Florient CHOUTEAU Date: Mon, 20 Jan 2020 18:37:40 +0100 Subject: [PATCH 2/4] Update constant names --- setup.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 84c819155..2b1472b49 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ neural networks. Supports the augmentation of images, keypoints/landmarks, bounding boxes, heatmaps and segmentation maps in a variety of different ways.""" -install_requires = [ +INSTALL_REQUIRES = [ "six", "numpy>=1.15", "scipy", @@ -19,7 +19,7 @@ "Shapely", ] -alternative_install_requires = {"opencv-python-headless": "opencv-python"} +ALT_INSTALL_REQUIRES = {"opencv-python-headless": "opencv-python"} def check_alternative_installation(install_require, alternative_install_require): @@ -48,7 +48,7 @@ def get_install_requirements(main_requires, alternative_requires): return new_install_requires -install_requires = get_install_requirements(install_requires, alternative_install_requires) +INSTALL_REQUIRES = get_install_requirements(INSTALL_REQUIRES, ALT_INSTALL_REQUIRES) setup( name="imgaug", @@ -57,7 +57,7 @@ def get_install_requirements(main_requires, alternative_requires): author_email="kontakt@ajung.name", url="https://github.com/aleju/imgaug", download_url="https://github.com/aleju/imgaug/archive/0.3.0.tar.gz", - install_requires=install_requires, + install_requires=INSTALL_REQUIRES, packages=find_packages(), include_package_data=True, package_data={ From 391d71baf6d579c20cfb445504be9501467ad3a8 Mon Sep 17 00:00:00 2001 From: Florient CHOUTEAU Date: Wed, 22 Jan 2020 11:02:00 +0100 Subject: [PATCH 3/4] Disable C01114 for setup.py as technically it is not a module --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 2b1472b49..3516f1612 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,4 @@ +# pylint: disable=C0114 import re from pkg_resources import get_distribution, DistributionNotFound From 59064b896b7325089bb2e88245b785c16bacde37 Mon Sep 17 00:00:00 2001 From: Florient CHOUTEAU Date: Fri, 24 Jan 2020 09:17:01 +0100 Subject: [PATCH 4/4] Allow multiple alternative installation requires (ex: opencv-contrib-python, opencv-python instead of opencv-python-headless) --- setup.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/setup.py b/setup.py index 3516f1612..d4b769f25 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -# pylint: disable=C0114 +# pylint: disable=missing-module-docstring import re from pkg_resources import get_distribution, DistributionNotFound @@ -20,33 +20,37 @@ "Shapely", ] -ALT_INSTALL_REQUIRES = {"opencv-python-headless": "opencv-python"} +ALT_INSTALL_REQUIRES = { + "opencv-python-headless": ["opencv-python", "opencv-contrib-python", "opencv-contrib-python-headless"], +} -def check_alternative_installation(install_require, alternative_install_require): +def check_alternative_installation(install_require, alternative_install_requires): """If some version version of alternative requirement installed, return alternative, else return main. """ - try: - alternative_pkg_name = re.split(r"[!<>=]", alternative_install_require)[0] - get_distribution(alternative_pkg_name) - except DistributionNotFound: - return install_require + for alternative_install_require in alternative_install_requires: + try: + alternative_pkg_name = re.split(r"[!<>=]", alternative_install_require)[0] + get_distribution(alternative_pkg_name) + return str(alternative_install_require) + except DistributionNotFound: + continue - return str(alternative_install_require) + return str(install_require) def get_install_requirements(main_requires, alternative_requires): """Iterates over all install requires If an install require has an alternative option, check if this option is installed If that is the case, replace the install require by the alternative to not install dual package""" - new_install_requires = [] + install_requires = [] for main_require in main_requires: - if main_require in alternative_requires.keys(): + if main_require in alternative_requires: main_require = check_alternative_installation(main_require, alternative_requires.get(main_require)) - new_install_requires.append(main_require) + install_requires.append(main_require) - return new_install_requires + return install_requires INSTALL_REQUIRES = get_install_requirements(INSTALL_REQUIRES, ALT_INSTALL_REQUIRES)