Set up pyenv to use in Travis CI builds.
Setting up pyenv properly in a Travis CI build environment can be quite tricky. This repo contains a script (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. The Travis CI build images currently contain a very old version of PyPy which breaks some common Python modules.
- Set the
$PYENV_VERSIONenvironment variable to the Python to install. - Tell Travis to cache the
$HOME/.pyenv_cachedirectory. - Download and source the script in
before_install.
There are a few install options that can be set via environment variables:
PYENV_VERSIONThe pyenv to install [required]PYENV_VERSION_STRINGString tofgrepagainst the output ofpython --versionto validate that the correct Python was installed (recommended) [default: none]PYENV_ROOTDirectory in which to install pyenv [default:~/.pyenv]PYENV_RELEASERelease tag of pyenv to download [default: clone from master]PYTHON_BUILD_CACHE_PATHDirectory in which to cache PyPy builds [default:~/.pyenv_cache]
language: python
matrix:
include:
- 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:
- ~/.pyenv_cache
before_install:
- |
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:
- py.test my_project- 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_RELEASEenvironment variable to achieve that. - pyenv fails to install properly if
~/.pyenvis present, even if the directory is empty. So if you cache any directories within~/.pyenvthen you will probably break pyenv.