Skip to content

Commit

Permalink
Merge pull request #27 from pact-foundation/download-pre-package-mock…
Browse files Browse the repository at this point in the history
…-service-and-verifier

Resolves #20: Download pre-packaged mock service and verifier during installation
  • Loading branch information
matthewbalvanz-wf authored Jun 21, 2017
2 parents fd151d2 + a9b991b commit 10aaaf6
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 185 deletions.
8 changes: 2 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,8 @@ install: pip install -r requirements_dev.txt
script:
- flake8
- pydocstyle pact
- tox --develop
- if [[ $TRAVIS_PYTHON_VERSION == "2.7" ]]; then rvm install 2.2.2; fi
- if [[ $TRAVIS_PYTHON_VERSION == "2.7" ]]; then rvm use 2.2.2; fi
- ruby --version
- bundler --version
- if [[ $TRAVIS_PYTHON_VERSION == "2.7" ]]; then make package; fi
- tox
- if [[ $TRAVIS_PYTHON_VERSION == "2.7" ]]; then make package && pip install ./dist/pact-python-*.tar.gz && make e2e; fi

before_deploy:
- export RELEASE_PACKAGE=$(ls dist/pact-python-*.tar.gz)
Expand Down
6 changes: 3 additions & 3 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include LICENSE
include *.gz
include *.txt
include *.md
prune *test
prune e2e/*
prune pact/test
prune pact/bin
prune e2e
11 changes: 4 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ help:
@echo ""
@echo " clean to clear build and distribution directories"
@echo " deps to install the required files for development"
@echo " e2e to run the end to end tests"
@echo " package to create a distribution package in /dist/"
@echo " release to perform a release build, including deps, test, and package targets"
@echo " test to run all tests"
Expand Down Expand Up @@ -52,20 +53,16 @@ endef
export E2E
.PHONY: e2e
e2e:
sh -c "$$E2E"
bash -c "$$E2E"


.PHONY: package
package: pact/bin
package:
python setup.py sdist


pact/bin:
scripts/build.sh


.PHONY: test
test: deps pact/bin
test: deps
flake8
pydocstyle pact
coverage erase
Expand Down
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,10 @@ For more information about provider states, refer to the [Pact documentation] on
# Development
Please read [CONTRIBUTING.md](CONTRIBUTING.md)

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

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

The setup the environment, run tests, and package the application, run:
`make release`
Expand Down
3 changes: 2 additions & 1 deletion RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
1. Increment the version according to semantic versioning rules in `pact/__init__.py`

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

3. Update the `CHANGELOG.md` using:

Expand Down
2 changes: 1 addition & 1 deletion pact/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@


__all__ = ('Consumer', 'EachLike', 'Pact', 'Provider', 'SomethingLike', 'Term')
__version__ = '0.5.0'
__version__ = '0.6.0'
4 changes: 2 additions & 2 deletions pact/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def provider_verifier_exe():


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

VERIFIER_PATH = normpath(join(
dirname(__file__), 'bin', 'verifier', 'bin', provider_verifier_exe()))
dirname(__file__), 'bin', 'pact', 'bin', provider_verifier_exe()))
111 changes: 0 additions & 111 deletions scripts/build.sh

This file was deleted.

119 changes: 71 additions & 48 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,68 +5,90 @@
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 Python mock service.
of the Ruby mock service and provider verifier.
"""
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'))
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):
Expand All @@ -82,7 +104,8 @@ def read(filename):
dependencies.append('subprocess32')

setup_args = dict(
cmdclass={'install': PactPythonInstallCommand},
cmdclass={'develop': PactPythonDevelopCommand,
'install': PactPythonInstallCommand},
name='pact-python',
version=pact.__version__,
description=('Tools for creating and verifying consumer driven contracts'
Expand Down

0 comments on commit 10aaaf6

Please sign in to comment.