Skip to content

Commit 10aaaf6

Browse files
Merge pull request #27 from pact-foundation/download-pre-package-mock-service-and-verifier
Resolves #20: Download pre-packaged mock service and verifier during installation
2 parents fd151d2 + a9b991b commit 10aaaf6

File tree

9 files changed

+88
-185
lines changed

9 files changed

+88
-185
lines changed

.travis.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,8 @@ install: pip install -r requirements_dev.txt
1818
script:
1919
- flake8
2020
- pydocstyle pact
21-
- tox --develop
22-
- if [[ $TRAVIS_PYTHON_VERSION == "2.7" ]]; then rvm install 2.2.2; fi
23-
- if [[ $TRAVIS_PYTHON_VERSION == "2.7" ]]; then rvm use 2.2.2; fi
24-
- ruby --version
25-
- bundler --version
26-
- if [[ $TRAVIS_PYTHON_VERSION == "2.7" ]]; then make package; fi
21+
- tox
22+
- if [[ $TRAVIS_PYTHON_VERSION == "2.7" ]]; then make package && pip install ./dist/pact-python-*.tar.gz && make e2e; fi
2723

2824
before_deploy:
2925
- export RELEASE_PACKAGE=$(ls dist/pact-python-*.tar.gz)

MANIFEST.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
include LICENSE
2-
include *.gz
32
include *.txt
43
include *.md
5-
prune *test
6-
prune e2e/*
4+
prune pact/test
5+
prune pact/bin
6+
prune e2e

Makefile

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ help:
55
@echo ""
66
@echo " clean to clear build and distribution directories"
77
@echo " deps to install the required files for development"
8+
@echo " e2e to run the end to end tests"
89
@echo " package to create a distribution package in /dist/"
910
@echo " release to perform a release build, including deps, test, and package targets"
1011
@echo " test to run all tests"
@@ -52,20 +53,16 @@ endef
5253
export E2E
5354
.PHONY: e2e
5455
e2e:
55-
sh -c "$$E2E"
56+
bash -c "$$E2E"
5657

5758

5859
.PHONY: package
59-
package: pact/bin
60+
package:
6061
python setup.py sdist
6162

6263

63-
pact/bin:
64-
scripts/build.sh
65-
66-
6764
.PHONY: test
68-
test: deps pact/bin
65+
test: deps
6966
flake8
7067
pydocstyle pact
7168
coverage erase

README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,10 @@ For more information about provider states, refer to the [Pact documentation] on
267267
# Development
268268
Please read [CONTRIBUTING.md](CONTRIBUTING.md)
269269

270-
This project needs a combination of Python and Ruby, as the Pact mock service and verifier
271-
are currently Ruby based. To setup a development environment:
270+
To setup a development environment:
272271

273-
1. Install Ruby 2.2.2 using a tool like [rvm] or [rbenv]
274-
2. Install the [bundler] package manager for Ruby with `gem install bundler`
275-
3. 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]
276-
4. Its recommended to create a Python [virtualenv] for the project
272+
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]
273+
2. Its recommended to create a Python [virtualenv] for the project
277274

278275
The setup the environment, run tests, and package the application, run:
279276
`make release`

RELEASING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
1. Increment the version according to semantic versioning rules in `pact/__init__.py`
44

55
2. To upgrade the the versions of `pact-mock_service` and `pact-provider-verifier`, change the
6-
appropriate `GEM_VESRION` variable in `scripts/build.sh` to the new version.
6+
`PACT_STANDALONE_VERSION` in `setup.py` to match the latest version available from the
7+
[pact-ruby-standalone](https://github.com/pact-foundation/pact-ruby-standalone/releases) repository.
78

89
3. Update the `CHANGELOG.md` using:
910

pact/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66

77

88
__all__ = ('Consumer', 'EachLike', 'Pact', 'Provider', 'SomethingLike', 'Term')
9-
__version__ = '0.5.0'
9+
__version__ = '0.6.0'

pact/constants.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def provider_verifier_exe():
2020

2121

2222
MOCK_SERVICE_PATH = normpath(join(
23-
dirname(__file__), 'bin', 'mock-service', 'bin', mock_service_exe()))
23+
dirname(__file__), 'bin', 'pact', 'bin', mock_service_exe()))
2424

2525
VERIFIER_PATH = normpath(join(
26-
dirname(__file__), 'bin', 'verifier', 'bin', provider_verifier_exe()))
26+
dirname(__file__), 'bin', 'pact', 'bin', provider_verifier_exe()))

scripts/build.sh

Lines changed: 0 additions & 111 deletions
This file was deleted.

setup.py

Lines changed: 71 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,68 +5,90 @@
55
import sys
66
import tarfile
77

8+
from zipfile import ZipFile
9+
810
from setuptools import setup
11+
from setuptools.command.develop import develop
912
from setuptools.command.install import install
1013

1114
import pact
1215

1316

17+
IS_64 = sys.maxsize > 2 ** 32
18+
PACT_STANDALONE_VERSION = '1.0.0'
19+
20+
21+
class PactPythonDevelopCommand(develop):
22+
"""
23+
Custom develop mode installer for pact-python.
24+
25+
When the package is installed using `python setup.py develop` or
26+
`pip install -e` it will download and unpack the appropriate Pact
27+
mock service and provider verifier.
28+
"""
29+
def run(self):
30+
develop.run(self)
31+
bin_path = os.path.join(os.path.dirname(__file__), 'pact', 'bin')
32+
if not os.path.exists(bin_path):
33+
os.mkdir(bin_path)
34+
35+
install_ruby_app(bin_path)
36+
37+
1438
class PactPythonInstallCommand(install):
1539
"""
1640
Custom installer for pact-python.
1741
1842
Installs the Python package and unpacks the platform appropriate version
19-
of Python mock service.
43+
of the Ruby mock service and provider verifier.
2044
"""
2145
def run(self):
2246
install.run(self)
2347
bin_path = os.path.join(self.install_lib, 'pact', 'bin')
24-
self.mock_service(bin_path)
25-
self.verifier(bin_path)
26-
27-
def mock_service(self, bin_path):
28-
"""Install the Ruby mock service for this platform."""
29-
is_64 = sys.maxsize > 2 ** 32
30-
target_platform = platform.platform().lower()
31-
if 'darwin' in target_platform:
32-
platform_tar = 'pact-mock-service-darwin.tar.gz'
33-
elif 'linux' in target_platform and is_64:
34-
platform_tar = 'pact-mock-service-linux-x64.tar.gz'
35-
elif 'linux' in target_platform:
36-
platform_tar = 'pact-mock-service-ia32.tar.gz'
37-
elif 'windows' in target_platform:
38-
platform_tar = 'pact-mock-service-win32.tar.gz'
39-
else:
40-
msg = ('Unfortunately, {} is not a supported platform. Only Linux,'
41-
' Windows, and OSX are currently supported.').format(
42-
platform.platform())
43-
raise Exception(msg)
44-
45-
self.announce(u'Extracting {} to {}'.format(platform_tar, bin_path))
46-
with tarfile.open(os.path.join(bin_path, platform_tar)) as f:
47-
f.extractall(os.path.join(bin_path, 'mock-service'))
48-
49-
def verifier(self, bin_path):
50-
"""Install the Ruby Pact Verifier for this platform."""
51-
is_64 = sys.maxsize > 2 ** 32
52-
target_platform = platform.platform().lower()
53-
if 'darwin' in target_platform:
54-
platform_tar = 'pact-provider-verifier-darwin.tar.gz'
55-
elif 'linux' in target_platform and is_64:
56-
platform_tar = 'pact-provider-verifier-linux-x64.tar.gz'
57-
elif 'linux' in target_platform:
58-
platform_tar = 'pact-provider-verifier-linux-ia32.tar.gz'
59-
elif 'windows' in target_platform:
60-
platform_tar = 'pact-provider-verifier-win32.tar.gz'
61-
else:
62-
msg = ('Unfortunately, {} is not a supported platform. Only Linux,'
63-
' Windows, and OSX are currently supported.').format(
64-
platform.platform())
65-
raise Exception(msg)
66-
67-
self.announce(u'Extracting {} to {}'.format(platform_tar, bin_path))
68-
with tarfile.open(os.path.join(bin_path, platform_tar)) as f:
69-
f.extractall(os.path.join(bin_path, 'verifier'))
48+
os.mkdir(bin_path)
49+
install_ruby_app(bin_path)
50+
51+
52+
def install_ruby_app(bin_path):
53+
"""
54+
Download a Ruby application and install it for use.
55+
56+
:param bin_path: The path where binaries should be installed.
57+
"""
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+
76+
if sys.version_info.major == 2:
77+
from urllib import urlopen
78+
else:
79+
from urllib.request import urlopen
80+
81+
path = os.path.join(bin_path, suffix)
82+
resp = urlopen(uri.format(version=PACT_STANDALONE_VERSION, suffix=suffix))
83+
with open(path, 'wb') as f:
84+
f.write(resp.read())
85+
86+
if 'windows' in platform.platform().lower():
87+
with ZipFile(path) as f:
88+
f.extractall(bin_path)
89+
else:
90+
with tarfile.open(path) as f:
91+
f.extractall(bin_path)
7092

7193

7294
def read(filename):
@@ -82,7 +104,8 @@ def read(filename):
82104
dependencies.append('subprocess32')
83105

84106
setup_args = dict(
85-
cmdclass={'install': PactPythonInstallCommand},
107+
cmdclass={'develop': PactPythonDevelopCommand,
108+
'install': PactPythonInstallCommand},
86109
name='pact-python',
87110
version=pact.__version__,
88111
description=('Tools for creating and verifying consumer driven contracts'

0 commit comments

Comments
 (0)