# pylint: disable=missing-module-docstring
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",
]

ALT_INSTALL_REQUIRES = {
    "opencv-python-headless": ["opencv-python", "opencv-contrib-python", "opencv-contrib-python-headless"],
}


def check_alternative_installation(install_require, alternative_install_requires):
    """If some version version of alternative requirement installed, return alternative,
    else return main.
    """
    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(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"""
    install_requires = []
    for main_require in main_requires:
        if main_require in alternative_requires:
            main_require = check_alternative_installation(main_require, alternative_requires.get(main_require))
        install_requires.append(main_require)

    return install_requires


INSTALL_REQUIRES = get_install_requirements(INSTALL_REQUIRES, ALT_INSTALL_REQUIRES)

setup(
    name="imgaug",
    version="0.3.0",
    author="Alexander Jung",
    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,
    packages=find_packages(),
    include_package_data=True,
    package_data={
        "": ["LICENSE", "README.md", "requirements.txt"],
        "imgaug": ["DejaVuSans.ttf", "quokka.jpg", "quokka_annotations.json", "quokka_depth_map_halfres.png"],
        "imgaug.checks": ["README.md"]
    },
    license="MIT",
    description="Image augmentation library for deep neural networks",
    long_description=long_description,
    keywords=["augmentation", "image", "deep learning", "neural network", "CNN", "machine learning",
              "computer vision", "overfitting"]
)

@@ -2850,11 +2850,906 @@
 itting%22%5D
+,%0A    classifiers=%5B%0A        %22Development Status :: 4 - Beta%22,%0A        %22Intended Audience :: Science/Research%22,%0A        %22Intended Audience :: Developers%22,%0A        %22Intended Audience :: Information Technology%22,%0A        %22License :: OSI Approved :: MIT License%22,%0A        %22Natural Language :: English%22,%0A        %22Operating System :: OS Independent%22,%0A        %22Programming Language :: Python :: 2.7%22,%0A        %22Programming Language :: Python :: 3%22,%0A        %22Programming Language :: Python :: 3.4%22,%0A        %22Programming Language :: Python :: 3.5%22,%0A        %22Programming Language :: Python :: 3.6%22,%0A        %22Programming Language :: Python :: 3.7%22,%0A        %22Programming Language :: Python :: 3.8%22,%0A        %22Topic :: Scientific/Engineering :: Artificial Intelligence%22,%0A        %22Topic :: Scientific/Engineering :: Image Recognition%22,%0A        %22Topic :: Software Development :: Libraries :: Python Modules%22%0A    %5D
 %0A)%0A

Add classifiers to setup.py