"""pact-python PyPI Package."""

import os
import platform
import sys
import tarfile

from zipfile import ZipFile

from setuptools import setup
from setuptools.command.develop import develop
from setuptools.command.install import install


IS_64 = sys.maxsize > 2 ** 32
PACT_STANDALONE_VERSION = '1.74.0'


here = os.path.abspath(os.path.dirname(__file__))

about = {}
with open(os.path.join(here, "pact", "__version__.py")) as f:
    exec(f.read(), about)


class PactPythonDevelopCommand(develop):
    """
    Custom develop mode installer for pact-python.

    When the package is installed using `python setup.py develop` or
    `pip install -e` it will download and unpack the appropriate Pact
    mock service and provider verifier.
    """
    def run(self):
        develop.run(self)
        bin_path = os.path.join(os.path.dirname(__file__), 'pact', 'bin')
        if not os.path.exists(bin_path):
            os.mkdir(bin_path)

        install_ruby_app(bin_path)


class PactPythonInstallCommand(install):
    """
    Custom installer for pact-python.

    Installs the Python package and unpacks the platform appropriate version
    of the Ruby mock service and provider verifier.
    """
    def run(self):
        install.run(self)
        bin_path = os.path.join(self.install_lib, 'pact', 'bin')
        os.mkdir(bin_path)
        install_ruby_app(bin_path)


def install_ruby_app(bin_path):
    """
    Download a Ruby application and install it for use.

    :param bin_path: The path where binaries should be installed.
    """
    target_platform = platform.platform().lower()
    uri = ('https://github.com/pact-foundation/pact-ruby-standalone/releases'
           '/download/v{version}/pact-{version}-{suffix}')

    if 'darwin' in target_platform or 'macos' in target_platform:
        suffix = 'osx.tar.gz'
    elif 'linux' in target_platform and IS_64:
        suffix = 'linux-x86_64.tar.gz'
    elif 'linux' in target_platform:
        suffix = 'linux-x86.tar.gz'
    elif 'windows' in target_platform:
        suffix = 'win32.zip'
    else:
        msg = ('Unfortunately, {} is not a supported platform. Only Linux,'
               ' Windows, and OSX are currently supported.').format(
            platform.platform())
        raise Exception(msg)

    if sys.version_info.major == 2:
        from urllib import urlopen
    else:
        from urllib.request import urlopen

    path = os.path.join(bin_path, suffix)
    resp = urlopen(uri.format(version=PACT_STANDALONE_VERSION, suffix=suffix))
    with open(path, 'wb') as f:
        if resp.code == 200:
            f.write(resp.read())
        else:
            raise RuntimeError(
                'Received HTTP {} when downloading {}'.format(
                    resp.code, resp.url))

    if 'windows' in platform.platform().lower():
        with ZipFile(path) as f:
            f.extractall(bin_path)
    else:
        with tarfile.open(path) as f:
            f.extractall(bin_path)


def read(filename):
    """Read file contents."""
    path = os.path.realpath(os.path.join(os.path.dirname(__file__), filename))
    with open(path, 'rb') as f:
        return f.read().decode('utf-8')


dependencies = [
    'click>=2.0.0',
    'psutil>=2.0.0',
    'requests>=2.5.0',
    'six>=1.9.0',
]

if sys.version_info.major == 2:
    dependencies.append('subprocess32')

setup_args = dict(
    cmdclass={'develop': PactPythonDevelopCommand,
              'install': PactPythonInstallCommand},
    name='pact-python',
    version=about['__version__'],
    description=('Tools for creating and verifying consumer driven contracts'
                 ' using the Pact framework.'),
    long_description=read('README.md'),
    long_description_content_type='text/markdown',
    author='Matthew Balvanz',
    author_email='matthew.balvanz@workiva.com',
    url='https://github.com/pact-foundation/pact-python',
    entry_points='''
        [console_scripts]
        pact-verifier=pact.verify:main
    ''',
    install_requires=dependencies,
    packages=['pact'],
    package_data={'pact': ['bin/*']},
    package_dir={'pact': 'pact'},
    license='MIT License')


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

@@ -3344,31 +3344,54 @@
 ')%0A%0A
-setup_args = dict(%0A
+if __name__ == '__main__':%0A    setup(%0A  
     
+  
 cmdc
@@ -3396,16 +3396,29 @@
 dclass=%7B
+%0A            
 'develop
@@ -3446,18 +3446,16 @@
 ommand,%0A
-  
         
@@ -3500,16 +3500,20 @@
 d%7D,%0A    
+   
+ 
 name='pa
@@ -3520,24 +3520,28 @@
 ct-python',%0A
+    
     version=
@@ -3566,16 +3566,20 @@
 '%5D,%0A    
+  
+  
 descript
@@ -3583,16 +3583,29 @@
 iption=(
+%0A            
 'Tools f
@@ -3650,22 +3650,10 @@
 ven 
-contracts'%0A   
+'%0A
     
@@ -3660,19 +3660,26 @@
         
-  '
+'contracts
  using t
@@ -3696,32 +3696,36 @@
 amework.'),%0A    
+  
+  
 long_description
@@ -3740,24 +3740,28 @@
 EADME.md'),%0A
+    
     long_des
@@ -3799,24 +3799,28 @@
 kdown',%0A    
+ 
+   
 author='Matt
@@ -3833,16 +3833,20 @@
 lvanz',%0A
+    
     auth
@@ -3885,16 +3885,20 @@
 a.com',%0A
+    
     url=
@@ -3943,24 +3943,28 @@
 ct-python',%0A
+    
     entry_po
@@ -3972,16 +3972,20 @@
 nts='''%0A
+    
         
@@ -4010,16 +4010,20 @@
         
+ 
+   
 pact-ver
@@ -4045,16 +4045,20 @@
 fy:main%0A
+    
     ''',
@@ -4058,16 +4058,20 @@
    ''',%0A
+    
     inst
@@ -4097,24 +4097,28 @@
 encies,%0A    
+   
+ 
 packages=%5B'p
@@ -4120,24 +4120,28 @@
 s=%5B'pact'%5D,%0A
+    
     package_
@@ -4166,24 +4166,28 @@
 n/*'%5D%7D,%0A    
+  
+  
 package_dir=
@@ -4204,16 +4204,20 @@
 pact'%7D,%0A
+    
     lice
@@ -4239,57 +4239,4 @@
 e')%0A
-%0A%0Aif __name__ == '__main__':%0A    setup(**setup_args)%0A

Converting to kwargs