Skip to content

Commit

Permalink
Fix setting of Python version in .travis.yml
Browse files Browse the repository at this point in the history
The environment variable TRAVIS_PYTHON_VERSION does not get set until
after the environment variable section has already run, so the previous
version just set _PYTHON_VERSION to an empty variable.  This then caused
conda to install the current version of Python, rather than the
targetting version.

We set _PYTHON_VERSION in an `if` test so that the Mac versions can be
neatly overridden in the environment setup with explicit values.  We
have to use the
    [[ -z "$_PYTHON_VERSION" ]]
test syntax rather than the more modern and robust
    [[ ! -v _PYTHON_VERSION ]]
because the Travis macOS machines only have bash 3.2 (released 2006) and
the latter syntax is in bash 4.2 (released 2011).  Thanks, Apple!
  • Loading branch information
jakelishman committed Nov 14, 2020
1 parent c719cbe commit 66685e9
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ os: linux
dist: xenial
language: python

# We use our own "_PYTHON_VERSION" variable because Travis jobs on macOS don't
# have a "language: python" available, so don't define the variable.
env: _CONDA_SUFFIX="Linux-x86_64" _PYTHON_VERSION="$TRAVIS_PYTHON_VERSION"
# This is overriden by the Mac versions, which also directly set
# _PYTHON_VERSION. We cannot set _PYTHON_VERSION to TRAVIS_PYTHON_VERSION here
# because the latter is not defined until after this environment setup takes
# place.
env: _CONDA_SUFFIX="Linux-x86_64"

# Set up conda with the correct version of conda.
before_install:
Expand All @@ -19,6 +21,10 @@ before_install:
- hash -r
- conda config --set always_yes yes --set changeps1 no
- conda info -a
# We have to use the older [[ -z "$x" ]] syntax rather than the more robust
# [[ ! -v _PYTHON_VERSION ]]
# because the macOS machines on Travis only have bash 3.2 (released 2006)!
- if [[ -z "$_PYTHON_VERSION" ]]; then export _PYTHON_VERSION="$TRAVIS_PYTHON_VERSION"; fi
- conda create -q -n test-environment python="$_PYTHON_VERSION"
- source activate test-environment
- QUTIP_DOWNLOAD=$(pwd -P)
Expand Down

0 comments on commit 66685e9

Please sign in to comment.