Skip to content

Commit ebed62a

Browse files
authored
Continuous Integration with Travis CI and AppVeyor (#5)
Continuous integration with Travis and AppVeyor. When a release is tagged and ready, it can be uploaded using Twine
1 parent 615ee07 commit ebed62a

File tree

8 files changed

+534
-88
lines changed

8 files changed

+534
-88
lines changed

.appveyor/appveyor-bootstrap.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
with various fixes and improvements that just weren't feasible to implement in PowerShell.
66
"""
77
from __future__ import print_function
8+
9+
import logging
10+
811
from os import environ
912
from os.path import exists
1013
from subprocess import check_call
@@ -14,6 +17,10 @@
1417
except ImportError:
1518
from urllib import urlretrieve
1619

20+
21+
log = logging.getLogger(__name__)
22+
23+
1724
BASE_URL = "https://www.python.org/ftp/python/"
1825
GET_PIP_URL = "https://bootstrap.pypa.io/get-pip.py"
1926
GET_PIP_PATH = "C:\get-pip.py"
@@ -48,63 +55,64 @@
4855

4956

5057
def download_file(url, path):
51-
print("Downloading: {} (into {})".format(url, path))
58+
log.info("Downloading: %s (into %s).", url, path)
5259
progress = [0, 0]
5360

5461
def report(count, size, total):
5562
progress[0] = count * size
5663
if progress[0] - progress[1] > 1000000:
5764
progress[1] = progress[0]
58-
print("Downloaded {:,}/{:,} ...".format(progress[1], total))
65+
log.info("Downloaded %n/%n ...", progress[1], total)
5966

6067
dest, _ = urlretrieve(url, path, reporthook=report)
6168
return dest
6269

6370

6471
def install_python(version, arch, home):
65-
print("Installing Python", version, "for", arch, "bit architecture to", home)
72+
log.info("Installing Python %s for %s bit architecture to '%s'.",
73+
version, arch, home)
6674
if exists(home):
6775
return
6876

6977
path = download_python(version, arch)
70-
print("Installing", path, "to", home)
78+
log.info("Installing '%s' to '%s'.", path, home)
7179
success = False
7280
for cmd in INSTALL_CMD[version]:
7381
cmd = [part.format(home=home, path=path) for part in cmd]
74-
print("Running:", " ".join(cmd))
82+
log.info("Running '%s'.", " ".join(cmd))
7583
try:
7684
check_call(cmd)
7785
except Exception as exc:
78-
print("Failed command", cmd, "with:", exc)
86+
log.exception("Failed command '%s'.", " ".join(cmd))
7987
if exists("install.log"):
8088
with open("install.log") as fh:
81-
print(fh.read())
89+
log.error(fh.read())
8290
else:
8391
success = True
8492
if success:
85-
print("Installation complete!")
93+
log.info("Installation complete.")
8694
else:
87-
print("Installation failed")
95+
log.error("Installation failed.")
8896

8997

9098
def download_python(version, arch):
9199
for _ in range(3):
92100
try:
93101
return download_file(URLS[version, arch], "installer.exe")
94102
except Exception as exc:
95-
print("Failed to download:", exc)
96-
print("Retrying ...")
103+
log.exception("Failed to download.")
104+
log.info("Retrying ...")
97105

98106

99107
def install_pip(home):
100108
pip_path = home + "/Scripts/pip.exe"
101109
python_path = home + "/python.exe"
102110
if exists(pip_path):
103-
print("pip already installed.")
111+
log.info("pip already installed.")
104112
else:
105-
print("Installing pip...")
113+
log.info("Installing pip.")
106114
download_file(GET_PIP_URL, GET_PIP_PATH)
107-
print("Executing:", python_path, GET_PIP_PATH)
115+
log.info("Executing: %s %s", python_path, GET_PIP_PATH)
108116
check_call([python_path, GET_PIP_PATH])
109117

110118

@@ -114,7 +122,10 @@ def install_packages(home, *packages):
114122
check_call(cmd)
115123

116124

117-
if __name__ == "__main__":
125+
if __name__ == '__main__':
126+
logging.basicConfig(level=logging.DEBUG,
127+
format="%(message)s")
128+
118129
install_python(environ['PYTHON_VERSION'], environ['PYTHON_ARCH'], environ['PYTHON_HOME'])
119130
install_pip(environ['PYTHON_HOME'])
120131
install_packages(environ['PYTHON_HOME'], "setuptools>=36.4.0", "wheel")

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ MANIFEST
44
*.egg-info
55
*.pyc
66
*.so
7+
*.swp
78
venv/

.travis.yml

Lines changed: 115 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,32 @@
11
language: python
2+
cache: pip
3+
sudo: false
4+
5+
env:
6+
global:
7+
# GITHUB_API_TOKEN
8+
- secure: YNLKYudc4YRn+i89r20lB8oDoigXqiBWHpBi+QVNUCuzbHcp1rtK5/uwvbMEzERPTcRsFcqp0BHOaXf8PzWFVYVVlLCag9eX69HuOopHakW6zvZgWEv5ZVUbzLatJmOJ6BXIP+b6o83lgrO1khG2e8VRPVVwO8D0kadr2zwpuH4=
9+
# APPVEYOR_API_TOKEN
10+
- secure: UaLfn9kWVK+EyYxvjZzoV3m3ODs+iD0F57kCF4Z+YqXdo3oPxd+hIoEpo9VtkXAvhNLbj3kvCyiv+J+lqEwuR6uoAFaiz70LaAsxIX1CuHzNhJRxUglK4TdTdoGXHo2bbiTPZRnPkYwFYip5ehx8q7tPnL+xgu3AiTTLvSr0R6g=
11+
# TWINE_USERNAME
12+
- secure: Od+iImlaOP2qzkGstfj3TTmhqWDdtZ1+CGFPJnHzZ9mj9l3Pg1Aek369f1MsGBXZeJqojiTx1xg/XzW3xH39QzbuynMGEFYOAZDnQMJsT990H1vKyHsoQ86t4n0T7FEIs6B5BzP1oDROdADHcxmRQ1BoSvWumbq/isGewArGO0M=
13+
# TWINE_PASSWORD
14+
- secure: cMN061O5PjB3B8+iSEgyo/qe3QPSDW8GaAupYtHKLnxT2M6JiepuVzZL40y9I1QTnZQMf8VIKH7XExLkgyVvbKZyQCctp9tioBBiAafp6uhAQMLSzj1+03gBzaJQJySPMLX4Snfa/TuhOqym5m4kYQTX/p3qCImzkgxWW1SV+rc=
15+
- TWINE_REPOSITORY=https://test.pypi.org/legacy/
16+
- TWINE_REPOSITORY_URL=https://test.pypi.org/legacy/
17+
18+
stages:
19+
- name: test
20+
- name: deploy
21+
if: type = push AND tag =~ ^v\d+\.\d+\.\d+
22+
23+
os:
24+
- linux
25+
26+
addons:
27+
apt_packages:
28+
- pandoc
29+
230
python:
331
- "2.7"
432
- "pypy"
@@ -7,20 +35,100 @@ python:
735
- "3.5"
836
- "3.6"
937
- "pypy3"
10-
sudo: false
1138

12-
matrix:
13-
fast_finish: true
14-
allow_failures:
15-
- python: "pypy3"
39+
before_install:
40+
- if [[ $TRAVIS_OS_NAME == "osx" ]]; then
41+
echo "Updating brew packages.";
42+
brew update || travis_terminate 1;
43+
if [[ $TRAVIS_PYTHON_VERSION == "2.7" ]]; then
44+
echo "Installing python 2.";
45+
brew upgrade python2 || travis_terminate 1;
46+
virtualenv venv -p python2;
47+
elif [[ $TRAVIS_PYTHON_VERSION == "3.6" ]]; then
48+
echo "Installing python 3.";
49+
brew install python3 || travis_terminate 1;
50+
virtualenv venv -p python3;
51+
fi;
52+
source venv/bin/activate || travis_terminate 1;
53+
python --version || travis_terminate 1;
54+
fi
55+
- if [[ $TRAVIS_PULL_REQUEST == false && $TRAVIS_TAG =~ v[0-9]+\.[0-9]+\.[0-9]+ ]]; then
56+
if [[ $TRAVIS_OS_NAME == "osx" ]]; then
57+
echo "Installing pandoc.";
58+
brew install pandoc || travis_terminate 1;
59+
fi;
60+
echo "Installing pypandoc.";
61+
pip install pypandoc || travis_terminate 1;
62+
fi
1663

1764
install:
1865
- pip install .
1966

2067
script:
21-
- python setup.py test
68+
- python setup.py test || travis_terminate 1
69+
# Need to pick a Python version to create the source distribution.
70+
- if [[ $TRAVIS_PYTHON_VERSION == "3.6" && $TRAVIS_OS_NAME == linux && $TRAVIS_PULL_REQUEST == false && $TRAVIS_TAG =~ v[0-9]+\.[0-9]+\.[0-9]+ ]]; then
71+
echo "Creating source distribution.";
72+
python setup.py sdist || travis_terminate 1;
73+
else
74+
echo "Skip creation of source distribution.";
75+
fi
76+
# Binary wheels for Linux that are too platform specific are not allowed to
77+
# be uploaded on PyPI. As we need to compile C code, we only create them on OSX.
78+
- if [[ $TRAVIS_OS_NAME == osx && $TRAVIS_PULL_REQUEST == false && $TRAVIS_TAG =~ v[0-9]+\.[0-9]+\.[0-9]+ ]]; then
79+
echo "Creating binary distribution wheel.";
80+
python setup.py bdist_wheel || travis_terminate 1;
81+
else
82+
echo "Skip creation of binary distribution wheel.";
83+
fi
84+
85+
deploy:
86+
provider: releases
87+
api_key:
88+
secure: Oy5f4YjhoPd1tAFK0nlD9ZmWYH1cpnl5R3erPinemU4S/8l0jyTb4e5gdYVhluzSTZGrvNKJREwTSsq6yOriNc9EgTc/YwkFczkFuPokGzNO+VNfaEfsm9v/zcPH+Tpc51mFWXYnhFzBkJeIeRPNoVXCifFL+WxoCyWg6ljpVHg=
89+
skip_cleanup: true
90+
file_glob: true
91+
file:
92+
- dist/Whirlpool-*.tar.gz
93+
- dist/Whirlpool-*.whl
94+
on:
95+
tags: true
96+
97+
jobs:
98+
fast_finish: true
99+
allow_failures:
100+
- python: "pypy3"
101+
include:
102+
# Manually include OSX in the job matrix, but only for
103+
# Python 2.7 and 3.6.
104+
- stage: test
105+
os: osx
106+
python: 2.7
107+
language: generic
108+
env: TRAVIS_PYTHON_VERSION=2.7
109+
- stage: test
110+
os: osx
111+
python: 3.6
112+
language: generic
113+
env: TRAVIS_PYTHON_VERSION=3.6
114+
# As the deploy script fetches all build artifacts uploaded to GitHub of
115+
# all stages, we only need to run it once.
116+
# So pinning it to Python 3.6 on Linux.
117+
- stage: deploy
118+
python: 3.6
119+
os: linux
120+
addons: skip
121+
cache: skip
122+
before_install: skip
123+
install: skip
124+
script:
125+
- echo "Check build status."
126+
- python .travis/travis-release.py || travis_terminate 1
127+
- echo "Deploy to PyPI stage."
128+
- pip install twine || travis_terminate 1
129+
- twine upload dist/* --skip-existing || travis_terminate 1
22130

23131
notifications:
24132
email:
25-
on_success: change
133+
on_success: never
26134
on_failure: change

0 commit comments

Comments
 (0)