<filename>setup.py
#!/usr/bin/env python

"""
Brown
-----

Browin is a set of tools for analysis of diffusion MRI data.

"""
from __future__ import print_function

import os.path as op
import io
import sys
from setuptools import Command, setup, find_packages
from setuptools.command.test import test as TestCommand
from pip.req import parse_requirements


LICENSE = 'new BSD'

setup_dict = dict(
    name='brown',
    version='0.1.0',
    description='Diffusion MRI data analysis tools',

    license='BSD 3-Clause',
    author='<NAME>',
    author_email='<EMAIL>',
    maintainer='<NAME>',
    maintainer_email='<EMAIL>',

    packages=find_packages(),

    install_requires=['numpy',
                      'scipy',
                      'nibabel'],

    extra_files=['CHANGES.rst', 'LICENSE', 'README.rst'],

    platforms='Linux/MacOSX',

    #https://pypi.python.org/pypi?%3Aaction=list_classifiers
    classifiers=[
        'Programming Language :: Python',
        'Development Status :: 3 - Alpha',
        'Natural Language :: English',
        'Environment :: Console',
        'Intended Audience :: Healthcare Industry',
        'License :: OSI Approved ::' + LICENSE,
        'Operating System :: OS Independent',
        'Topic :: Software Development :: Libraries :: Python Modules',
        'Topic :: Scientific/Engineering :: Medical Science Apps.',
        'Topic :: Scientific/Engineering :: Information Analysis',
    ],

    extras_require={
        'testing': ['pytest'],
    }
)


#long description
def read(*filenames, **kwargs):
    encoding = kwargs.get('encoding', 'utf-8')
    sep = kwargs.get('sep', '\n')
    buf = []
    for filename in filenames:
        with io.open(filename, encoding=encoding) as f:
            buf.append(f.read())
    return sep.join(buf)


setup_dict.update(dict(long_description=read('README.rst', 'CHANGES.rst')))


#Python3 support keywords
if sys.version_info >= (3,):
    setup_dict['use_2to3'] = False
    setup_dict['convert_2to3_doctests'] = ['']
    setup_dict['use_2to3_fixers'] = ['']


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)


setup_dict.update(dict(tests_require=['pytest'],
                       cmdclass={'test': PyTest}))


# class run_audit(Command):
#     """Audits source code using PyFlakes for following issues:
# - Names which are used but not defined or used before they are defined.
# - Names which are redefined without having been used.
# """
#     description = "Audit source code with PyFlakes"
#     user_options = []
#
#     def initialize_options(self):
#         pass
#
#     def finalize_options(self):
#         pass
#
#     def run(self):
#         import os
#         import sys
#         try:
#             import pyflakes.scripts.pyflakes as flakes
#         except ImportError:
#             print("Audit requires PyFlakes installed in your system.")
#             sys.exit(-1)
#
#         warns = 0
#         # Define top-level directories
#         dirs = ('brown')
#         for dir in dirs:
#             for root, _, files in os.walk(dir):
#                 for file in files:
#                     if file != '__init__.py' and file.endswith('.py'):
#                         warns += flakes.checkPath(os.path.join(root, file))
#         if warns > 0:
#             print("Audit finished with total %d warnings." % warns)
#         else:
#             print("No problems found in sourcecode.")


if __name__ == '__main__':
    setup(**setup_dict)
