# :coding: utf-8
# :copyright: Copyright (c) 2014 Martin Pengelly-Phillips
# :license: See LICENSE.txt.

import os
import re

from setuptools.command.test import test as TestCommand
try:
    from setuptools import setup
except ImportError:
    from distutils.core import setup


class PyTest(TestCommand):
    '''Pytest command.'''

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

    def run_tests(self):
        '''Import pytest and run.'''
        import pytest
        errno = pytest.main(self.test_args)
        raise SystemExit(errno)


with open(os.path.join(
    os.path.dirname(__file__), 'source', 'riffle', '_version.py'
)) as _version_file:
    _version = re.match(
        r'.*__version__ = \'(.*?)\'', _version_file.read(), re.DOTALL
    ).group(1)


setup(
    name='Riffle',
    version=_version,
    description='Filesystem browser for PySide.',
    long_description=open('README.rst').read(),
    keywords='filesystem, browser, pyside, qt, pyqt',
    url='https://github.com/4degrees/riffle',
    author='Martin Pengelly-Phillips',
    author_email='martin@4degrees.ltd.uk',
    license='Apache License (2.0)',
    packages=[
        'riffle',
    ],
    package_dir={
        '': 'source'
    },
    install_requires=[
    ],
    tests_require=['pytest >= 2.3.5'],
    cmdclass={
        'test': PyTest
    },
    zip_safe=False
)

@@ -138,143 +138,205 @@
 ools
-.command.test import test as TestCommand%0Atry:%0A    from setuptools import setup%0Aexcept ImportError:%0A    from distutils.core import setup
+ import setup, find_packages%0Afrom setuptools.command.test import test as TestCommand%0A%0A%0AROOT_PATH = os.path.dirname(%0A    os.path.realpath(__file__)%0A)%0A%0ASOURCE_PATH = os.path.join(ROOT_PATH, 'source')
 %0A%0A%0Ac
@@ -712,48 +712,19 @@
 oin(
-%0A    os.path.dirname(__file__), 'source'
+SOURCE_PATH
 , 'r
@@ -744,17 +744,16 @@
 sion.py'
-%0A
 )) as _v
@@ -769,24 +769,23 @@
 le:%0A    
-_version
+VERSION
  = re.ma
@@ -826,16 +826,24 @@
 .*?)%5C'',
+%0A       
  _versio
@@ -856,16 +856,24 @@
 .read(),
+%0A       
  re.DOTA
@@ -930,24 +930,23 @@
 version=
-_version
+VERSION
 ,%0A    de
@@ -1272,33 +1272,34 @@
 ges=
-%5B%0A        'riffle',%0A    %5D
+find_packages(SOURCE_PATH)
 ,%0A  
@@ -1365,16 +1365,69 @@
 uires=%5B%0A
+        'PySide %3E= 1.1.1',%0A        'clique %3E= 1.2.0'%0A
     %5D,%0A 
@@ -1506,32 +1506,12 @@
 est%0A
+
     %7D
-,%0A    zip_safe=False
 %0A)%0A

Clean up setup file and add missing dependencies.