From c0ab3b823eeea6b43626b96012bb7bf15b421112 Mon Sep 17 00:00:00 2001 From: Michael Sanders Date: Sun, 9 Sep 2018 11:06:27 -0700 Subject: [PATCH 1/4] Add support for automated wheel packaging / PyPI deploys See https://www.benfrederickson.com/writing-python-extensions-in-rust-using-pyo3/ --- .travis.yml | 42 ++++++++++++++++++++++++++++++++++++++++++ appveyor.yml | 39 +++++++++++++++++++++++++++++++++++++++ scripts/travis | 15 +++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 .travis.yml create mode 100644 appveyor.yml create mode 100755 scripts/travis diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..eff263c --- /dev/null +++ b/.travis.yml @@ -0,0 +1,42 @@ +language: python + +matrix: + include: + - name: "Linux 64-bit" + sudo: required + services: + - docker + env: + - CIBW_SKIP=*manylinux1_i686* + - PIP=pip + - PYTHON=python + - name: "Linux 32-bit" + sudo: required + services: + - docker + env: + - CIBW_SKIP=*manylinux1_x86_64* + - PIP=pip + - PYTHON=python + - name: "macOS" + os: osx + language: generic + env: + - PIP=pip2 + - PYTHON=python2 + +env: + global: + - TWINE_USERNAME=michael.sanders + +script: + - $PIP install cibuildwheel setuptools_rust + - export CIBW_BEFORE_BUILD="pip install setuptools_rust && source ./scripts/travis" + - export CIBW_SKIP=cp34-*\ $CIBW_SKIP + - export CIBW_ENVIRONMENT='PATH="$HOME/rust/bin:$PATH"' + - cibuildwheel --output-dir wheelhouse + - | + if [[ $TRAVIS_TAG ]]; then + $PIP install twine + $PYTHON -m twine upload wheelhouse/*.whl + fi diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..a5261a3 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,39 @@ +environment: + TWINE_USERNAME: michael.sanders + TWINE_PASSWORD: + secure: KaZtF5dYBSkBOMAd0H/04w== + matrix: + # Stable 64-bit MSVC + - channel: stable + target: x86_64-pc-windows-msvc + CIBW_SKIP: "*win32* cp27-* cp33-* cp34-*" + CIBW_BEFORE_BUILD: pip install setuptools-rust + # Stable 32-bit MSVC + - channel: stable + target: i686-pc-windows-msvc + CIBW_SKIP: "*win_amd64* cp27-* cp33-* cp34-*" + CIBW_BEFORE_BUILD: pip install setuptools-rust + + +# From https://github.com/starkat99/appveyor-rust/blob/master/appveyor.yml +install: + - appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe + - rustup-init -yv --default-toolchain nightly --default-host %target% + - set PATH=%PATH%;%USERPROFILE%\.cargo\bin + - rustc -vV + - cargo -vV + - pip install cibuildwheel==0.9.4 setuptools_rust + +build_script: + - cibuildwheel --output-dir wheelhouse + - > + IF "%APPVEYOR_REPO_TAG%" == "true" + ( + python -m pip install twine + && + python -m twine upload 'wheelhouse/*.whl' + ) + +artifacts: + - path: "wheelhouse\\*.whl" + name: Wheels diff --git a/scripts/travis b/scripts/travis new file mode 100755 index 0000000..09cd7c7 --- /dev/null +++ b/scripts/travis @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +# From https://github.com/benfred/py-cpp-demangle/blob/13a22fd/ci/install_rust.sh +# https://www.benfrederickson.com/writing-python-extensions-in-rust-using-pyo3/ +if [ ! -d ~/rust-installer ]; then + set -x + mkdir ~/rust-installer + curl -sL https://static.rust-lang.org/rustup.sh -o ~/rust-installer/rustup.sh + sh ~/rust-installer/rustup.sh --prefix=~/rust --spec=nightly --disable-sudo -y + set +x +fi + +if command -v yum; then + yum install -y gpg libXtst libXtst-devel libXext libXext-devel +fi From cb3924e89450bdbd5bd18a3359a151e31dd5aaa8 Mon Sep 17 00:00:00 2001 From: Michael Sanders Date: Mon, 10 Sep 2018 20:58:28 -0700 Subject: [PATCH 2/4] Upload master builds to TestPyPI --- .travis.yml | 20 +++++++++++--------- appveyor.yml | 15 ++++++++++++--- setup.py | 27 ++++++++++++++++++++++++++- 3 files changed, 49 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index eff263c..c818937 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,7 @@ language: python - matrix: include: - - name: "Linux 64-bit" + - name: Linux 64-bit sudo: required services: - docker @@ -10,7 +9,7 @@ matrix: - CIBW_SKIP=*manylinux1_i686* - PIP=pip - PYTHON=python - - name: "Linux 32-bit" + - name: Linux 32-bit sudo: required services: - docker @@ -18,25 +17,28 @@ matrix: - CIBW_SKIP=*manylinux1_x86_64* - PIP=pip - PYTHON=python - - name: "macOS" + - name: macOS os: osx language: generic env: - PIP=pip2 - PYTHON=python2 - env: global: - TWINE_USERNAME=michael.sanders - + # Note: TWINE_PASSWORD is set in Travis settings. script: - - $PIP install cibuildwheel setuptools_rust + - "$PIP install cibuildwheel setuptools_rust" - export CIBW_BEFORE_BUILD="pip install setuptools_rust && source ./scripts/travis" - export CIBW_SKIP=cp34-*\ $CIBW_SKIP - - export CIBW_ENVIRONMENT='PATH="$HOME/rust/bin:$PATH"' + - export CIBW_ENVIRONMENT="CI=\"$CI\" TRAVIS_BRANCH=\"$TRAVIS_BRANCH\" TRAVIS_COMMIT=\"$TRAVIS_COMMIT\" PATH=\"\$HOME/rust/bin:\$PATH\"" - cibuildwheel --output-dir wheelhouse - | - if [[ $TRAVIS_TAG ]]; then + if [[ ! -z "$TRAVIS_TAG" ]]; then $PIP install twine $PYTHON -m twine upload wheelhouse/*.whl + elif [[ "$TRAVIS_BRANCH" = "master" ]] && [[ -z "$TRAVIS_PULL_REQUEST_SHA" ]]; then + export TWINE_PASSWORD="$TWINE_TEST_PASSWORD" + $PIP install twine + $PYTHON -m twine upload wheelhouse/*.whl --repository-url https://test.pypi.org/legacy/ fi diff --git a/appveyor.yml b/appveyor.yml index a5261a3..1196a2d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,7 +1,6 @@ environment: TWINE_USERNAME: michael.sanders - TWINE_PASSWORD: - secure: KaZtF5dYBSkBOMAd0H/04w== + # Note: TWINE_PASSWORD is set in Appveyor settings. matrix: # Stable 64-bit MSVC - channel: stable @@ -31,7 +30,17 @@ build_script: ( python -m pip install twine && - python -m twine upload 'wheelhouse/*.whl' + @python -m twine upload "wheelhouse/*.whl" --username %TWINE_USERNAME% --password %TWINE_PASSWORD% + ) + - > + IF "%APPVEYOR_REPO_BRANCH%" == "master" + ( + IF [%APPVEYOR_PULL_REQUEST_HEAD_COMMIT%] == [] + ( + python -m pip install twine + && + @python -m twine upload "wheelhouse/*.whl" --repository-url https://test.pypi.org/legacy/ --username %TWINE_USERNAME% --password %TWINE_TEST_PASSWORD% + ) ) artifacts: diff --git a/setup.py b/setup.py index b2894a5..229b5d3 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,8 @@ # -*- coding: utf-8 -*- +import distutils.util +import os import re +import subprocess from ast import literal_eval from setuptools import setup from setuptools_rust import Binding, RustExtension @@ -19,12 +22,34 @@ def parse_module_metadata(): return [grep_attr(body, attr) for attr in ("version", "author")] +def strtobool(string): + return bool(distutils.util.strtobool(string)) + + +def git_rev_count(revision): + return subprocess.check_output(["git", + "rev-list", + "--count", + revision]).decode("utf-8").strip() + + +def expand_version(version): + env = os.environ + is_ci = strtobool(env.get("CI", "f")) + branch = env.get("APPVEYOR_REPO_BRANCH") or env.get("TRAVIS_BRANCH") + if is_ci and branch == "master": + commit = env.get("APPVEYOR_REPO_COMMIT") or env.get("TRAVIS_COMMIT") + rev_count = git_rev_count(commit) + return "{}.dev{}".format(version, rev_count) + return version + + def main(): version, author = parse_module_metadata() description = "A simple, cross-platform GUI automation library for Python." setup( name='autopy', - version=version, + version=expand_version(version), author=author, author_email='michael.sanders@fastmail.com', description=description, From 7a8c4cb672aebee2804df1dd967f3e86a6403cef Mon Sep 17 00:00:00 2001 From: Michael Sanders Date: Mon, 10 Sep 2018 21:10:24 -0700 Subject: [PATCH 3/4] Add Python 2.7 Windows builds --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 1196a2d..4667c2e 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -10,7 +10,7 @@ environment: # Stable 32-bit MSVC - channel: stable target: i686-pc-windows-msvc - CIBW_SKIP: "*win_amd64* cp27-* cp33-* cp34-*" + CIBW_SKIP: "*win_amd64* cp33-* cp34-*" CIBW_BEFORE_BUILD: pip install setuptools-rust From 67594b3d2832f4dd0467b158c74c69f78fda2f77 Mon Sep 17 00:00:00 2001 From: Michael Sanders Date: Fri, 14 Sep 2018 12:54:47 -0700 Subject: [PATCH 4/4] Fix build against PRs --- setup.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 229b5d3..ad37486 100644 --- a/setup.py +++ b/setup.py @@ -36,8 +36,10 @@ def git_rev_count(revision): def expand_version(version): env = os.environ is_ci = strtobool(env.get("CI", "f")) + pr_sha = env.get("TRAVIS_PULL_REQUEST_SHA") or \ + env.get("APPVEYOR_PULL_REQUEST_HEAD_COMMIT") branch = env.get("APPVEYOR_REPO_BRANCH") or env.get("TRAVIS_BRANCH") - if is_ci and branch == "master": + if is_ci and not pr_sha and branch == "master": commit = env.get("APPVEYOR_REPO_COMMIT") or env.get("TRAVIS_COMMIT") rev_count = git_rev_count(commit) return "{}.dev{}".format(version, rev_count)