Skip to content

Commit 75a96dc

Browse files
Package the Ruby Mock Service and Verifier
- Build process now downloads and prepares the Ruby applications like the NPM based Pact - Resulting *.tar.gz now includes portable Ruby versions of Mock Service and Verifier - The platform appropriate version is unpacked when a user installs pact-python
1 parent 189c647 commit 75a96dc

File tree

6 files changed

+198
-3
lines changed

6 files changed

+198
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# pact-python specific ignores
22
e2e/pacts
3+
pact/bin
34

45
# Byte-compiled / optimized / DLL files
56
__pycache__/

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ sudo: false
1010

1111
install: pip install -r requirements_dev.txt
1212

13-
script: make test
13+
script:
14+
- flake8
15+
- pydocstyle pact
16+
- tox --develop

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
include LICENSE
2+
include *.gz
23
include *.txt
34
include *.md
45
prune *test
6+
prune e2e/*

Makefile

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ endef
1010

1111
help:
1212
@echo ""
13+
@echo " clean to clear build and distribution directories"
1314
@echo " deps to install the required files for development"
1415
@echo " package to create a distribution package in /dist/"
1516
@echo " release to perform a release build, including deps, test, and package targets"
@@ -21,6 +22,13 @@ help:
2122
release: deps test package
2223

2324

25+
.PHONY: clean
26+
clean:
27+
rm -rf build
28+
rm -rf dist
29+
rm -rf pact/bin
30+
31+
2432
.PHONY: deps
2533
deps:
2634
pip install -r requirements_dev.txt
@@ -42,13 +50,17 @@ e2e:
4250
docker-compose down'
4351

4452
.PHONY: package
45-
package:
53+
package: pact/bin
4654
python setup.py sdist
4755

4856

57+
pact/bin:
58+
scripts/build.sh
59+
60+
4961
export VERSION_CHECK
5062
.PHONY: test
51-
test: deps
63+
test: deps pact/bin
5264
@echo "Checking version consistency..."
5365
python -c "$$VERSION_CHECK"
5466

scripts/build.sh

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
6+
build() {
7+
echo "Building..."
8+
pushd $(pwd)
9+
mkdir -p build
10+
cd build
11+
if [ ! -d "${PROJECT_NAME}-${GEM_VERSION}" ]; then
12+
wget https://github.com/${REPOSITORY}/archive/v${GEM_VERSION}.zip -O temp.zip
13+
unzip temp.zip
14+
rm temp.zip
15+
fi
16+
17+
cd ${PROJECT_NAME}-${GEM_VERSION}
18+
19+
bundle
20+
bundle exec rake package
21+
popd
22+
}
23+
24+
25+
package() {
26+
echo "Packaging $STANDALONE_PACKAGE_NAME.$EXTENSION for pypi as $PYPI_PACKAGE_NAME.$EXTENSION"
27+
pushd $(pwd)
28+
mkdir -p pact/bin
29+
30+
cd build
31+
cp ${PROJECT_NAME}-${GEM_VERSION}/pkg/${PROJECT_NAME//_/-}-* .
32+
rm -rf $STANDALONE_PACKAGE_NAME
33+
34+
if [ $EXTENSION = "zip" ]; then
35+
unzip $STANDALONE_PACKAGE_NAME.$EXTENSION
36+
else
37+
tar -xzf $STANDALONE_PACKAGE_NAME.$EXTENSION
38+
fi
39+
40+
mv $STANDALONE_PACKAGE_NAME $PYPI_PACKAGE_NAME
41+
cd $PYPI_PACKAGE_NAME
42+
43+
tar -czf ../../pact/bin/${PYPI_PACKAGE_NAME}.tar.gz *
44+
popd
45+
}
46+
47+
48+
echo "Packaging the Mock Service for distribution."
49+
export GEM_VERSION=0.12.1
50+
export RELEASE_VERSION=1
51+
export PACKAGE_VERSION=${GEM_VERSION}-${RELEASE_VERSION}
52+
53+
export PROJECT_NAME='pact-mock_service'
54+
export REPOSITORY='bethesque/pact-mock_service'
55+
build
56+
57+
export STANDALONE_PACKAGE_NAME="${PROJECT_NAME//_/-}-${PACKAGE_VERSION}-win32"
58+
export PYPI_PACKAGE_NAME="${PROJECT_NAME//_/-}-win32"
59+
export SUFFIX='win32'
60+
export EXTENSION='zip'
61+
package
62+
63+
export STANDALONE_PACKAGE_NAME="${PROJECT_NAME//_/-}-${PACKAGE_VERSION}-osx"
64+
export PYPI_PACKAGE_NAME="${PROJECT_NAME//_/-}-darwin"
65+
export SUFFIX='osx'
66+
export EXTENSION='tar.gz'
67+
package
68+
69+
export STANDALONE_PACKAGE_NAME="${PROJECT_NAME//_/-}-${PACKAGE_VERSION}-linux-x86"
70+
export PYPI_PACKAGE_NAME="${PROJECT_NAME//_/-}-ia32"
71+
export SUFFIX='linux-x86'
72+
export EXTENSION='tar.gz'
73+
package
74+
75+
export STANDALONE_PACKAGE_NAME="${PROJECT_NAME//_/-}-${PACKAGE_VERSION}-linux-x86_64"
76+
export PYPI_PACKAGE_NAME="${PROJECT_NAME//_/-}-linux-x64"
77+
export SUFFIX='linux-x86_64'
78+
export EXTENSION='tar.gz'
79+
package
80+
81+
echo "Packaging the Verifier for distribution."
82+
export GEM_VERSION=0.0.13
83+
export RELEASE_VERSION=1
84+
export PACKAGE_VERSION=${GEM_VERSION}-${RELEASE_VERSION}
85+
export PROJECT_NAME='pact-provider-verifier'
86+
export REPOSITORY='pact-foundation/pact-provider-verifier'
87+
build
88+
89+
export STANDALONE_PACKAGE_NAME="${PROJECT_NAME}-${PACKAGE_VERSION}-win32"
90+
export PYPI_PACKAGE_NAME="${PROJECT_NAME}-win32"
91+
export SUFFIX='win32'
92+
export EXTENSION='zip'
93+
package
94+
95+
export STANDALONE_PACKAGE_NAME="${PROJECT_NAME}-${PACKAGE_VERSION}-osx"
96+
export PYPI_PACKAGE_NAME="${PROJECT_NAME}-darwin"
97+
export SUFFIX='osx'
98+
export EXTENSION='tar.gz'
99+
package
100+
101+
export STANDALONE_PACKAGE_NAME="${PROJECT_NAME}-${PACKAGE_VERSION}-linux-x86"
102+
export PYPI_PACKAGE_NAME="${PROJECT_NAME}-linux-ia32"
103+
export SUFFIX='linux-x86'
104+
export EXTENSION='tar.gz'
105+
package
106+
107+
export STANDALONE_PACKAGE_NAME="${PROJECT_NAME}-${PACKAGE_VERSION}-linux-x86_64"
108+
export PYPI_PACKAGE_NAME="${PROJECT_NAME}-linux-x64"
109+
export SUFFIX='linux-x86_64'
110+
export EXTENSION='tar.gz'
111+
package

setup.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,70 @@
11
"""pact-python PyPI Package."""
22

33
import os
4+
import platform
5+
import sys
6+
import tarfile
7+
48
from setuptools import find_packages, setup
9+
from setuptools.command.install import install
10+
11+
12+
class PactPythonInstallCommand(install):
13+
"""
14+
Custom installer for pact-python.
15+
16+
Installs the Python package and unpacks the platform appropriate version
17+
of Python mock service.
18+
"""
19+
def run(self):
20+
install.run(self)
21+
bin_path = os.path.join(self.install_lib, 'pact', 'bin')
22+
self.mock_service(bin_path)
23+
self.verifier(bin_path)
24+
25+
def mock_service(self, bin_path):
26+
"""Install the Ruby mock service for this platform."""
27+
is_64 = sys.maxsize > 2 ** 32
28+
target_platform = platform.platform().lower()
29+
if 'darwin' in target_platform:
30+
platform_tar = 'pact-mock-service-darwin.tar.gz'
31+
elif 'linux' in target_platform and is_64:
32+
platform_tar = 'pact-mock-service-linux-x64.tar.gz'
33+
elif 'linux' in target_platform:
34+
platform_tar = 'pact-mock-service-ia32.tar.gz'
35+
elif 'windows' in target_platform:
36+
platform_tar = 'pact-mock-service-win32.tar.gz'
37+
else:
38+
msg = ('Unfortunately, {} is not a supported platform. Only Linux,'
39+
' Windows, and OSX are currently supported.').format(
40+
platform.platform())
41+
raise Exception(msg)
42+
43+
self.announce(u'Extracting {} to {}'.format(platform_tar, bin_path))
44+
with tarfile.open(os.path.join(bin_path, platform_tar)) as f:
45+
f.extractall(os.path.join(bin_path, 'mock-service'))
46+
47+
def verifier(self, bin_path):
48+
"""Install the Ruby Pact Verifier for this platform."""
49+
is_64 = sys.maxsize > 2 ** 32
50+
target_platform = platform.platform().lower()
51+
if 'darwin' in target_platform:
52+
platform_tar = 'pact-provider-verifier-darwin.tar.gz'
53+
elif 'linux' in target_platform and is_64:
54+
platform_tar = 'pact-provider-verifier-linux-x64.tar.gz'
55+
elif 'linux' in target_platform:
56+
platform_tar = 'pact-provider-verifier-linux-ia32.tar.gz'
57+
elif 'windows' in target_platform:
58+
platform_tar = 'pact-provider-verifier-win32.tar.gz'
59+
else:
60+
msg = ('Unfortunately, {} is not a supported platform. Only Linux,'
61+
' Windows, and OSX are currently supported.').format(
62+
platform.platform())
63+
raise Exception(msg)
64+
65+
self.announce(u'Extracting {} to {}'.format(platform_tar, bin_path))
66+
with tarfile.open(os.path.join(bin_path, platform_tar)) as f:
67+
f.extractall(os.path.join(bin_path, 'verifier'))
568

669

770
def get_version():
@@ -21,6 +84,7 @@ def read(filename):
2184
dependencies = [
2285
dep.strip() for dep in read('requirements.txt').split('\n') if dep.strip()]
2386
setup_args = dict(
87+
cmdclass={'install': PactPythonInstallCommand},
2488
name='pact-python',
2589
version=get_version(),
2690
description=('Tools for creating and verifying consumer driven contracts'
@@ -31,6 +95,8 @@ def read(filename):
3195
url='https://github.com/pact-foundation/pact-python',
3296
install_requires=dependencies,
3397
packages=find_packages(exclude=['*.test', '*.test.*', 'test.*', 'test']),
98+
package_data={'pact': ['bin/*']},
99+
package_dir={'pact': 'pact'},
34100
license=read('LICENSE'))
35101

36102

0 commit comments

Comments
 (0)