# coding=utf-8
import os
import shutil
from intelliw import __version__
from setuptools import setup, find_packages


def move_base_file(infile, outfile):
    """move intelliw/scaffolding/resources/iw.py to workdir """
    shutil.copy(infile, outfile)


def parse_requirements(path):
    """ load requirements from a pip requirements file. (replacing from pip.req import parse_requirements)"""
    with open(path, 'r', encoding='utf8') as fd:
        return [r.strip() for r in fd.readlines()]


def long_description_load(filename):
    with open(filename, "r", encoding='utf8') as fh:
        long_description = fh.read()
    return long_description


def purge_pycache(path):
    for file_name in os.listdir(path):
        abs_path = os.path.join(path, file_name)
        if file_name in ("__pycache__", "logs"):
            shutil.rmtree(abs_path)
            print(f"delete: {abs_path}")
        elif os.path.isdir(abs_path):
            purge_pycache(abs_path)


install_requires = parse_requirements('requirements/requirements-base.txt')
extras_require = {
    "all": parse_requirements('requirements/requirements.txt')
}
long_description = long_description_load('README.md')
purge_pycache('intelliw')

setup(
    name='intelliw',
    version=__version__,
    author='yonyou',
    author_email='yonyou@yonyou.com',
    url="http://git.yonyou.com/iuapaipaas/iw-algo-fx",
    python_requires='>=3.6',

    description='An easy to start Intelligent Workshop Algorithm Framework',
    long_description=long_description,
    long_description_content_type="text/markdown",

    classifiers=[
        'Development Status :: 3 - Alpha',
        'Programming Language :: Python :: 3.6',
        'Programming Language :: Python :: 3.7',
        'Programming Language :: Python :: 3.8',
        'Programming Language :: Python :: 3.9',
        'Programming Language :: Python :: 3.10',
        'Programming Language :: Python :: 3.11',
        'Programming Language :: Python :: 3.12',
        'Operating System :: OS Independent',
    ],

    packages=find_packages(),
    install_requires=install_requires,
    extras_require=extras_require,
    include_package_data=True,

    entry_points={
        'console_scripts': [
            'intelliw = intelliw.interface.entrypoint:run'
        ]
    },

)
