#!/usr/bin/env python
# Installs django-scim2

from setuptools import setup
import os
import sys
import unittest
import sys


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


def get_version():
    path = os.path.join(BASE_DIR, 'django_scim', '__init__.py')
    version_line = None
    with open(path) as fp:
        for line in fp:
            if line.startswith('__version__'):
                version_line = line
                break
    if not version_line:
        raise ValueError('Unable to find version line in __init__.py')

    version = version_line.split('=')[1].strip().strip("'")
    return version


def long_description():
    """Get the long description from the README"""
    return open(os.path.join(BASE_DIR, 'README.rst')).read()


def run_tests():
    os.environ['DJANGO_SETTINGS_MODULE'] = os.environ.get('DJANGO_SETTINGS_MODULE', 'test_settings')

    import django
    django.setup()
    from django.test.utils import get_runner
    from django.conf import settings

    # eg. TEST_FILTER=django_scim.tests.test_views.UserTestCase.test_get_user_by_id
    test_filter = os.environ.get('TEST_FILTER')
    test_labels = [test_filter] if test_filter else []

    test_runner = get_runner(settings)
    failures = test_runner(
        pattern='test_*.py',
        verbosity=1,
        interactive=True
    ).run_tests(test_labels)
    sys.exit(failures)


setup(
    name='django-scim2',
    version=get_version(),
    description='A partial implementation of the SCIM 2.0 provider specification for use with Django.',
    url='https://github.com/15five/django-scim2',
    download_url='https://github.com/15five/django-scim2/archive/master.zip',
    maintainer='Paul Logston',
    maintainer_email='paul@15five.com',
    author='Paul Logston',
    author_email='paul@15five.com',
    keywords='django scim 2.0',
    license='MIT',
    long_description=long_description(),
    packages=['django_scim'],
    install_requires=[
        'python-dateutil>=2.6.0',
        'six',
        'scim2-filter-parser==0.1.0',
    ],
    tests_require=[
        'mock',
    ],
    test_suite='setup.run_tests',
    zip_safe=False,
    include_package_data=True,
    classifiers=[
        'Development Status :: 5 - Production/Stable',
        'Environment :: Web Environment',
        'Framework :: Django',
        'Intended Audience :: Developers',
        'License :: OSI Approved :: MIT License',
        'Natural Language :: English',
        'Operating System :: OS Independent',
        'Programming Language :: Python :: 3.3',
        'Programming Language :: Python :: 3.4',
        'Programming Language :: Python :: 3.5',
        'Programming Language :: Python :: 3.6',
        'Programming Language :: Python :: 3.7',
        'Topic :: Internet',
        'Topic :: Software Development :: Libraries :: Python Modules',
    ],
)

