forked from pact-foundation/pact-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
129 lines (101 loc) · 3.64 KB
/
setup.py
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
"""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
import pact
IS_64 = sys.maxsize > 2 ** 32
PACT_STANDALONE_VERSION = '1.0.0'
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:
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:
f.write(resp.read())
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 = read('requirements.txt').split()
if sys.version_info.major == 2:
dependencies.append('subprocess32')
setup_args = dict(
cmdclass={'develop': PactPythonDevelopCommand,
'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='[email protected]',
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)