#!/usr/bin/env python
import os.path

from setuptools import find_packages, setup


def _parse_requirement(line):
    if "#egg=" not in line:
        return line
    # When a requirement is from Git, remove the Git part and keep the egg name.
    # This is needed as setup.py does not want any Git requirements in install_requires
    return line.rpartition("#egg=")[2]


def requirements(path):
    assert os.path.exists(path), "Missing requirements {}".format(path)
    with open(path) as f:
        return list(map(_parse_requirement, f.read().splitlines()))


with open("VERSION") as f:
    VERSION = f.read()

install_requires = requirements("requirements.txt") + requirements("base/requirements.txt")
tests_requires = requirements("tests-requirements.txt")

setup(
    name="arkindex",
    version=VERSION,
    description="Manuscripts indexation framework",
    author="Teklia",
    author_email="abadie@teklia.com",
    url="https://arkindex.teklia.com",
    python_requires=">=3.10",
    install_requires=install_requires,
    test_suite="arkindex.project.runtests.run",
    tests_require=tests_requires,
    extras_require={
        "test": tests_requires,
    },
    packages=find_packages(),
    include_package_data=True,
    py_modules=["arkindex", ],
    entry_points={"console_scripts": ["arkindex=arkindex.manage:main"]},
    scripts=[
        "arkindex/manage.py",
    ],
)