# -*- coding: utf-8 -*-
import re
import sys
from setuptools import setup, find_packages
from setuptools.command.test import test as TestCommand


class PyTest(TestCommand):
    def finalize_options(self):
        TestCommand.finalize_options(self)
        self.test_args = []
        self.test_suite = True

    def run_tests(self):
        import pytest
        errcode = pytest.main(self.test_args)
        sys.exit(errcode)


def find_version(fname):
    '''Attempts to find the version number in the file names fname.
    Raises RuntimeError if not found.
    '''
    version = ''
    with open(fname, 'r') as fp:
        reg = re.compile(r'__version__ = [\'"]([^\'"]*)[\'"]')
        for line in fp:
            m = reg.match(line)
            if m:
                version = m.group(1)
                break
    if not version:
        raise RuntimeError('Cannot find version information')
    return version

__version__ = find_version("mfr/__init__.py")


def read(fname):
    with open(fname) as fp:
        content = fp.read()
    return content

setup(
    name='mfr',
    version=__version__,
    description='HTML file renderer for Python',
    long_description=(read("README.rst") + '\n\n' +
                      read("HISTORY.rst")),
    author='Center for Open Science',
    author_email='contact@cos.io',
    url='https://github.com/CenterForOpenScience/modular-file-renderer',
    packages=find_packages(exclude=("test*", "player*")),
    include_package_data=True,
    package_data={
        "": ['templates/*', 'static/*/*', '*.txt'],
    },
    license=read("LICENSE"),
    zip_safe=False,
    keywords='mfr',
    classifiers=[
        'Development Status :: 2 - Pre-Alpha',
        'Intended Audience :: Developers',
        'License :: OSI Approved :: Apache Software License',
        'Natural Language :: English',
        "Programming Language :: Python :: 2",
        'Programming Language :: Python :: 2.6',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.3',
        'Programming Language :: Python :: 3.4',
    ],
    test_suite='tests',
    tests_require=['pytest'],
    cmdclass={'test': PyTest}

)

# -*- coding: utf-8 -*-
import re
import sys
from setuptools import setup, find_packages
from setuptools.command.test import test as TestCommand


# Plugins that will not work with python versions
EXCLUDE_PLUGINS = {
    "2.6": ['mfr_ipynb'],
    "2.7": [],
    "3.3": ['mfr_docx'],
    "3.4": ['mfr_docx'],
}

SYS_EXCLUDE = EXCLUDE_PLUGINS[sys.version[0:2]]


class PyTest(TestCommand):
    def finalize_options(self):
        TestCommand.finalize_options(self)
        self.test_args = []
        self.test_suite = True

    def run_tests(self):
        import pytest
        errcode = pytest.main(self.test_args)
        sys.exit(errcode)


def find_version(fname):
    '''Attempts to find the version number in the file names fname.
    Raises RuntimeError if not found.
    '''
    version = ''
    with open(fname, 'r') as fp:
        reg = re.compile(r'__version__ = [\'"]([^\'"]*)[\'"]')
        for line in fp:
            m = reg.match(line)
            if m:
                version = m.group(1)
                break
    if not version:
        raise RuntimeError('Cannot find version information')
    return version

__version__ = find_version("mfr/__init__.py")


def read(fname):
    with open(fname) as fp:
        content = fp.read()
    return content


setup(
    name='mfr',
    version=__version__,
    description='HTML file renderer for Python',
    long_description=(read("README.rst") + '\n\n' +
                      read("HISTORY.rst")),
    author='Center for Open Science',
    author_email='contact@cos.io',
    url='https://github.com/CenterForOpenScience/modular-file-renderer',
    packages=list(
        set(find_packages(exclude=("test*", "player*"))) - set(SYS_EXCLUDE)
    ),
    include_package_data=True,
    package_data={
        "": ['templates/*', 'static/*/*', '*.txt'],
    },
    license=read("LICENSE"),
    zip_safe=False,
    keywords='mfr',
    classifiers=[
        'Development Status :: 2 - Pre-Alpha',
        'Intended Audience :: Developers',
        'License :: OSI Approved :: Apache Software License',
        'Natural Language :: English',
        "Programming Language :: Python :: 2",
        'Programming Language :: Python :: 2.6',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.3',
        'Programming Language :: Python :: 3.4',
    ],
    test_suite='tests',
    tests_require=['pytest'],
    cmdclass={'test': PyTest}

)

exclude plugins if they are not compatible with the python version