from setuptools import setup
from codecs import open
from os import path
import re
import argparse

"""
def get_args():
    parser = argparse.ArgumentParser()
    parser.add_argument('--package_name', type=str, default='test_package_pigeon')
    parser.add_argument('--abstract', type=str, default="", help="This package is ...")
    parser.add_argument('--keywords', type=str, help="keyword1, keyword2, keyword3")
    args = parser.parse_args()
    return args
"""


root_dir = path.abspath(path.dirname(__file__))


def _requirements():
    return [name.rstrip() for name in open(path.join(root_dir, 'requirements.txt')).readlines()]


def _test_requirements():
    return [name.rstrip() for name in open(path.join(root_dir, 'test-requirements.txt')).readlines()]


def main():
    """
    args = get_args()
    package_name = args.package_name
    abstract = args.abstract
    keywords = args.keywords
    """
    package_name = 'test_package_pigeon'
    abstract = "This package is test."
    keywords = "pigeon, package, python, test"

    with open(path.join(root_dir, package_name, '__init__.py')) as f:
        init_text = f.read()
        version = re.search(r'__version__\s*=\s*[\'\"](.+?)[\'\"]', init_text).group(1)
        license = re.search(r'__license__\s*=\s*[\'\"](.+?)[\'\"]', init_text).group(1)
        author = re.search(r'__author__\s*=\s*[\'\"](.+?)[\'\"]', init_text).group(1)
        author_email = re.search(r'__author_email__\s*=\s*[\'\"](.+?)[\'\"]', init_text).group(1)
        url = re.search(r'__url__\s*=\s*[\'\"](.+?)[\'\"]', init_text).group(1)

    assert version
    assert license
    assert author
    assert author_email
    assert url

    with open('README.rst', encoding='utf-8') as f:
        long_description = f.read()


    setup(
        name=package_name,
        packages=[package_name],

        version=version,

        license=license,

        install_requires=_requirements(),
        tests_require=_test_requirements(),

        author=author,
        author_email=author_email,

        url=url,

        description=abstract,
        long_description=long_description,
        keywords=keywords,

        classifiers=[
            'Development Status :: 5 - Production/Stable',
            'License :: OSI Approved :: BSD License',
            'Programming Language :: Python',
            'Programming Language :: Python :: 3',
            'Programming Language :: Python :: 3.4',
            'Programming Language :: Python :: 3.5',
            'Programming Language :: Python :: 3.6',
            'Topic :: Database',
            'Topic :: Software Development :: Libraries :: Python Modules',
        ],
    )

if(__name__=='__main__'):
    main()