Skip to content
This repository has been archived by the owner on Mar 28, 2019. It is now read-only.

Commit

Permalink
Merge branch 'release/0.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
JayH5 committed Nov 1, 2016
2 parents 96193c7 + 6246405 commit bc19f75
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 52 deletions.
20 changes: 13 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
language: python
env:
global:
- SETUP_SCRIPT=setup-pyenv.sh
matrix:
include:
# Without PyPy
- python: "2.7"
- python: '2.7'
# Basic options
- python: "pypy"
env: PYPY_VERSION="5.3.1"
- python: pypy
env: PYENV_VERSION=pypy-5.4.1 PYENV_VERSION_STRING='PyPy 5.4.1'
# Custom options
- python: "pypy"
env: PYPY_VERSION="5.3" PYENV_ROOT=$HOME/.pyenv-pypy PYENV_RELEASE=v20160629 PYTHON_BUILD_CACHE=$HOME/.pyenv-pypy-cache
- python: pypy
env: PYENV_VERSION=pypy-5.4.1 PYENV_VERSION_STRING='PyPy 5.4.1' PYENV_ROOT=$HOME/.pyenv-pypy PYENV_RELEASE=v1.0.2 PYTHON_BUILD_CACHE=$HOME/.pyenv-pypy-cache
# Legacy setup-pypy.sh
- python: pypy
env: PYPY_VERSION=5.4.1 SETUP_SCRIPT=setup-pypy.sh

cache:
- pip
- directories:
- $HOME/.pyenv_cache

script:
- source setup-pypy.sh
- source $SETUP_SCRIPT
- python --version

deploy:
provider: releases
api_key:
secure: ZbOjmIOmz3TsPFhM7U+RddpJxVJDfudHhKyr+ZIgc/xTDYuzGDD8VRkexpT3dGoDUpgve0SyHPeeg0Otq54mHaaig4RKQN+xDmBtFnbK+zlqjH9pM14p239wPfuMOksWIUzM15QqWe2DQoJ2BrcTdgP2EntNfJIshsoWK8EZADlqIflwLVSRNJ3qKCW+ScO+XI9CGavnKvm+J1/tBUfF8MyR4HGdFlUw17jzsdz0p5O/D7EM8VHqSGNMy6FtKkvnwuyK6gDgE8Y1o1luTDA6Ii1Qr9d0d1Oo23QIk7XxxLICnBZ+BuUIxr457TKQ1/G52J77xj7rmlo8ntdpY29I1cH8qxsyv2eUZskfO+Zvycgw/cVPkUVW24AiBT2s6cyifI56jIMircPaBGvvA/w0kbkUKAKKBsm49esgaQoxb+ewkxhNUXVo85P6IOG+vuOLiefKByOrDAYhRn8vgWwi51IBZlakjZpwP2x7Os9ffllBlRsQp4l2F6QzNVlkshJpBP7HeEl0HbWjnewmRYhmrnCpvQwI4jBFCrjMcFv763z2BNwTbfLVLZvXCKY4bQM4A/h9bdmt83OVwHqVE8sUuFs6/7iLXdfV+phSEWk/fjR9KA/pf49Jja1rzsqCS+SwPU1rr9M865RPm+1zy4ll2BnUde2o3g6kZEz5XAKl1Ig=
file: setup-pypy.sh
file: setup-pyenv.sh
on:
tags: true
33 changes: 19 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
# travis-pypy
Set up a more recent [PyPy](http://pypy.org) to use in [Travis CI](https://travis-ci.org).
# travis-pyenv
Set up [pyenv](https://github.com/yyuu/pyenv) to use in [Travis CI](https://travis-ci.org) builds.

The Travis CI build images currently contain a very old version of PyPy which breaks a bunch of Python modules. This repository contains a script that can be used to set up a newer version of PyPy in your Travis CI builds using [pyenv](https://github.com/yyuu/pyenv).
Setting up pyenv properly in a Travis CI build environment can be quite tricky. This repo contains a script ([`setup-pyenv.sh`](setup-pyenv.sh)) that makes this process much simpler.

A common use case for this is to install an up-to-date version of [PyPy](http://pypy.org). The Travis CI build images currently contain a very old version of PyPy which breaks some common Python modules.

## Usage
1. Set the `$PYPY_VERSION` environment variable to the version of PyPy to install.
1. Set the `$PYENV_VERSION` environment variable to the Python to install.
2. Tell Travis to cache the `$HOME/.pyenv_cache` directory.
3. Download and source the script in `before_install`.

There are a few install options that can be set via environment variables:
* `PYPY_VERSION`
Version of PyPy2 to install [required]
* `PYENV_VERSION`
The pyenv to install [required]
* `PYENV_VERSION_STRING`
String to `fgrep` against the output of `python --version` to validate that the correct Python was installed (recommended) [default: none]
* `PYENV_ROOT`
Directory in which to install pyenv [default: `~/.pyenv`]
* `PYENV_RELEASE`
Expand All @@ -24,19 +28,20 @@ There are a few install options that can be set via environment variables:
language: python
matrix:
include:
- python: "2.7"
- python: "pypy"
env: PYPY_VERSION="5.3.1"
- python: '2.7'
- python: '3.5'
- python: pypy
env: PYENV_VERSION=pypy-5.4.1 PYENV_VERSION_STRING='PyPy 5.4.1'
cache:
- pip
- directories:
- $HOME/.pyenv_cache
- ~/.pyenv_cache

before_install:
- |
if [[ -n "$PYPY_VERSION" ]]; then
wget https://github.com/praekeltfoundation/travis-pypy/releases/download/0.1.0/setup-pypy.sh
source setup-pypy.sh
if [[ -n "$PYENV_VERSION" ]]; then
wget https://github.com/praekeltfoundation/travis-pyenv/releases/download/0.2.0/setup-pyenv.sh
source setup-pyenv.sh
fi
script:
Expand All @@ -45,4 +50,4 @@ script:
## Notes
* Installing pyenv by downloading a release tag rather than cloning the git repo can make your builds a bit faster in some cases. Set the `PYENV_RELEASE` environment variable to achieve that.
* pyenv fails to install properly if ~/.pyenv is present, even if the directory is empty. So if you cache any directories within ~/.pyenv then you will probably break pyenv.
* pyenv fails to install properly if `~/.pyenv` is present, even if the directory is empty. So if you cache any directories within `~/.pyenv` then you will probably break pyenv.
57 changes: 57 additions & 0 deletions setup-pyenv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# NOTE: This script needs to be sourced so it can modify the environment.
#
# Environment variables that can be set:
# - PYENV_VERSION
# Python to install [required]
# - PYENV_VERSION_STRING
# String to `fgrep` against the output of `python --version` to validate
# that the correct Python was installed (recommended) [default: none]
# - PYENV_ROOT
# Directory in which to install pyenv [default: ~/.pyenv]
# - PYENV_RELEASE
# Release tag of pyenv to download [default: clone from master]
# - PYTHON_BUILD_CACHE_PATH:
# Directory in which to cache PyPy builds [default: ~/.pyenv_cache]

if [[ -z "$PYENV_VERSION" ]]; then
echo "\$PYENV_VERSION is not set. Not installing a pyenv."
return 0
fi

# Get out of the virtualenv we're in.
deactivate

# Install pyenv
PYENV_ROOT="${PYENV_ROOT:-$HOME/.pyenv}"
if [[ -n "$PYENV_RELEASE" ]]; then
# Fetch the release archive from Github (slightly faster than cloning)
mkdir "$PYENV_ROOT"
curl -fsSL "https://github.com/yyuu/pyenv/archive/$PYENV_RELEASE.tar.gz" \
| tar -xz -C "$PYENV_ROOT" --strip-components 1
else
# Don't have a release to fetch, so just clone directly
git clone --depth 1 https://github.com/yyuu/pyenv.git "$PYENV_ROOT"
fi

export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

# Make sure the cache directory exists
PYTHON_BUILD_CACHE_PATH="${PYTHON_BUILD_CACHE_PATH:-$HOME/.pyenv_cache}"
mkdir -p "$PYTHON_BUILD_CACHE_PATH"

# Install the pyenv
pyenv install "$PYENV_VERSION"
pyenv global "$PYENV_VERSION"

# Make and source a new virtualenv
VIRTUAL_ENV="$HOME/ve-pyenv-$PYENV_PYTHON"
virtualenv -p "$(which python)" "$VIRTUAL_ENV"
source "$VIRTUAL_ENV/bin/activate"

if [[ -n "$PYENV_VERSION_STRING" ]]; then
if ! python --version 2>&1 | fgrep "$PYENV_VERSION_STRING"; then
echo "Failed to verify that the pyenv was properly installed."
return 1
fi
fi
38 changes: 7 additions & 31 deletions setup-pypy.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# DEPRECATED: Please use setup-pyenv.sh rather.
# NOTE: This script needs to be sourced so it can modify the environment.
#
# Environment variables that can be set:
Expand All @@ -10,40 +11,15 @@
# - PYTHON_BUILD_CACHE_PATH:
# Directory in which to cache PyPy builds [default: ~/.pyenv_cache]

echo 'WARNING: setup-pypy.sh is *deprecated*. Please use setup-pyenv.sh rather.'
echo 'setup-pypy.sh will be removed in the next release.'

if [[ -z "$PYPY_VERSION" ]]; then
echo "\$PYPY_VERSION is not set. Not installing PyPy."
return 0
fi

# Get out of the virtualenv we're in.
deactivate

# Install pyenv
PYENV_ROOT="${PYENV_ROOT:-$HOME/.pyenv}"
if [[ -n "$PYENV_RELEASE" ]]; then
# Fetch the release archive from Github (slightly faster than cloning)
mkdir "$PYENV_ROOT"
curl -SL "https://github.com/yyuu/pyenv/archive/$PYENV_RELEASE.tar.gz" | \
tar -xz -C "$PYENV_ROOT" --strip-components 1
else
# Don't have a release to fetch, so just clone directly
git clone --depth 1 https://github.com/yyuu/pyenv.git "$PYENV_ROOT"
fi

export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
export PYENV_VERSION="pypy-$PYPY_VERSION"
export PYENV_VERSION_STRING="PyPy $PYPY_VERSION"

# Make sure the cache directory exists
PYTHON_BUILD_CACHE_PATH="${PYTHON_BUILD_CACHE_PATH:-$HOME/.pyenv_cache}"
mkdir -p "$PYTHON_BUILD_CACHE_PATH"

# Install pypy and make a virtualenv for it.
pyenv install -s pypy-$PYPY_VERSION
pyenv global pypy-$PYPY_VERSION
virtualenv -p $(which python) "$HOME/env-pypy-$PYPY_VERSION"
source "$HOME/env-pypy-$PYPY_VERSION/bin/activate"

if ! python --version 2>&1 | fgrep "PyPy $PYPY_VERSION"; then
echo "Failed to verify that PyPy was properly installed."
return 1
fi
source "$(dirname "$BASH_SOURCE")"/setup-pyenv.sh

0 comments on commit bc19f75

Please sign in to comment.