Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for automated wheel packaging / PyPI deploys #19

Merged
merged 4 commits into from
Sep 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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