import re
import shutil
from pathlib import Path

from setuptools import setup, find_packages


VERSION = {}  # type: ignore
with open("ddochi/__version__.py", "r") as version_file:
    exec(version_file.read(), VERSION)


# Remove stale dooly.egg-info directory to avoid https://github.com/pypa/pip/issues/5466
stale_egg_info = Path(__file__).parent / "ddochi.egg-info"
if stale_egg_info.exists():
    print(
        (
            "Warning: {} exists.\n\n"
            "If you recently updated dooly, this is expected,\n"
            "but it may prevent dooly from installing in editable mode.\n\n"
            "This directory is automatically generated by Python's packaging tools.\n"
            "I will remove it now.\n\n"
            "See https://github.com/pypa/pip/issues/5466 for details.\n"
        ).format(stale_egg_info)
    )
    shutil.rmtree(stale_egg_info)


_deps = [
    "black~=22.0",
    "flake8>=3.8.3",
    "datasets",
    "numpy>=1.17",
    "filelock",
    "huggingface-hub>=0.1.0,<1.0",
    "importlib_metadata",
    "requests",
    "regex",
    "packaging>=20.0",
    "pyyaml>=5.1",
    "tqdm>=4.27",
    "torch>=1.0",
    "tokenizers>=0.11.1,!=0.11.3",
    "transformers>=4.22.0",
    "nltk",
]

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


def deps_list(*pkgs):
    return [deps[pkg] for pkg in pkgs]


extras = {}

install_requires = [
    deps["filelock"],  # filesystem locks, e.g., to prevent parallel downloads
    deps["huggingface-hub"],
    deps["datasets"],
    deps["numpy"],
    deps["torch"],
    deps["packaging"],  # utilities from PyPA to e.g., compare versions
    deps["pyyaml"],  # used for the model cards metadata
    deps["regex"],  # for OpenAI GPT
    deps["requests"],  # for downloading models over HTTPS
    deps["tokenizers"],
    deps["transformers"],
    deps["tqdm"],  # progress bars in model download and training scripts
    deps["nltk"],
]


setup(
    name="ddochi",
    version=VERSION["version"],
    url="https://github.com/jinmang2/DDOCHI",
    author="jinmang2",
    author_email="jinmang2@gmail.com",
    description="",
    python_requires=">=3.8.0",
    packages=find_packages(exclude=["tests"]),
    long_description=open("README.md", encoding="utf-8").read(),
    long_description_content_type="text/markdown",
    extras_require=extras,
    install_requires=install_requires,
    zip_safe=False,
    classifiers=[
        "Operating System :: OS Independent",
        "Programming Language :: Python :: 3",
        "Programming Language :: Python :: 3.8",
        "Programming Language :: Python :: 3.9",
        "License :: OSI Approved :: Apache Software License",
    ],
)