# Copyright (c) 2021 CloudZero - ALL RIGHTS RESERVED - PROPRIETARY AND CONFIDENTIAL
# Unauthorized copying of this file and/or project, via any medium is strictly prohibited.
# Direct all questions to legal@cloudzero.com

# Note: To use the 'upload' functionality of this file, you must:
#   $ pip install twine
import io
import os
import sys
from shutil import rmtree
from typing import ClassVar

from connections_anycost_iapi import __version__
from setuptools import Command, find_packages, setup

# Package meta-data.
NAME = "feature_connections_anycost_iapi"
DESCRIPTION = "IAPI Interface Files"
URL = "https://github.com/Cloudzero/feature-connections-anycost"
EMAIL = "support@cloudzero.com"
AUTHOR = "CloudZero"

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

# Import the README and use it as the long-description.
# Note: this will only work if 'README.rst' is present in your MANIFEST.in file!
with io.open(os.path.join(here, "README.md"), encoding="utf-8") as f:
    long_description = "\n" + f.read()


class UploadCommand(Command):
    """Support setup.py upload."""

    description = "Build and publish the package."
    user_options: ClassVar = []  # type: ignore

    @staticmethod
    def status(s):
        """Prints things in bold."""
        print("\033[1m{0}\033[0m".format(s))

    def initialize_options(self):
        pass

    def finalize_options(self):
        pass

    def run(self):
        try:
            self.status("Removing previous builds…")
            rmtree(os.path.join(here, "dist"))
        except OSError:
            pass

        self.status("Building Source distribution…")
        os.system("{0} setup.py sdist".format(sys.executable))

        self.status("Uploading the package to PyPi via Twine…")
        os.system("twine upload dist/*")

        sys.exit()


# Where the magic happens:
setup(
    name=NAME,
    version=__version__,
    description=DESCRIPTION,
    long_description=long_description,
    long_description_content_type="text/markdown",
    author=AUTHOR,
    author_email=EMAIL,
    url=URL,
    packages=find_packages(include=["connections_anycost_iapi"]),
    package_data={"connections_anycost_iapi": ["py.typed"]},
    install_requires=["cz-common-python>=4.3.0"],
    include_package_data=True,
    license="UNLICENSED",
    classifiers=[
        "Development Status :: 4 - Beta",
        "Intended Audience :: Developers",
        "Natural Language :: English",
        "Programming Language :: Python",
        "Programming Language :: Python :: 3",
        "Programming Language :: Python :: 3.12",
    ],
    # $ setup.py publish support.
    cmdclass={
        "upload": UploadCommand,
    },
)
