Skip to content

Commit

Permalink
Switch to installing the packages from pact-ruby-standalone
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewbalvanz-wf committed Jun 19, 2017
1 parent db3e7c3 commit ab43c8b
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 192 deletions.
5 changes: 1 addition & 4 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 @@ -60,10 +61,6 @@ package:
python setup.py sdist


pact/bin:
scripts/build.sh


.PHONY: test
test: deps pact/bin
flake8
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
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.

92 changes: 24 additions & 68 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import sys
import tarfile

import shutil
from zipfile import ZipFile

from setuptools import setup
Expand All @@ -16,11 +15,7 @@


IS_64 = sys.maxsize > 2 ** 32
MOCK_SERVICE_URI = (
'https://github.com/bethesque/pact-mock_service/releases/download/v2.1.0/')
VERIFIER_URI = (
'https://github.com/pact-foundation/pact-provider-verifier'
'/releases/download/v1.0.2/')
PACT_STANDALONE_VERSION = '0.0.1'


class PactPythonDevelopCommand(develop):
Expand All @@ -37,8 +32,7 @@ def run(self):
if not os.path.exists(bin_path):
os.mkdir(bin_path)

mock_service(bin_path)
verifier(bin_path)
install_ruby_app(bin_path)


class PactPythonInstallCommand(install):
Expand All @@ -52,26 +46,40 @@ def run(self):
install.run(self)
bin_path = os.path.join(self.install_lib, 'pact', 'bin')
os.mkdir(bin_path)
mock_service(bin_path)
verifier(bin_path)
install_ruby_app(bin_path)


def install_ruby_app(bin_path, dir_name, platform_tar, repository_uri):
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.
:param platform_tar: The application tar or zip file to download.
:param dir_name: The directory name for the unpacked files.
:param repository_uri: The GitHub repository URI.
"""
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, platform_tar)
resp = urlopen(repository_uri + platform_tar)
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())

Expand All @@ -82,38 +90,6 @@ def install_ruby_app(bin_path, dir_name, platform_tar, repository_uri):
with tarfile.open(path) as f:
f.extractall(bin_path)

platform_name = platform_tar.replace('.tar.gz', '').replace('.zip', '')
shutil.move(os.path.join(bin_path, platform_name),
os.path.join(bin_path, dir_name))


def get_version():
"""Return latest version noted in CHANGES.txt."""
lastline = [line for line in read('CHANGES.txt').split('\n') if line][-1]
version = lastline.split(',')[0]
return version[1:]


def mock_service(bin_path):
"""Install the Ruby mock service for this platform."""
target_platform = platform.platform().lower()
if 'darwin' in target_platform:
platform_tar = 'pact-mock-service-2.1.0-1-osx.tar.gz'
elif 'linux' in target_platform and IS_64:
platform_tar = 'pact-mock-service-2.1.0-1-linux-x86_64.tar.gz'
elif 'linux' in target_platform:
platform_tar = 'pact-mock-service-2.1.0-1-linux-x86.tar.gz'
elif 'windows' in target_platform:
platform_tar = 'pact-mock-service-2.1.0-1-win32.zip'
else:
msg = ('Unfortunately, {} is not a supported platform. Only Linux,'
' Windows, and OSX are currently supported.').format(
platform.platform())
raise Exception(msg)

install_ruby_app(
bin_path, 'mock-service', platform_tar, MOCK_SERVICE_URI)


def read(filename):
"""Read file contents."""
Expand All @@ -122,26 +98,6 @@ def read(filename):
return f.read().decode('utf-8')


def verifier(bin_path):
"""Install the Ruby Pact Verifier for this platform."""
target_platform = platform.platform().lower()
if 'darwin' in target_platform:
platform_tar = 'pact-provider-verifier-1.0.2-1-osx.tar.gz'
elif 'linux' in target_platform and IS_64:
platform_tar = 'pact-provider-verifier-1.0.2-1-linux-x86_64.tar.gz'
elif 'linux' in target_platform:
platform_tar = 'pact-provider-verifier-1.0.2-1-linux-x86.tar.gz'
elif 'windows' in target_platform:
platform_tar = 'pact-provider-verifier-1.0.2-1-win32.zip'
else:
msg = ('Unfortunately, {} is not a supported platform. Only Linux,'
' Windows, and OSX are currently supported.').format(
platform.platform())
raise Exception(msg)

install_ruby_app(bin_path, 'verifier', platform_tar, VERIFIER_URI)


dependencies = read('requirements.txt').split()

if sys.version_info.major == 2:
Expand Down

0 comments on commit ab43c8b

Please sign in to comment.