From ab43c8b458301f5e8cc9ea464672f0a462db4a5f Mon Sep 17 00:00:00 2001 From: Matthew Balvanz Date: Wed, 31 May 2017 21:00:51 -0500 Subject: [PATCH] Switch to installing the packages from pact-ruby-standalone --- Makefile | 5 +-- README.md | 9 ++-- RELEASING.md | 3 +- pact/constants.py | 4 +- scripts/build.sh | 111 ---------------------------------------------- setup.py | 92 ++++++++++---------------------------- 6 files changed, 32 insertions(+), 192 deletions(-) delete mode 100755 scripts/build.sh diff --git a/Makefile b/Makefile index 3f08da4945..123a7111fd 100644 --- a/Makefile +++ b/Makefile @@ -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" @@ -60,10 +61,6 @@ package: python setup.py sdist -pact/bin: - scripts/build.sh - - .PHONY: test test: deps pact/bin flake8 diff --git a/README.md b/README.md index 35f779f445..273079bbcf 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/RELEASING.md b/RELEASING.md index 5f67cbc406..f1b7d90ae8 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -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: diff --git a/pact/constants.py b/pact/constants.py index 9310cac4a3..801689a330 100644 --- a/pact/constants.py +++ b/pact/constants.py @@ -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())) diff --git a/scripts/build.sh b/scripts/build.sh deleted file mode 100755 index d759e9229d..0000000000 --- a/scripts/build.sh +++ /dev/null @@ -1,111 +0,0 @@ -#!/usr/bin/env bash - -set -e - - -build() { - echo "Building..." - pushd $(pwd) - mkdir -p build - cd build - if [ ! -d "${PROJECT_NAME}-${GEM_VERSION}" ]; then - wget https://github.com/${REPOSITORY}/archive/v${GEM_VERSION}.zip -O temp.zip - unzip temp.zip - rm temp.zip - fi - - cd ${PROJECT_NAME}-${GEM_VERSION} - - bundle - bundle exec rake package - popd -} - - -package() { - echo "Packaging $STANDALONE_PACKAGE_NAME.$EXTENSION for pypi as $PYPI_PACKAGE_NAME.$EXTENSION" - pushd $(pwd) - mkdir -p pact/bin - - cd build - cp ${PROJECT_NAME}-${GEM_VERSION}/pkg/${PROJECT_NAME//_/-}-* . - rm -rf $STANDALONE_PACKAGE_NAME - - if [ $EXTENSION = "zip" ]; then - unzip $STANDALONE_PACKAGE_NAME.$EXTENSION - else - tar -xzf $STANDALONE_PACKAGE_NAME.$EXTENSION - fi - - mv $STANDALONE_PACKAGE_NAME $PYPI_PACKAGE_NAME - cd $PYPI_PACKAGE_NAME - - tar -czf ../../pact/bin/${PYPI_PACKAGE_NAME}.tar.gz * - popd -} - - -echo "Packaging the Mock Service for distribution." -export GEM_VERSION=2.1.0 -export RELEASE_VERSION=1 -export PACKAGE_VERSION=${GEM_VERSION}-${RELEASE_VERSION} - -export PROJECT_NAME='pact-mock_service' -export REPOSITORY='bethesque/pact-mock_service' -build - -export STANDALONE_PACKAGE_NAME="${PROJECT_NAME//_/-}-${PACKAGE_VERSION}-win32" -export PYPI_PACKAGE_NAME="${PROJECT_NAME//_/-}-win32" -export SUFFIX='win32' -export EXTENSION='zip' -package - -export STANDALONE_PACKAGE_NAME="${PROJECT_NAME//_/-}-${PACKAGE_VERSION}-osx" -export PYPI_PACKAGE_NAME="${PROJECT_NAME//_/-}-darwin" -export SUFFIX='osx' -export EXTENSION='tar.gz' -package - -export STANDALONE_PACKAGE_NAME="${PROJECT_NAME//_/-}-${PACKAGE_VERSION}-linux-x86" -export PYPI_PACKAGE_NAME="${PROJECT_NAME//_/-}-ia32" -export SUFFIX='linux-x86' -export EXTENSION='tar.gz' -package - -export STANDALONE_PACKAGE_NAME="${PROJECT_NAME//_/-}-${PACKAGE_VERSION}-linux-x86_64" -export PYPI_PACKAGE_NAME="${PROJECT_NAME//_/-}-linux-x64" -export SUFFIX='linux-x86_64' -export EXTENSION='tar.gz' -package - -echo "Packaging the Verifier for distribution." -export GEM_VERSION=1.0.1 -export RELEASE_VERSION=1 -export PACKAGE_VERSION=${GEM_VERSION}-${RELEASE_VERSION} -export PROJECT_NAME='pact-provider-verifier' -export REPOSITORY='pact-foundation/pact-provider-verifier' -build - -export STANDALONE_PACKAGE_NAME="${PROJECT_NAME}-${PACKAGE_VERSION}-win32" -export PYPI_PACKAGE_NAME="${PROJECT_NAME}-win32" -export SUFFIX='win32' -export EXTENSION='zip' -package - -export STANDALONE_PACKAGE_NAME="${PROJECT_NAME}-${PACKAGE_VERSION}-osx" -export PYPI_PACKAGE_NAME="${PROJECT_NAME}-darwin" -export SUFFIX='osx' -export EXTENSION='tar.gz' -package - -export STANDALONE_PACKAGE_NAME="${PROJECT_NAME}-${PACKAGE_VERSION}-linux-x86" -export PYPI_PACKAGE_NAME="${PROJECT_NAME}-linux-ia32" -export SUFFIX='linux-x86' -export EXTENSION='tar.gz' -package - -export STANDALONE_PACKAGE_NAME="${PROJECT_NAME}-${PACKAGE_VERSION}-linux-x86_64" -export PYPI_PACKAGE_NAME="${PROJECT_NAME}-linux-x64" -export SUFFIX='linux-x86_64' -export EXTENSION='tar.gz' -package diff --git a/setup.py b/setup.py index 28ce7e18a1..9a96e454d3 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,6 @@ import sys import tarfile -import shutil from zipfile import ZipFile from setuptools import setup @@ -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): @@ -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): @@ -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()) @@ -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.""" @@ -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: