55import sys
66import tarfile
77
8- import shutil
98from zipfile import ZipFile
109
1110from setuptools import setup
1615
1716
1817IS_64 = sys .maxsize > 2 ** 32
19- MOCK_SERVICE_URI = (
20- 'https://github.com/bethesque/pact-mock_service/releases/download/v2.1.0/' )
21- VERIFIER_URI = (
22- 'https://github.com/pact-foundation/pact-provider-verifier'
23- '/releases/download/v1.0.2/' )
18+ PACT_STANDALONE_VERSION = '0.0.1'
2419
2520
2621class PactPythonDevelopCommand (develop ):
@@ -37,8 +32,7 @@ def run(self):
3732 if not os .path .exists (bin_path ):
3833 os .mkdir (bin_path )
3934
40- mock_service (bin_path )
41- verifier (bin_path )
35+ install_ruby_app (bin_path )
4236
4337
4438class PactPythonInstallCommand (install ):
@@ -52,26 +46,40 @@ def run(self):
5246 install .run (self )
5347 bin_path = os .path .join (self .install_lib , 'pact' , 'bin' )
5448 os .mkdir (bin_path )
55- mock_service (bin_path )
56- verifier (bin_path )
49+ install_ruby_app (bin_path )
5750
5851
59- def install_ruby_app (bin_path , dir_name , platform_tar , repository_uri ):
52+ def install_ruby_app (bin_path ):
6053 """
6154 Download a Ruby application and install it for use.
6255
6356 :param bin_path: The path where binaries should be installed.
64- :param platform_tar: The application tar or zip file to download.
65- :param dir_name: The directory name for the unpacked files.
66- :param repository_uri: The GitHub repository URI.
6757 """
58+ target_platform = platform .platform ().lower ()
59+ uri = ('https://github.com/pact-foundation/pact-ruby-standalone/releases'
60+ '/download/v{version}/pact-{version}-{suffix}' )
61+
62+ if 'darwin' in target_platform :
63+ suffix = 'osx.tar.gz'
64+ elif 'linux' in target_platform and IS_64 :
65+ suffix = 'linux-x86_64.tar.gz'
66+ elif 'linux' in target_platform :
67+ suffix = 'linux-x86.tar.gz'
68+ elif 'windows' in target_platform :
69+ suffix = 'win32.zip'
70+ else :
71+ msg = ('Unfortunately, {} is not a supported platform. Only Linux,'
72+ ' Windows, and OSX are currently supported.' ).format (
73+ platform .platform ())
74+ raise Exception (msg )
75+
6876 if sys .version_info .major == 2 :
6977 from urllib import urlopen
7078 else :
7179 from urllib .request import urlopen
7280
73- path = os .path .join (bin_path , platform_tar )
74- resp = urlopen (repository_uri + platform_tar )
81+ path = os .path .join (bin_path , suffix )
82+ resp = urlopen (uri . format ( version = PACT_STANDALONE_VERSION , suffix = suffix ) )
7583 with open (path , 'wb' ) as f :
7684 f .write (resp .read ())
7785
@@ -82,38 +90,6 @@ def install_ruby_app(bin_path, dir_name, platform_tar, repository_uri):
8290 with tarfile .open (path ) as f :
8391 f .extractall (bin_path )
8492
85- platform_name = platform_tar .replace ('.tar.gz' , '' ).replace ('.zip' , '' )
86- shutil .move (os .path .join (bin_path , platform_name ),
87- os .path .join (bin_path , dir_name ))
88-
89-
90- def get_version ():
91- """Return latest version noted in CHANGES.txt."""
92- lastline = [line for line in read ('CHANGES.txt' ).split ('\n ' ) if line ][- 1 ]
93- version = lastline .split (',' )[0 ]
94- return version [1 :]
95-
96-
97- def mock_service (bin_path ):
98- """Install the Ruby mock service for this platform."""
99- target_platform = platform .platform ().lower ()
100- if 'darwin' in target_platform :
101- platform_tar = 'pact-mock-service-2.1.0-1-osx.tar.gz'
102- elif 'linux' in target_platform and IS_64 :
103- platform_tar = 'pact-mock-service-2.1.0-1-linux-x86_64.tar.gz'
104- elif 'linux' in target_platform :
105- platform_tar = 'pact-mock-service-2.1.0-1-linux-x86.tar.gz'
106- elif 'windows' in target_platform :
107- platform_tar = 'pact-mock-service-2.1.0-1-win32.zip'
108- else :
109- msg = ('Unfortunately, {} is not a supported platform. Only Linux,'
110- ' Windows, and OSX are currently supported.' ).format (
111- platform .platform ())
112- raise Exception (msg )
113-
114- install_ruby_app (
115- bin_path , 'mock-service' , platform_tar , MOCK_SERVICE_URI )
116-
11793
11894def read (filename ):
11995 """Read file contents."""
@@ -122,26 +98,6 @@ def read(filename):
12298 return f .read ().decode ('utf-8' )
12399
124100
125- def verifier (bin_path ):
126- """Install the Ruby Pact Verifier for this platform."""
127- target_platform = platform .platform ().lower ()
128- if 'darwin' in target_platform :
129- platform_tar = 'pact-provider-verifier-1.0.2-1-osx.tar.gz'
130- elif 'linux' in target_platform and IS_64 :
131- platform_tar = 'pact-provider-verifier-1.0.2-1-linux-x86_64.tar.gz'
132- elif 'linux' in target_platform :
133- platform_tar = 'pact-provider-verifier-1.0.2-1-linux-x86.tar.gz'
134- elif 'windows' in target_platform :
135- platform_tar = 'pact-provider-verifier-1.0.2-1-win32.zip'
136- else :
137- msg = ('Unfortunately, {} is not a supported platform. Only Linux,'
138- ' Windows, and OSX are currently supported.' ).format (
139- platform .platform ())
140- raise Exception (msg )
141-
142- install_ruby_app (bin_path , 'verifier' , platform_tar , VERIFIER_URI )
143-
144-
145101dependencies = read ('requirements.txt' ).split ()
146102
147103if sys .version_info .major == 2 :
0 commit comments