Continuous Integration with Travis CI
A bit of a late-comer to this game, I’ve just discovered the merits of so-called “continuous integration”. In a Journal of Open Source Software (JOSS) review for stripy
, one of the reviewers suggested Travis CI as a way to test if the code is working correctly. I’ve heard of CI before, but the learning curve to actually integrate it within my workflow seemed daunting.
But now I am a convert.
With Travis CI I actually save time. Right now I’ve integrated it into many of my projects and with every commit I make to GitHub it allows me to:
- Benchmark my code against a set of tests with
pytest
(emails are send to me if I break something) - Compile documentation from docstrings commented within my code with
pydoc
- Upload docs to GitHub pages or my own web server
- Package and push tagged releases to PyPI
- Compile and tag Docker images
Sample .travis.yml
script
Here is what a configuration file looks like (taken from the top directory of pycurious
)
dist: bionic
language: python
python:
- "3.5"
- "3.6"
- "3.7"
install:
- pip3 install numpy scipy pytest pdoc
- pip3 install -e .
script:
# test with pytest
pytest tests/
# generate the docs
- mkdir docs
- cd docs
- pdoc --html -o . --force pycurious
- mv pycurious/*.html .
- rm -rf pycurious/
- cd ../
deploy:
provider: pages
skip_cleanup: true
github_token: $GITHUB_TOKEN # Put in settings as a secure variable
keep_history: true
on:
branch: master
verbose: true
local_dir: docs/
- Install required packages with pip.
- Run a suite of tests with
pytest
. - Compile documentation with
pdoc
. - Deploy the documentation on GitHub pages.
- Repeat the same process for Python 3.5, 3.6, and 3.7
So cool!
The only limitation I’ve run into is the lack of parallel support to test MPI environments sigh! But apparently Jenkins is here to help with that. For another time…