11"""pact-python PyPI Package."""
22
33import os
4+ import platform
5+ import sys
6+ import tarfile
7+
48from setuptools import find_packages , setup
9+ from setuptools .command .install import install
10+
11+
12+ class PactPythonInstallCommand (install ):
13+ """
14+ Custom installer for pact-python.
15+
16+ Installs the Python package and unpacks the platform appropriate version
17+ of Python mock service.
18+ """
19+ def run (self ):
20+ install .run (self )
21+ bin_path = os .path .join (self .install_lib , 'pact' , 'bin' )
22+ self .mock_service (bin_path )
23+ self .verifier (bin_path )
24+
25+ def mock_service (self , bin_path ):
26+ """Install the Ruby mock service for this platform."""
27+ is_64 = sys .maxsize > 2 ** 32
28+ target_platform = platform .platform ().lower ()
29+ if 'darwin' in target_platform :
30+ platform_tar = 'pact-mock-service-darwin.tar.gz'
31+ elif 'linux' in target_platform and is_64 :
32+ platform_tar = 'pact-mock-service-linux-x64.tar.gz'
33+ elif 'linux' in target_platform :
34+ platform_tar = 'pact-mock-service-ia32.tar.gz'
35+ elif 'windows' in target_platform :
36+ platform_tar = 'pact-mock-service-win32.tar.gz'
37+ else :
38+ msg = ('Unfortunately, {} is not a supported platform. Only Linux,'
39+ ' Windows, and OSX are currently supported.' ).format (
40+ platform .platform ())
41+ raise Exception (msg )
42+
43+ self .announce (u'Extracting {} to {}' .format (platform_tar , bin_path ))
44+ with tarfile .open (os .path .join (bin_path , platform_tar )) as f :
45+ f .extractall (os .path .join (bin_path , 'mock-service' ))
46+
47+ def verifier (self , bin_path ):
48+ """Install the Ruby Pact Verifier for this platform."""
49+ is_64 = sys .maxsize > 2 ** 32
50+ target_platform = platform .platform ().lower ()
51+ if 'darwin' in target_platform :
52+ platform_tar = 'pact-provider-verifier-darwin.tar.gz'
53+ elif 'linux' in target_platform and is_64 :
54+ platform_tar = 'pact-provider-verifier-linux-x64.tar.gz'
55+ elif 'linux' in target_platform :
56+ platform_tar = 'pact-provider-verifier-linux-ia32.tar.gz'
57+ elif 'windows' in target_platform :
58+ platform_tar = 'pact-provider-verifier-win32.tar.gz'
59+ else :
60+ msg = ('Unfortunately, {} is not a supported platform. Only Linux,'
61+ ' Windows, and OSX are currently supported.' ).format (
62+ platform .platform ())
63+ raise Exception (msg )
64+
65+ self .announce (u'Extracting {} to {}' .format (platform_tar , bin_path ))
66+ with tarfile .open (os .path .join (bin_path , platform_tar )) as f :
67+ f .extractall (os .path .join (bin_path , 'verifier' ))
568
669
770def get_version ():
@@ -21,6 +84,7 @@ def read(filename):
2184dependencies = [
2285 dep .strip () for dep in read ('requirements.txt' ).split ('\n ' ) if dep .strip ()]
2386setup_args = dict (
87+ cmdclass = {'install' : PactPythonInstallCommand },
2488 name = 'pact-python' ,
2589 version = get_version (),
2690 description = ('Tools for creating and verifying consumer driven contracts'
@@ -31,6 +95,8 @@ def read(filename):
3195 url = 'https://github.com/pact-foundation/pact-python' ,
3296 install_requires = dependencies ,
3397 packages = find_packages (exclude = ['*.test' , '*.test.*' , 'test.*' , 'test' ]),
98+ package_data = {'pact' : ['bin/*' ]},
99+ package_dir = {'pact' : 'pact' },
34100 license = read ('LICENSE' ))
35101
36102
0 commit comments