# 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 os
import sys
from pathlib import Path
from shutil import rmtree

from setuptools import Command, find_packages, setup

from cost_adaptor_anycost_iapi import __version__

# Package meta-data.
NAME = 'feature_cost_adaptor_anycost_iapi'
DESCRIPTION = 'IAPI Interface Files'
URL = 'https://github.com/Cloudzero/feature-cost-adaptor-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!
long_description = (Path(here) / 'README.md').read_text(encoding='utf-8')


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

    description = 'Build and publish the package.'
    user_options = []  # noqa E225: ignore Mutable class variables should not be used as default arguments

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

    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(f'{sys.executable} setup.py sdist')  # noqa S605: Command injection -- runs setup.py

        self.status('Uploading the package to PyPi via Twine…')
        os.system('twine upload dist/*')  # noqa S605: Command injection -- runs twine

        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=['cost_adaptor_anycost_iapi']),
    package_data={'cost_adaptor_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.13',
    ],
    # $ setup.py publish support.
    cmdclass={
        'upload': UploadCommand,
    },
)
