diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..c818937 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,44 @@ +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 + # Note: TWINE_PASSWORD is set in Travis settings. +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="CI=\"$CI\" TRAVIS_BRANCH=\"$TRAVIS_BRANCH\" TRAVIS_COMMIT=\"$TRAVIS_COMMIT\" PATH=\"\$HOME/rust/bin:\$PATH\"" + - cibuildwheel --output-dir wheelhouse + - | + 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 new file mode 100644 index 0000000..4667c2e --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,48 @@ +environment: + TWINE_USERNAME: michael.sanders + # Note: TWINE_PASSWORD is set in Appveyor settings. + 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* 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" --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: + - 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 diff --git a/setup.py b/setup.py index b2894a5..ad37486 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,36 @@ 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")) + 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 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) + 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,