forked from pact-foundation/pact-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
106 lines (88 loc) · 3.67 KB
/
Copy pathsetup.py
File metadata and controls
106 lines (88 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
"""pact-python PyPI Package."""
import os
import platform
import sys
import tarfile
from setuptools import setup
from setuptools.command.install import install
import pact
class PactPythonInstallCommand(install):
"""
Custom installer for pact-python.
Installs the Python package and unpacks the platform appropriate version
of Python mock service.
"""
def run(self):
install.run(self)
bin_path = os.path.join(self.install_lib, 'pact', 'bin')
self.mock_service(bin_path)
self.verifier(bin_path)
def mock_service(self, bin_path):
"""Install the Ruby mock service for this platform."""
is_64 = sys.maxsize > 2 ** 32
target_platform = platform.platform().lower()
if 'darwin' in target_platform:
platform_tar = 'pact-mock-service-darwin.tar.gz'
elif 'linux' in target_platform and is_64:
platform_tar = 'pact-mock-service-linux-x64.tar.gz'
elif 'linux' in target_platform:
platform_tar = 'pact-mock-service-ia32.tar.gz'
elif 'windows' in target_platform:
platform_tar = 'pact-mock-service-win32.tar.gz'
else:
msg = ('Unfortunately, {} is not a supported platform. Only Linux,'
' Windows, and OSX are currently supported.').format(
platform.platform())
raise Exception(msg)
self.announce(u'Extracting {} to {}'.format(platform_tar, bin_path))
with tarfile.open(os.path.join(bin_path, platform_tar)) as f:
f.extractall(os.path.join(bin_path, 'mock-service'))
def verifier(self, bin_path):
"""Install the Ruby Pact Verifier for this platform."""
is_64 = sys.maxsize > 2 ** 32
target_platform = platform.platform().lower()
if 'darwin' in target_platform:
platform_tar = 'pact-provider-verifier-darwin.tar.gz'
elif 'linux' in target_platform and is_64:
platform_tar = 'pact-provider-verifier-linux-x64.tar.gz'
elif 'linux' in target_platform:
platform_tar = 'pact-provider-verifier-linux-ia32.tar.gz'
elif 'windows' in target_platform:
platform_tar = 'pact-provider-verifier-win32.tar.gz'
else:
msg = ('Unfortunately, {} is not a supported platform. Only Linux,'
' Windows, and OSX are currently supported.').format(
platform.platform())
raise Exception(msg)
self.announce(u'Extracting {} to {}'.format(platform_tar, bin_path))
with tarfile.open(os.path.join(bin_path, platform_tar)) as f:
f.extractall(os.path.join(bin_path, 'verifier'))
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 = read('requirements.txt').split()
if sys.version_info.major == 2:
dependencies.append('subprocess32')
setup_args = dict(
cmdclass={'install': PactPythonInstallCommand},
name='pact-python',
version=pact.__version__,
description=('Tools for creating and verifying consumer driven contracts'
' using the Pact framework.'),
long_description=read('README.md'),
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=read('LICENSE'))
if __name__ == '__main__':
setup(**setup_args)