#!/usr/bin/env python
import os
import sys

from setuptools import find_packages, setup

_MIN_PY_VERSION = ({{py_versions[0][0]}}, {{py_versions[0][2:]}})


def read(fname):
    return open(os.path.join(os.path.dirname(__file__), fname), encoding="utf-8").read()


def get_version():
    with open("{{name}}/__init__.py", encoding="utf-8") as init_file:
        for line in init_file.readlines():
            if line.startswith("__version__"):
                return line.split(" = ")[1].rstrip()[1:-1]
    raise ValueError("Version not found in name/__init__.py")


def check_min_py_version():
    if sys.version_info[:2] < _MIN_PY_VERSION:
        raise RuntimeError(
            f"Python version >= {'.'.join(map(str, _MIN_PY_VERSION))} required."
        )


def main():
    check_min_py_version()
    setup(
        name="{{name}}",
        version=get_version(),
        author="{{author}}",
        author_email="{{email}}",
        description="{{description}}",
        license="GPLv3",
        keywords="{{keywords}}",
        url="{{repository}}",
        project_urls={
            "Source": "{{repository}}",
            "Tracker": "{{repository}}/issues",
        },
        packages=find_packages(exclude=["*.tests", "*.tests.*", "tests.*", "tests"]),
        package_data={"{{name}}": ["py.typed"]},
        include_package_data=True,
        long_description_content_type="text/x-rst",
        long_description=read("README.rst"),
        install_requires=read("requirements.txt").splitlines(),
        python_requires=">={{py_versions[0]}}",
        classifiers=[
            "Programming Language :: Python :: 3",
            {%- for py_version in py_versions %}
            "Programming Language :: Python :: {{py_version}}",
            {%- endfor %}
            "Programming Language :: Python :: Implementation :: CPython",
            "License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
            "Development Status :: 3 - Alpha",
        ],
        entry_points={"console_scripts": ["{{name}}={{name}}.main:main"]},
    )


if __name__ == "__main__":
    main()
