import os
import sys

from setuptools import find_packages, setup
from setuptools.command.test import test as TestCommand


tests_require = [
    'check-manifest>=0.25',
    'coverage>=4.0',
    'isort>=4.2.2',
    'pep257>=0.7.0',
    'pytest-cache>=1.0',
    'pytest-cov>=1.8.0',
    'pytest-pep8>=1.0.6',
    'pytest>=2.8.0',
    'Flask-CeleryExt>=0.1.0',
    'Flask-CLI>=0.2.1',
    'Flask-Mail>=0.9.1',
]

extras_require = {
    'celery': [
        'celery>=3.1.0',
    ],
    'docs': [
        'Sphinx>=1.3',
    ],
    'tests': tests_require,
}

extras_require['all'] = []
for reqs in extras_require.values():
    extras_require['all'].extend(reqs)

setup_requires = [
    'Babel>=1.3',
]

install_requires = [
    'Flask-BabelEx>=0.9.2',
    'Flask-Login<0.3.0,>=0.2.11',
    'Flask-Menu>=0.4.0',
    'Flask-Security>=1.7.4',
    'invenio-base>=1.0.0a1',
    'invenio-db>=1.0.0a4',
    'SQLAlchemy-Utils[ipaddress]>=0.31.0',
]

packages = find_packages()


class PyTest(TestCommand):

    """PyTest Test."""

    user_options = [('pytest-args=', 'a', "Arguments to pass to py.test")]

    def initialize_options(self):
        """Init pytest."""
        TestCommand.initialize_options(self)
        self.pytest_args = []
        try:
            from ConfigParser import ConfigParser
        except ImportError:
            from configparser import ConfigParser
        config = ConfigParser()
        config.read('pytest.ini')
        self.pytest_args = config.get('pytest', 'addopts').split(' ')

    def finalize_options(self):
        """Finalize pytest."""
        TestCommand.finalize_options(self)
        if hasattr(self, '_test_args'):
            self.test_suite = ''
        else:
            self.test_args = []
            self.test_suite = True

    def run_tests(self):
        """Run tests."""
        # import here, cause outside the eggs aren't loaded
        import pytest
        errno = pytest.main(self.pytest_args)
        sys.exit(errno)

setup(
    name='irrelevant-flask-test-thing-pls',
    version='0.0',
    description=__doc__,
    long_description='tl;dr',
    keywords='why does it not work',
    license='GPLv2',
    author='Jeremy Knackintosh',
    author_email='',
    url='https://github.com/otron/flask-minimal-testing-issue.git',
    packages=packages,
    zip_safe=False,
    include_package_data=True,
    platforms='any',
    entry_points=None,
    extras_require=extras_require,
    install_requires=install_requires,
    setup_requires=setup_requires,
    tests_require=tests_require,
    classifiers=[
        'Environment :: Web Environment',
        'Intended Audience :: Developers',
        'License :: OSI Approved :: GNU General Public License v2 (GPLv2)',
        'Operating System :: OS Independent',
        'Programming Language :: Python',
        'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
        'Topic :: Software Development :: Libraries :: Python Modules',
        'Programming Language :: Python :: 2',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.3',
        'Programming Language :: Python :: 3.4',
        'Programming Language :: Python :: 3.5',
        'Development Status :: 3 - Alpha',
    ],
    cmdclass={'test': PyTest},
)
