#!/usr/bin/env python
# flake8: noqa

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

# get version
with open('memsql/__init__.py') as f:
    exec(f.read())

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

    def run_tests(self):
        import pytest, sys
        errno = pytest.main(self.test_args)
        raise sys.exit(errno)

setup(
    name='memsql',
    version=__version__,    # this is defined by the "exec(f.read())" at the top of this file.
    author='MemSQL',
    author_email='support@memsql.com',
    url='http://github.com/memsql/memsql-python',

    license='LICENSE.txt',
    description='Useful utilities and plugins for MemSQL integration.',
    long_description=open('README.rst').read(),

    packages=[ 'memsql', 'memsql.collectd', 'memsql.common', ],
    install_requires=['ordereddict', 'MySQL-python>=1.2.4', 'wraptor', 'netifaces'],
    tests_require=['pytest', 'mock'],
    cmdclass={ 'test': PyTest },
)

#!/usr/bin/env python

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

# get version
from memsql import __version__

class PyTest(TestCommand):
    user_options = [
        ('watch', 'w',
         "watch tests for changes"),
        ('scan-directory=', 'd',
         "only search for tests in the specified directory"),
    ]
    boolean_options = ['watch']

    def initialize_options(self):
        self.watch = False
        self.scan_directory = None
        self.test_suite = None
        self.test_module = None
        self.test_loader = None

    def finalize_options(self):
        TestCommand.finalize_options(self)

        self.test_suite = True
        self.test_args = []
        if self.watch:
            self.test_args.append('-f')
        if self.scan_directory is not None:
            self.test_args.append(self.scan_directory)

    def run_tests(self):
        import os, sys

        MY_PATH = os.path.dirname(__file__)
        sys.path.append(MY_PATH)
        os.environ['PYTHONPATH'] = os.environ.get('PYTHONPATH', '') + ':' + MY_PATH

        import pytest
        errno = pytest.main(self.test_args)
        raise sys.exit(errno)

setup(
    name='memsql',
    version=__version__,    # this is defined by the "exec(f.read())" at the top of this file.
    author='MemSQL',
    author_email='support@memsql.com',
    url='http://github.com/memsql/memsql-python',

    license='LICENSE.txt',
    description='Useful utilities and plugins for MemSQL integration.',
    long_description=open('README.rst').read(),

    packages=[ 'memsql', 'memsql.collectd', 'memsql.common', ],
    install_requires=['ordereddict', 'MySQL-python>=1.2.4', 'wraptor', 'netifaces'],
    tests_require=['pytest', 'mock'],
    cmdclass={ 'test': PyTest },
)

test watcher, and sub dir support