Skip to content

Commit df1f22a

Browse files
arturoriterelliottmurraytaj-p
authored
chore(NONE-0000): update from upstream (#3)
* chore: Releasing version 1.4.0 * fix: make uvicorn versions over 0.14 (pact-foundation#255) * chore: Releasing version 1.4.1 * chore: Bundle Ruby standalones into dist artifact. (pact-foundation#256) Install all ruby standalone packages when running sdist. Devloppers can also now provide a --bin-path that contains the binaries required for their OS, so that can they use this package in offline environments. * chore: Releasing version 1.4.2 Co-authored-by: Elliott Murray <[email protected]> Co-authored-by: Taj Pereira <[email protected]>
1 parent 12aebb6 commit df1f22a

File tree

4 files changed

+131
-21
lines changed

4 files changed

+131
-21
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
### 1.4.2
2+
* f2230b6 - chore: Bundle Ruby standalones into dist artifact. (#256) (Taj Pereira, Sun Aug 22 19:53:53 2021 +0930)
3+
* e370786 - chore: Releasing version 1.4.1 (Elliott Murray, Tue Aug 17 18:55:53 2021 +0100)
4+
* 7dc8864 - fix: make uvicorn versions over 0.14 (#255) (Elliott Murray, Tue Aug 17 18:51:52 2021 +0100)
5+
* da49cd7 - chore: Releasing version 1.4.0 (Elliott Murray, Sat Aug 7 10:17:26 2021 +0100)
6+
* 0089937 - fix: issue originating from snyk with requests and urllib (#252) (Elliott Murray, Sat Jul 31 12:46:15 2021 +0100)
7+
* 903371b - feat: added support for message provider (#251) (Fabio Pulvirenti, Sat Jul 31 13:24:19 2021 +0200)
8+
* 2c81029 - chore(snyk): update fastapi (#239) (Elliott Murray, Fri Jun 11 09:12:38 2021 +0100)
9+
### 1.4.1
10+
* 7dc8864 - fix: make uvicorn versions over 0.14 (#255) (Elliott Murray, Tue Aug 17 18:51:52 2021 +0100)
11+
### 1.4.0
12+
* 0089937 - fix: issue originating from snyk with requests and urllib (#252) (Elliott Murray, Sat Jul 31 12:46:15 2021 +0100)
13+
* 903371b - feat: added support for message provider (#251) (Fabio Pulvirenti, Sat Jul 31 13:24:19 2021 +0200)
14+
* 2c81029 - chore(snyk): update fastapi (#239) (Elliott Murray, Fri Jun 11 09:12:38 2021 +0100)
115
### 1.3.9
216
* 98d9a4b - chore(ruby): update ruby standalen (#233) (Elliott Murray, Thu May 13 20:21:10 2021 +0100)
317
* 657e770 - fix: change default from empty string to empty list (#235) (Vasile Tofan, Thu May 13 22:20:47 2021 +0300)

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
include LICENSE
22
include *.txt
33
include *.md
4+
include pact/bin/*
45
prune pact/test
5-
prune pact/bin
66
prune e2e

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ To setup a development environment:
437437
1. If you want to run tests for all Python versions, install 2.7, 3.3, 3.4, 3.5, and 3.6 from source or using a tool like [pyenv]
438438
2. Its recommended to create a Python [virtualenv] for the project
439439

440-
The setup the environment, run tests, and package the application, run:
440+
To setup the environment, run tests, and package the application, run:
441441
`make release`
442442

443443
If you are just interested in packaging pact-python so you can install it using pip:
@@ -449,6 +449,15 @@ From there you can use pip to install it:
449449

450450
`pip install ./dist/pact-python-N.N.N.tar.gz`
451451

452+
## Offline Installation of Standalone Packages
453+
454+
Although all Ruby standalone applications are predownloaded into the wheel artifact, it may be useful, for development, purposes to install custom Ruby binaries. In which case, use the `bin-path` flag.
455+
```
456+
pip install pact-python --bin-path=/absolute/path/to/folder/containing/pact/binaries/for/your/os
457+
```
458+
459+
Pact binaries can be found at [Pact Ruby Releases](https://github.com/pact-foundation/pact-ruby-standalone/releases).
460+
452461
## Testing
453462

454463
This project has unit and end to end tests, which can both be run from make:

setup.py

Lines changed: 106 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import os
44
import platform
5+
import shutil
56
import sys
67
import tarfile
78

@@ -10,18 +11,39 @@
1011
from setuptools import setup
1112
from setuptools.command.develop import develop
1213
from setuptools.command.install import install
14+
from distutils.command.sdist import sdist as sdist_orig
1315

1416

1517
IS_64 = sys.maxsize > 2 ** 32
1618
PACT_STANDALONE_VERSION = '1.88.51'
17-
19+
PACT_STANDALONE_SUFFIXES = ['osx.tar.gz',
20+
'linux-x86_64.tar.gz',
21+
'linux-x86.tar.gz',
22+
'win32.zip']
1823

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

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

30+
class sdist(sdist_orig):
31+
"""
32+
Subclass sdist so that we can download all standalone ruby applications
33+
into ./pact/bin so our users receive all the binaries on pip install.
34+
"""
35+
def run(self):
36+
package_bin_path = os.path.join(os.path.dirname(__file__), 'pact', 'bin')
37+
38+
if os.path.exists(package_bin_path):
39+
shutil.rmtree(package_bin_path, ignore_errors=True)
40+
os.mkdir(package_bin_path)
41+
42+
for suffix in PACT_STANDALONE_SUFFIXES:
43+
filename = ('pact-{version}-{suffix}').format(version=PACT_STANDALONE_VERSION, suffix=suffix)
44+
download_ruby_app_binary(package_bin_path, filename, suffix)
45+
super().run()
46+
2547

2648
class PactPythonDevelopCommand(develop):
2749
"""
@@ -35,11 +57,11 @@ class PactPythonDevelopCommand(develop):
3557
def run(self):
3658
"""Install ruby command."""
3759
develop.run(self)
38-
bin_path = os.path.join(os.path.dirname(__file__), 'pact', 'bin')
39-
if not os.path.exists(bin_path):
40-
os.mkdir(bin_path)
60+
package_bin_path = os.path.join(os.path.dirname(__file__), 'pact', 'bin')
61+
if not os.path.exists(package_bin_path):
62+
os.mkdir(package_bin_path)
4163

42-
install_ruby_app(bin_path)
64+
install_ruby_app(package_bin_path, download_bin_path=None)
4365

4466

4567
class PactPythonInstallCommand(install):
@@ -48,25 +70,66 @@ class PactPythonInstallCommand(install):
4870
4971
Installs the Python package and unpacks the platform appropriate version
5072
of the Ruby mock service and provider verifier.
73+
74+
User Options:
75+
--bin-path An absolute folder path containing predownloaded pact binaries
76+
that should be used instead of fetching from the internet.
5177
"""
5278

79+
user_options = install.user_options + [('bin-path=', None, None)]
80+
81+
def initialize_options(self):
82+
"""Load our preconfigured options"""
83+
install.initialize_options(self)
84+
self.bin_path = None
85+
86+
def finalize_options(self):
87+
"""Load provided CLI arguments into our options"""
88+
install.finalize_options(self)
89+
5390
def run(self):
5491
"""Install python binary."""
5592
install.run(self)
56-
bin_path = os.path.join(self.install_lib, 'pact', 'bin')
57-
os.mkdir(bin_path)
58-
install_ruby_app(bin_path)
93+
package_bin_path = os.path.join(self.install_lib, 'pact', 'bin')
94+
if not os.path.exists(package_bin_path):
95+
os.mkdir(package_bin_path)
96+
install_ruby_app(package_bin_path, self.bin_path)
5997

6098

61-
def install_ruby_app(bin_path):
99+
def install_ruby_app(package_bin_path, download_bin_path):
62100
"""
63-
Download a Ruby application and install it for use.
101+
Installs the ruby standalone application for this OS.
64102
65-
:param bin_path: The path where binaries should be installed.
103+
:param package_bin_path: The path where we want our pact binaries unarchived.
104+
:param download_bin_path: An optional path containing pre-downloaded pact binaries.
105+
"""
106+
107+
binary = ruby_app_binary()
108+
if download_bin_path is None:
109+
download_bin_path = package_bin_path
110+
111+
path = os.path.join(download_bin_path, binary['filename'])
112+
113+
if os.path.isfile(path) is True:
114+
extract_ruby_app_binary(download_bin_path, package_bin_path, binary['filename'])
115+
else:
116+
if download_bin_path is not None:
117+
if os.path.isfile(path) is not True:
118+
raise RuntimeError('Could not find {} binary.'.format(path))
119+
extract_ruby_app_binary(download_bin_path, package_bin_path, binary['filename'])
120+
else:
121+
download_ruby_app_binary(package_bin_path, binary['filename'], binary['suffix'])
122+
extract_ruby_app_binary(package_bin_path, package_bin_path, binary['filename'])
123+
124+
def ruby_app_binary():
125+
"""
126+
Determines the ruby app binary required for this OS.
127+
128+
:return A dictionary of type {'filename': string, 'version': string, 'suffix': string }
66129
"""
67130
target_platform = platform.platform().lower()
68-
uri = ('https://github.com/pact-foundation/pact-ruby-standalone/releases'
69-
'/download/v{version}/pact-{version}-{suffix}')
131+
132+
binary = ('pact-{version}-{suffix}')
70133

71134
if 'darwin' in target_platform or 'macos' in target_platform:
72135
suffix = 'osx.tar.gz'
@@ -82,12 +145,26 @@ def install_ruby_app(bin_path):
82145
platform.platform())
83146
raise Exception(msg)
84147

148+
binary = binary.format(version=PACT_STANDALONE_VERSION, suffix=suffix)
149+
return {'filename': binary, 'version': PACT_STANDALONE_VERSION, 'suffix': suffix}
150+
151+
def download_ruby_app_binary(path_to_download_to, filename, suffix):
152+
"""
153+
Downloads `binary` into `path_to_download_to`.
154+
155+
:param path_to_download_to: The path where binaries should be downloaded.
156+
:param filename: The filename that should be installed.
157+
:param suffix: The suffix of the standalone app to install.
158+
"""
159+
uri = ('https://github.com/pact-foundation/pact-ruby-standalone/releases'
160+
'/download/v{version}/pact-{version}-{suffix}')
161+
85162
if sys.version_info.major == 2:
86163
from urllib import urlopen
87164
else:
88165
from urllib.request import urlopen
89166

90-
path = os.path.join(bin_path, suffix)
167+
path = os.path.join(path_to_download_to, filename)
91168
resp = urlopen(uri.format(version=PACT_STANDALONE_VERSION, suffix=suffix))
92169
with open(path, 'wb') as f:
93170
if resp.code == 200:
@@ -97,12 +174,21 @@ def install_ruby_app(bin_path):
97174
'Received HTTP {} when downloading {}'.format(
98175
resp.code, resp.url))
99176

177+
def extract_ruby_app_binary(source, destination, binary):
178+
"""
179+
Extracts the ruby app binary from `source` into `destination`.
180+
181+
:param source: The location of the binary to unarchive.
182+
:param destination: The location to unarchive to.
183+
:param binary: The binary that needs to be unarchived.
184+
"""
185+
path = os.path.join(source, binary)
100186
if 'windows' in platform.platform().lower():
101187
with ZipFile(path) as f:
102-
f.extractall(bin_path)
188+
f.extractall(destination)
103189
else:
104190
with tarfile.open(path) as f:
105-
f.extractall(bin_path)
191+
f.extractall(destination)
106192

107193

108194
def read(filename):
@@ -117,16 +203,17 @@ def read(filename):
117203
'psutil>=2.0.0',
118204
'requests>=2.5.0',
119205
'six>=1.9.0',
120-
'fastapi==0.67.0',
206+
'fastapi>=0.67.0',
121207
'urllib3>=1.26.5',
122-
'uvicorn==0.14.0'
208+
'uvicorn>=0.14.0'
123209
]
124210

125211
if __name__ == '__main__':
126212
setup(
127213
cmdclass={
128214
'develop': PactPythonDevelopCommand,
129-
'install': PactPythonInstallCommand},
215+
'install': PactPythonInstallCommand,
216+
'sdist': sdist},
130217
name='pact-python',
131218
version=about['__version__'],
132219
description=(

0 commit comments

Comments
 (0)