From ebd9d0adb1d096b5afc968b2c3be879860785f2c Mon Sep 17 00:00:00 2001 From: yeganer Date: Thu, 31 Aug 2017 10:24:56 +0200 Subject: [PATCH 1/6] Add travis caching --- .travis.yml | 175 ++++++++++++++++++++++----------------- travis/before_install.sh | 19 +++++ 2 files changed, 119 insertions(+), 75 deletions(-) create mode 100644 travis/before_install.sh diff --git a/.travis.yml b/.travis.yml index edce95dfdc3..f4098e19605 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,96 +1,121 @@ -os: - - linux -language: python +# We set the language to c because python isn't supported on the MacOS X nodes +# on Travis. However, the language ends up being irrelevant anyway, since we +# install Python ourselves using conda. +language: c -python: - - 2.7 +os: + - linux -virtualenv: - system_site_packages: true +# Setting sudo to false opts in to Travis-CI container-based builds. +sudo: false -cache: - apt: true +# The apt packages below are needed for sphinx builds. A full list of packages +# that can be included can be found here: +# +# https://github.com/travis-ci/apt-package-whitelist/blob/master/ubuntu-precise -sudo: false +addons: + apt: + packages: + -clang env: global: - - COMPILER=gcc - - PANDAS_VERSION=0.16 - - ASTROPY_USE_SYSTEM_PYTEST=1 + + # The following versions are the 'default' for tests, unless + # overridden underneath. They are defined here in order to save having + # to repeat them for all configurations. + - PYTHON_VERSION=2.7 + - NUMPY_VERSION=stable + - ASTROPY_VERSION=stable + - MAIN_CMD='python setup.py' - SETUP_CMD='test' - - TEST_MODE='normal' + - PIP_DEPENDENCIES='' + - EVENT_TYPE='pull_request push' + + + # For this package-template, we include examples of Cython modules, + # so Cython is required for testing. If your package does not include + # Cython code, you can set CONDA_DEPENDENCIES='' + - CONDA_DEPENDENCIES='Cython' + + # List other runtime dependencies for the package that are available as + # pip packages here. + # - PIP_DEPENDENCIES='' + + # Conda packages for affiliated packages are hosted in channel + # "astropy" while builds for astropy LTS with recent numpy versions + # are in astropy-ci-extras. If your package uses either of these, + # add the channels to CONDA_CHANNELS along with any other channels + # you want to use. + - CONDA_CHANNELS='astropy-ci-extras astropy' + + # If there are matplotlib or other GUI tests, uncomment the following + # line to use the X virtual framebuffer. + # - SETUP_XVFB=True + - COMPILER=gcc + - TARDIS_REF_DATA_URL='https://github.com/tardis-sn/tardis-refdata.git' - - MINICONDA_URL='http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh' - - SAVE_COVERAGE=false + - ASTROPY_USE_SYSTEM_PYTEST=1 + - COMPILER=gcc -matrix: - include: - - python: 2.7 - env: - - COMPILER=gcc - - SETUP_CMD='test --coverage --args="--tardis-refdata=$HOME/tardis-refdata/"' - - TEST_MODE='spectrum' - - SAVE_COVERAGE=true - - - python: 2.7 - env: - - COMPILER=clang - - SETUP_CMD='test --args="--tardis-refdata=$HOME/tardis-refdata/"' - - TEST_MODE='spectrum' + matrix: + # Make sure that egg_info works without dependencies + # - PYTHON_VERSION=2.7 SETUP_CMD='egg_info' + # - PYTHON_VERSION=3.4 SETUP_CMD='egg_info' + # - PYTHON_VERSION=3.5 SETUP_CMD='egg_info' + # - PYTHON_VERSION=3.6 SETUP_CMD='egg_info' + - COMPILER=clang - - os: osx - language: generic - env: - - COMPILER=clang - - SETUP_CMD='test --args="--tardis-refdata=$HOME/tardis-refdata/"' - - TEST_MODE='spectrum' - - MINICONDA_URL='http://repo.continuum.io/miniconda/Miniconda2-latest-MacOSX-x86_64.sh' +matrix: + # Don't wait for allowed failures + fast_finish: true - - python: 2.7 + include: + # Try MacOS X + - os: osx env: SETUP_CMD='test' -addons: - apt: - packages: - - clang - - - - -before_install: - # We do this to make sure we get the dependencies so pip works below - - export PYTHONIOENCODING=UTF8 - - wget $MINICONDA_URL -O miniconda.sh - - chmod +x miniconda.sh - - bash miniconda.sh -b -p $HOME/miniconda - - export PATH=$HOME/miniconda/bin:$PATH - - hash -r - - conda update --yes conda - - if [[ $TEST_MODE == 'spectrum' ]]; then conda install -c conda-forge git-lfs=2.2.1 -y; fi - - if [[ $TEST_MODE == 'spectrum' ]]; then git lfs install --skip-smudge; fi - - if [[ $TEST_MODE == 'spectrum' ]]; then git clone $TARDIS_REF_DATA_URL $HOME/tardis-refdata; fi - - if [[ $TEST_MODE == 'spectrum' ]]; then cd $HOME/tardis-refdata; fi - - if [[ $TEST_MODE == 'spectrum' ]]; then git fetch origin pull/3/head:carsus-ref; fi - - if [[ $TEST_MODE == 'spectrum' ]]; then git checkout carsus-ref; fi - - if [[ $TEST_MODE == 'spectrum' ]]; then git lfs pull --include="atom_data/kurucz_cd23_chianti_H_He.h5" origin; fi - - if [[ $TEST_MODE == 'spectrum' ]]; then git lfs pull --include="atom_data/chianti_He.h5" origin; fi - - if [[ $TEST_MODE == 'spectrum' ]]; then git lfs pull --include="plasma_reference/" origin; fi - - if [[ $TEST_MODE == 'spectrum' ]]; then git lfs pull --include="unit_test_data.h5" origin; fi - - if [[ $TEST_MODE == 'spectrum' ]]; then cd $TRAVIS_BUILD_DIR; fi + # Do a coverage test. + - os: linux + env: SETUP_CMD='test --coverage --args="--tardis-refdata=$HOME/tardis-refdata/"' + + - os: linux + env: SETUP_CMD='conda env create -f tardis_env27.yml' install: - - cd $TRAVIS_BUILD_DIR - - conda env create -f tardis_env27.yml - - source activate tardis + + # We now use the ci-helpers package to set up our testing environment. + # This is done by using Miniconda and then using conda and pip to install + # dependencies. Which dependencies are installed using conda and pip is + # determined by the CONDA_DEPENDENCIES and PIP_DEPENDENCIES variables, + # which should be space-delimited lists of package names. See the README + # in https://github.com/astropy/ci-helpers for information about the full + # list of environment variables that can be used to customize your + # environment. In some cases, ci-helpers may not offer enough flexibility + # in how to install a package, in which case you can have additional + # commands in the install: section below. + + - git clone git://github.com/yeganer/ci-helpers.git + - source ci-helpers/travis/setup_conda.sh + - source travis/before_install.sh + + # As described above, using ci-helpers, you should be able to set up an + # environment with dependencies installed using conda and pip, but in some + # cases this may not provide enough flexibility in how to install a + # specific dependency (and it will not be able to install non-Python + # dependencies). Therefore, you can also include commands below (as + # well as at the start of the install section or in the before_install + # section if they are needed before setting up conda) to install any + # other dependencies. script: - - echo CC=$COMPILER python setup.py $SETUP_CMD - - CC=$COMPILER python setup.py $SETUP_CMD + - echo CC=$COMPILER $MAIN_CMD $SETUP_CMD + - CC=$COMPILER $MAIN_CMD $SETUP_CMD after_success: - - if [[ "$SAVE_COVERAGE" = true ]]; then coveralls; fi - -after_failure: - - cat /home/travis/.pip/pip.log + # If coveralls.io is set up for this package, uncomment the line below. + # The coveragerc file may be customized as needed for your package. + # - if [[ $SETUP_CMD == *coverage* ]]; then coveralls --rcfile='packagename/tests/coveragerc'; fi + - if [[ $SETUP_CMD == *coverage* ]]; then coveralls; fi diff --git a/travis/before_install.sh b/travis/before_install.sh new file mode 100644 index 00000000000..bb6b9575c7b --- /dev/null +++ b/travis/before_install.sh @@ -0,0 +1,19 @@ +conda env create -f tardis_env27.yml +source activate tardis +if [[ $SETUP_CMD == *coverage* ]]; then + conda install -c conda-forge git-lfs=2.2.1 -y + git lfs install --skip-smudge + git clone $TARDIS_REF_DATA_URL $HOME/tardis-refdata + cd $HOME/tardis-refdata + + # Checkout PR version, not master + git fetch origin pull/3/head:carsus-ref + git checkout carsus-ref + + # Pull the files + git lfs pull --include="atom_data/kurucz_cd23_chianti_H_He.h5" origin + git lfs pull --include="atom_data/chianti_He.h5" origin + git lfs pull --include="plasma_reference/" origin + git lfs pull --include="unit_test_data.h5" origin + cd $TRAVIS_BUILD_DIR +fi From 516e24169de4fe9f389534895c67f38810fe6994 Mon Sep 17 00:00:00 2001 From: yeganer Date: Thu, 31 Aug 2017 10:42:49 +0200 Subject: [PATCH 2/6] Fix type in apt 'clang' dependency --- .travis.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index f4098e19605..452d5eb3a68 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,8 +16,7 @@ sudo: false addons: apt: - packages: - -clang + packages: clang env: global: @@ -57,7 +56,6 @@ env: - TARDIS_REF_DATA_URL='https://github.com/tardis-sn/tardis-refdata.git' - ASTROPY_USE_SYSTEM_PYTEST=1 - - COMPILER=gcc matrix: # Make sure that egg_info works without dependencies @@ -65,6 +63,7 @@ env: # - PYTHON_VERSION=3.4 SETUP_CMD='egg_info' # - PYTHON_VERSION=3.5 SETUP_CMD='egg_info' # - PYTHON_VERSION=3.6 SETUP_CMD='egg_info' + - COMPILER=gcc - COMPILER=clang matrix: From 4e719e1541241c31a7db9a5bcef1e3ecf79d1ed8 Mon Sep 17 00:00:00 2001 From: yeganer Date: Thu, 31 Aug 2017 11:10:57 +0200 Subject: [PATCH 3/6] Run the full test via build matrix --- .travis.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 452d5eb3a68..03779978696 100644 --- a/.travis.yml +++ b/.travis.yml @@ -58,13 +58,15 @@ env: - ASTROPY_USE_SYSTEM_PYTEST=1 matrix: + - COMPILER=gcc + - COMPILER=clang + - SETUP_CMD='test' + - SETUP_CMD='test --coverage --args="--tardis-refdata=$HOME/tardis-refdata/"' # Make sure that egg_info works without dependencies # - PYTHON_VERSION=2.7 SETUP_CMD='egg_info' # - PYTHON_VERSION=3.4 SETUP_CMD='egg_info' # - PYTHON_VERSION=3.5 SETUP_CMD='egg_info' # - PYTHON_VERSION=3.6 SETUP_CMD='egg_info' - - COMPILER=gcc - - COMPILER=clang matrix: @@ -80,9 +82,6 @@ matrix: - os: linux env: SETUP_CMD='test --coverage --args="--tardis-refdata=$HOME/tardis-refdata/"' - - os: linux - env: SETUP_CMD='conda env create -f tardis_env27.yml' - install: # We now use the ci-helpers package to set up our testing environment. From eac566ad65fe73a92c727312f589cdd954bbb0f9 Mon Sep 17 00:00:00 2001 From: yeganer Date: Thu, 31 Aug 2017 11:15:26 +0200 Subject: [PATCH 4/6] Enable caching --- .travis.yml | 5 +++++ travis/before_install.sh | 9 ++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 03779978696..6e29ebe81e3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,11 @@ addons: apt: packages: clang +cache: + directories: + - $HOME/miniconda + - $HOME/tardis-refdata + env: global: diff --git a/travis/before_install.sh b/travis/before_install.sh index bb6b9575c7b..67c1840ad75 100644 --- a/travis/before_install.sh +++ b/travis/before_install.sh @@ -1,12 +1,15 @@ conda env create -f tardis_env27.yml source activate tardis -if [[ $SETUP_CMD == *coverage* ]]; then + +if [[ $SETUP_CMD == *coverage* ]]; then conda install -c conda-forge git-lfs=2.2.1 -y git lfs install --skip-smudge - git clone $TARDIS_REF_DATA_URL $HOME/tardis-refdata + if [ ! -d "$HOME/tardis-refdata" ]; then + git clone $TARDIS_REF_DATA_URL $HOME/tardis-refdata + fi cd $HOME/tardis-refdata - # Checkout PR version, not master + # Checkout PR version of tardis-refdata, not master git fetch origin pull/3/head:carsus-ref git checkout carsus-ref From 64c30bc427f6f131c15b7bd7d35fa81e2fa94a09 Mon Sep 17 00:00:00 2001 From: yeganer Date: Fri, 8 Sep 2017 08:29:34 +0200 Subject: [PATCH 5/6] Include setup helper scripts in tardis We can't use an external repository because we are hacking the scripts heavily to work with a conda environment file instead of defining the dependencies with environment variables in .travis.yml. --- .travis.yml | 3 +- travis/before_install.sh | 3 -- travis/setup_conda.sh | 62 +++++++++++++++++++++++++++++++++++++ travis/setup_conda_linux.sh | 23 ++++++++++++++ travis/setup_conda_osx.sh | 30 ++++++++++++++++++ 5 files changed, 116 insertions(+), 5 deletions(-) create mode 100755 travis/setup_conda.sh create mode 100755 travis/setup_conda_linux.sh create mode 100755 travis/setup_conda_osx.sh diff --git a/.travis.yml b/.travis.yml index 6e29ebe81e3..d41a2fbd476 100644 --- a/.travis.yml +++ b/.travis.yml @@ -100,8 +100,7 @@ install: # in how to install a package, in which case you can have additional # commands in the install: section below. - - git clone git://github.com/yeganer/ci-helpers.git - - source ci-helpers/travis/setup_conda.sh + - source travis/setup_conda.sh - source travis/before_install.sh # As described above, using ci-helpers, you should be able to set up an diff --git a/travis/before_install.sh b/travis/before_install.sh index 67c1840ad75..0d4d8a5df62 100644 --- a/travis/before_install.sh +++ b/travis/before_install.sh @@ -1,6 +1,3 @@ -conda env create -f tardis_env27.yml -source activate tardis - if [[ $SETUP_CMD == *coverage* ]]; then conda install -c conda-forge git-lfs=2.2.1 -y git lfs install --skip-smudge diff --git a/travis/setup_conda.sh b/travis/setup_conda.sh new file mode 100755 index 00000000000..8c93ccf6f5d --- /dev/null +++ b/travis/setup_conda.sh @@ -0,0 +1,62 @@ +#!/bin/bash + +# Note to the future: keep the conda scripts separate for each OS because many +# packages call ci-helpers with: +# +# source ci-helpers/travis/setup_conda_$TRAVIS_OS_NAME.sh +# +# The present script was added later. + +if [[ $DEBUG == True ]]; then + set -x +fi + +# First check: if the build should be run at all based on the event type + +if [[ ! -z $EVENT_TYPE ]]; then + for event in $EVENT_TYPE; do + if [[ $TRAVIS_EVENT_TYPE = $event ]]; then + allow_to_build=True + fi + done + if [[ $allow_to_build != True ]]; then + travis_terminate 0 + fi +fi + +# Second check: if any of the custom tags are used to skip the build + +TR_SKIP="\[(skip travis|travis skip)\]" +DOCS_ONLY="\[docs only|build docs\]" + +# Travis doesn't provide the commit message of the top of the branch for +# PRs, only the commit message of the merge. Thus this ugly workaround is +# needed for now. + +if [[ $TRAVIS_PULL_REQUEST == false ]]; then + COMMIT_MESSAGE=${TRAVIS_COMMIT_MESSAGE} +else + COMMIT_MESSAGE=$(git show -s $TRAVIS_COMMIT_RANGE | awk 'BEGIN{count=0}{if ($1=="Author:") count++; if (count==1) print $0}') +fi + +# Skip build if the commit message contains [skip travis] or [travis skip] +# Remove workaround once travis has this feature natively +# https://github.com/travis-ci/travis-ci/issues/5032 + +if [[ ! -z $(echo ${COMMIT_MESSAGE} | grep -E "${TR_SKIP}") ]]; then + echo "Travis was requested to be skipped by the commit message, exiting." + travis_terminate 0 +elif [[ ! -z $(echo ${COMMIT_MESSAGE} | grep -E "${DOCS_ONLY}") ]]; then + if [[ $SETUP_CMD != *build_docs* ]] && [[ $SETUP_CMD != *build_sphinx* ]]; then + echo "Only docs build was requested by the commit message, exiting." + travis_terminate 0 + fi +fi + +echo "==================== Starting executing ci-helpers scripts =====================" + +source travis/setup_conda_$TRAVIS_OS_NAME.sh; + +echo "================= Returning executing local .travis.yml script =================" + +set +x diff --git a/travis/setup_conda_linux.sh b/travis/setup_conda_linux.sh new file mode 100755 index 00000000000..fd41caef75b --- /dev/null +++ b/travis/setup_conda_linux.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# Install conda +# http://conda.pydata.org/docs/travis.html#the-travis-yml-file +echo ls -la $HOME/miniconda +ls -la $HOME/miniconda +if [ ! "$(ls -A $HOME/miniconda)" ]; then + echo "Cache is empty, installing miniconda and test environment." + # Control will enter here if $HOME/miniconda is empty. + rm -r $HOME/miniconda + wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh + bash miniconda.sh -b -p $HOME/miniconda + + export PATH="$HOME/miniconda/bin:$PATH" + + hash -r + + conda env create -f tardis_env27.yml +else + export PATH="$HOME/miniconda/bin:$PATH" +fi + +source activate tardis diff --git a/travis/setup_conda_osx.sh b/travis/setup_conda_osx.sh new file mode 100755 index 00000000000..ee88e8cd5c9 --- /dev/null +++ b/travis/setup_conda_osx.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# Workaround for https://github.com/travis-ci/travis-ci/issues/6307, which +# caused the following error on MacOS X workers: +# +# /Users/travis/build.sh: line 109: shell_session_update: command not found +# +rvm get head + +# Install conda +# http://conda.pydata.org/docs/travis.html#the-travis-yml-file +echo ls -la $HOME/miniconda +ls -la $HOME/miniconda +if [ ! "$(ls -A $HOME/miniconda)" ]; then + echo "Cache is empty, installing miniconda and test environment." + # Control will enter here if $HOME/miniconda is empty. + rm -r $HOME/miniconda + # Control will enter here if $HOME/miniconda doesn't exist. + wget https://repo.continuum.io/miniconda/Miniconda3-latest-MacOSX-x86_64.sh -O miniconda.sh + + export PATH="$HOME/miniconda/bin:$PATH" + + hash -r + + conda env create -f tardis_env27.yml +else + export PATH="$HOME/miniconda/bin:$PATH" +fi + +source activate tardis From ce6c76feeacfa2e1386f0af5bd68265f9b8665be Mon Sep 17 00:00:00 2001 From: yeganer Date: Fri, 8 Sep 2017 10:40:14 +0200 Subject: [PATCH 6/6] Test for empty directory, not if it exists --- travis/before_install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/travis/before_install.sh b/travis/before_install.sh index 0d4d8a5df62..5775915e1a2 100644 --- a/travis/before_install.sh +++ b/travis/before_install.sh @@ -1,7 +1,7 @@ if [[ $SETUP_CMD == *coverage* ]]; then conda install -c conda-forge git-lfs=2.2.1 -y git lfs install --skip-smudge - if [ ! -d "$HOME/tardis-refdata" ]; then + if [ ! "$(ls -A $HOME/tardis-refdata)" ]; then git clone $TARDIS_REF_DATA_URL $HOME/tardis-refdata fi cd $HOME/tardis-refdata