Skip to content

Commit

Permalink
Add support for automated wheel packaging / PyPI deploys (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
msanders authored Sep 14, 2018
1 parent 7211d5c commit 33f7d5e
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 1 deletion.
44 changes: 44 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
48 changes: 48 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions scripts/travis
Original file line number Diff line number Diff line change
@@ -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
29 changes: 28 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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='[email protected]',
description=description,
Expand Down

0 comments on commit 33f7d5e

Please sign in to comment.