Continuous Integration With Travis and flake8
2016-07-13
Last Saturday (July 9th) Eli and I met up to review the codebase, and the main issue I identified was that Travis was not set up with flake8 to test the codebase was conforming to the pep8 guidelines.
I’d filed Issue #17 for this, back at the start of the project on May 19.
Yash had started to develop the [.travis.yml](https://github.com/sugarlabs/edit-fonts-activity/blob/gh-pages/.travis.yml)
file to build a .xo bundle but hadn’t complete this just yet, so I commended out most of the code and what remained is very simple:
# this makes travis run a fast Docker container system
sudo: false
# we use python 2.7
language: python
python:
- "2.7"
# we need to install flake8 to use it
before_install:
- "pip install flake8"
# we check the codebase
script:
- "flake8 --statistics --ignore=E402 --exclude=defcon,extractor,fontTools,fontmake,robofab,ufo2ft,ufoLib,snippets ."
You can see there’s a few arguments passed that are pretty simple.
Stastics prints the number of occurences of each error, so you can fix the most common issues across the codebase first.
E402 is about the order of imports, but since we need to import gi to version later imports, we can’t adhere to that rule, so we ignore it.
We also exclude all the third party libraries, and our snippets.
Eli and I worked together on this and I finished it up on Sunday in Pull Request #65
Yash had already set up Travis configuration, at https://travis-ci.org/sugarlabs/edit-fonts-activity, so once this was merged, our button went green:
Finally I added a CONTRIBUTING.md file that explains how to use it.
I’ll get a similar travis set up for the gh-pages branch too.
Perhaps we could also set up a git hook that runs the flake8 command on each commit…