import os
import sys
import re
import platform
from setuptools import find_packages, setup

project_name = "deeplake"


this_directory = os.path.abspath(os.path.dirname(__file__))

with open(os.path.join(this_directory, "deeplake/requirements/common.txt")) as f:
    requirements = f.readlines()

with open(os.path.join(this_directory, "deeplake/requirements/tests.txt")) as f:
    tests = f.readlines()

with open(os.path.join(this_directory, "README.md"), encoding="utf-8") as f:
    long_description = f.read()


req_map = {
    b: a
    for a, b in (
        re.findall(r"^(([^!=<>~]+)(?:[!=<>~].*)?$)", x.strip("\n"))[0]
        for x in requirements
    )
}

# Add optional dependencies to this dict without version. Version should be specified in requirements.txt
extras = {
    "audio": ["av"],
    "video": ["av"],
    "av": ["av"],
    "gcp": ["google-cloud-storage", "google-auth", "google-auth-oauthlib"],
    "dicom": ["pydicom"],
    "visualizer": ["IPython", "flask"],
    "gdrive": [
        "google-api-python-client",
        "oauth2client",
        "google-auth",
        "google-auth-oauthlib",
    ],
    "point_cloud": ["laspy"],
}

all_extras = {r for v in extras.values() for r in v}
install_requires = [req_map[r] for r in req_map if r not in all_extras]
extras_require = {k: [req_map[r] for r in v] for k, v in extras.items()}
extras_require["all"] = [req_map[r] for r in all_extras]


init_file = os.path.join(project_name, "__init__.py")


def get_property(prop):
    result = re.search(
        # find variable with name `prop` in the __init__.py file
        rf'{prop}\s*=\s*[\'"]([^\'"]*)[\'"]',
        open(init_file).read(),
    )
    return result.group(1)


def libdeeplake_availabe():
    py_ver = sys.version_info
    if sys.platform == "linux":
        if py_ver >= (3, 6) and py_ver <= (3, 10):
            return True
    if sys.platform == "darwin":
        mac_ver = list(map(int, platform.mac_ver()[0].split(".")))
        if (
            (mac_ver[0] > 10 or mac_ver[0] == 10 and mac_ver[1] >= 12)
            and py_ver >= (3, 7)
            and py_ver <= (3, 10)
        ):
            return True
    return False


if libdeeplake_availabe():
    install_requires.insert(0, "libdeeplake==0.0.25")
install_requires.append("hub>=2.8.7")


config = {
    "name": project_name,
    "version": get_property("__version__"),
    "description": "Activeloop Deep Lake",
    "long_description": long_description,
    "long_description_content_type": "text/markdown",
    "author": "activeloop.ai",
    "author_email": "support@activeloop.ai",
    "packages": find_packages(),
    "install_requires": install_requires,
    "extras_require": extras_require,
    "tests_require": tests,
    "include_package_data": True,
    "zip_safe": False,
    "entry_points": {"console_scripts": ["activeloop = deeplake.cli.commands:cli"]},
    "dependency_links": [],
    "project_urls": {
        "Documentation": "https://docs.activeloop.ai/",
        "Source": "https://github.com/activeloopai/deeplake",
    },
}

setup(**config)

setup.py
import os
import sys
import re
import platform
from setuptools import find_packages, setup

project_name = "deeplake"


this_directory = os.path.abspath(os.path.dirname(__file__))

with open(os.path.join(this_directory, "deeplake/requirements/common.txt")) as f:
    requirements = f.readlines()

with open(os.path.join(this_directory, "deeplake/requirements/tests.txt")) as f:
    tests = f.readlines()

with open(os.path.join(this_directory, "README.md"), encoding="utf-8") as f:
    long_description = f.read()


req_map = {
    b: a
    for a, b in (
        re.findall(r"^(([^!=<>~]+)(?:[!=<>~].*)?$)", x.strip("\n"))[0]
        for x in requirements
    )
}

# Add optional dependencies to this dict without version. Version should be specified in requirements.txt
extras = {
    "audio": ["av"],
    "video": ["av"],
    "av": ["av"],
    "gcp": ["google-cloud-storage", "google-auth", "google-auth-oauthlib"],
    "dicom": ["pydicom"],
    "visualizer": ["IPython", "flask"],
    "gdrive": [
        "google-api-python-client",
        "oauth2client",
        "google-auth",
        "google-auth-oauthlib",
    ],
    "point_cloud": ["laspy"],
}

all_extras = {r for v in extras.values() for r in v}
install_requires = [req_map[r] for r in req_map if r not in all_extras]
extras_require = {k: [req_map[r] for r in v] for k, v in extras.items()}
extras_require["all"] = [req_map[r] for r in all_extras]


init_file = os.path.join(project_name, "__init__.py")


def get_property(prop):
    result = re.search(
        # find variable with name `prop` in the __init__.py file
        rf'{prop}\s*=\s*[\'"]([^\'"]*)[\'"]',
        open(init_file).read(),
    )
    return result.group(1)


def libdeeplake_availabe():
    py_ver = sys.version_info
    if sys.platform == "linux":
        if py_ver >= (3, 6) and py_ver <= (3, 10):
            return True
    if sys.platform == "darwin":
        mac_ver = list(map(int, platform.mac_ver()[0].split(".")))
        if (
            (mac_ver[0] > 10 or mac_ver[0] == 10 and mac_ver[1] >= 12)
            and py_ver >= (3, 7)
            and py_ver <= (3, 10)
        ):
            return True
    return False


if libdeeplake_availabe():
    install_requires.insert(0, "libdeeplake==0.0.25")
install_requires.append("hub>=2.8.7")


config = {
    "name": project_name,
    "version": get_property("__version__"),
    "description": "Activeloop Deep Lake",
    "long_description": long_description,
    "long_description_content_type": "text/markdown",
    "author": "activeloop.ai",
    "author_email": "support@activeloop.ai",
    "packages": find_packages(),
    "install_requires": install_requires,
    "extras_require": extras_require,
    "tests_require": tests,
    "include_package_data": True,
    "zip_safe": False,
    "entry_points": {"console_scripts": ["activeloop = deeplake.cli.commands:cli"]},
    "dependency_links": [],
    "project_urls": {
        "Documentation": "https://docs.activeloop.ai/",
        "Source": "https://github.com/activeloopai/deeplake",
    },
    "license": "MPL-2.0",
    "classifiers": [
        "License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)",
    ],
}

setup(**config)

setup.py
diff --git a/setup.py b/setup.py
index 6ceea3e601..0d1a7b8d3f 100644
--- a/setup.py
+++ b/setup.py
@@ -103,6 +103,10 @@ def libdeeplake_availabe():
         "Documentation": "https://docs.activeloop.ai/",
         "Source": "https://github.com/activeloopai/deeplake",
     },
+    "license": "MPL-2.0",
+    "classifiers": [
+        "License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)",
+    ],
 }
 
 setup(**config)

[FEATURE] Add license in PyPI packages
## 🚨🚨 Feature Request

- [x] A new implementation (Improvement) 

### Is your feature request related to a problem?

deeplake, hub and libdeeplake currently use [Mozilla Public License](https://www.mozilla.org/en-US/MPL/) (MPL). However they do not advertise their license in their respective PyPI packages. This makes automatic license checks (`liccheck`) fail. 

### Description of the possible solution

Add license and license classifiers in `setup.cfg` for hub, deeplake and libdeeplake.
Syntax:
> setup.cfg
```
[metadata]
license = MPL 2.0
license_file = LICENSE
classifiers = 
	License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)
```

References:
- https://setuptools.pypa.io/en/latest/deprecated/distutils/setupscript.html#additional-meta-data
- https://pypi.org/classifiers/
- https://github.com/SethMMorton/natsort/blob/master/setup.cfg
