import io
import os
import re
from setuptools import setup, find_packages

from performanceplatform import collector


class Setup(object):

    """A series of helpers for getting the setup looking buff"""

    @staticmethod
    def read(fname, fail_silently=False):
        """
        Read the content of the given file. The path is evaluated from the
        directory containing this file.
        """
        try:
            filepath = os.path.join(os.path.dirname(__file__), fname)
            with io.open(filepath, 'rt', encoding='utf8') as f:
                return f.read()
        except:
            if not fail_silently:
                raise
            return ''

    @staticmethod
    def version():
        data = Setup.read(
            'performanceplatform/collector/__init__.py'
        )
        version = re.search(
            r"^__version__ = ['\"]([^'\"]*)['\"]",
            data,
            re.M | re.I
        ).group(1).strip()
        return version.encode('ascii')

    @staticmethod
    def requirements(fname):
        """
        Create a list of requirements from the output of the pip freeze command
        saved in a text file.
        """
        packages = Setup.read(fname).split('\n')
        packages = (p.strip() for p in packages)
        packages = (p for p in packages if p and not p.startswith('#'))
        return list(packages)

    @staticmethod
    def long_description():
        return Setup.read('README.rst')

if __name__ == '__main__':
    setup(
        name='performanceplatform-collector',
        version=Setup.version(),
        packages=find_packages(exclude=['test*']),

        # metadata for upload to PyPI
        author=collector.__author__,
        author_email=collector.__author_email__,
        maintainer='Government Digital Service',
        url='https://github.com/alphagov/performanceplatform-collector',

        description='performanceplatform-collector: tools for sending'
            'data to the Performance Platform',
        long_description=Setup.long_description(),
        license='MIT',
        keywords='api data performance_platform',

        install_requires=Setup.requirements('requirements.txt'),
        tests_require=Setup.requirements('requirements_for_tests.txt'),

        test_suite='nose.collector',

        entry_points={
            'console_scripts': [
                'pp-collector=performanceplatform.collector.main:main'
            ]
        }
    )

@@ -116,122 +116,13 @@
 r%0A%0A%0A
-class Setup(object):%0A%0A    %22%22%22A series of helpers for getting the setup looking buff%22%22%22%0A%0A    @staticmethod%0A    
 def 
+_
 read
@@ -147,36 +147,32 @@
 tly=False):%0A
-    
     %22%22%22%0A
         Read
@@ -155,28 +155,24 @@
 e):%0A    %22%22%22%0A
-    
     Read the
@@ -230,20 +230,16 @@
 rom the%0A
-    
     dire
@@ -266,36 +266,32 @@
 s file.%0A    
-  
-  
 %22%22%22%0A    
     try:%0A   
@@ -282,21 +282,13 @@
     
-   
- 
 try:%0A
-    
     
@@ -357,20 +357,16 @@
         
- 
-   
 with io.
@@ -417,28 +417,24 @@
             
-    
 return f.rea
@@ -445,20 +445,16 @@
     
-   
- 
 except:%0A
     
@@ -449,20 +449,16 @@
 except:%0A
-    
         
@@ -491,20 +491,16 @@
         
-    
 raise%0A  
@@ -501,28 +501,24 @@
 ise%0A        
- 
-   
 return ''%0A%0A 
@@ -520,34 +520,18 @@
 ''%0A%0A
-    @staticmethod%0A    def 
+%0Adef _get_
 vers
@@ -545,35 +545,22 @@
     
-  
-  
 data = 
-Setup.
+_
 read(%0A
-    
     
@@ -615,18 +615,10 @@
     
-    )%0A    
+)%0A
     
@@ -646,20 +646,16 @@
         
-    
 r%22%5E__ver
@@ -693,20 +693,16 @@
         
-    
 data,%0A  
@@ -707,20 +707,16 @@
         
-   
- 
 re.M %7C r
@@ -719,20 +719,16 @@
  %7C re.I%0A
-    
     ).gr
@@ -742,20 +742,16 @@
 strip()%0A
-    
     retu
@@ -782,34 +782,18 @@
 ')%0A%0A
-    @staticmethod%0A    def 
+%0Adef _get_
 requ
@@ -809,36 +809,28 @@
 fname):%0A    
-    %22%22%22%0A    
+%22%22%22%0A
     Create a
@@ -893,20 +893,16 @@
 command%0A
-    
     save
@@ -923,20 +923,16 @@
 le.%0A
-    
     %22%22%22%0A
     
@@ -927,20 +927,16 @@
     %22%22%22%0A
-    
     pack
@@ -942,22 +942,17 @@
 kages = 
-Setup.
+_
 read(fna
@@ -967,20 +967,16 @@
 t('%5Cn')%0A
-    
     pack
@@ -1012,20 +1012,16 @@
 ckages)%0A
-    
     pack
@@ -1080,28 +1080,24 @@
 h('#'))%0A    
- 
-   
 return list(
@@ -1111,34 +1111,18 @@
 s)%0A%0A
-    @staticmethod%0A    def 
+%0Adef _get_
 long
@@ -1145,25 +1145,16 @@
     
-  
-  
 return 
-Setup.
+_
 read
@@ -1169,16 +1169,17 @@
 .rst')%0A%0A
+%0A
 if __nam
@@ -1270,22 +1270,21 @@
 version=
-Setup.
+_get_
 version(
@@ -1729,22 +1729,21 @@
 ription=
-Setup.
+_get_
 long_des
@@ -1853,22 +1853,21 @@
 equires=
-Setup.
+_get_
 requirem
@@ -1918,14 +1918,13 @@
 ire=
-Setup.
+_get_
 requ

Refactor class methods into private functions