Skip to content

Commit

Permalink
Travis CI: Add flake8 tests to find syntax errors and undefined names (
Browse files Browse the repository at this point in the history
…Trusted-AI#29)

* Travis CI: Add flake8 tests to find syntax errors and undefined names

Another attempt at Trusted-AI#15 which also tries to consolidate repetitive parts of the __.travis.yml__ file.

Add [flake8](http://flake8.pycqa.org) tests to find Python syntax errors and undefined names.

__E901,E999,F821,F822,F823__ are the "_showstopper_" flake8 issues that can halt the runtime with a SyntaxError, NameError, etc. Most other flake8 issues are merely "style violations" -- useful for readability but they do not effect runtime safety.
* F821: undefined name `name`
* F822: undefined name `name` in `__all__`
* F823: local variable name referenced before assignment
* E901: SyntaxError or IndentationError
* E999: SyntaxError -- failed to compile a file into an Abstract Syntax Tree

* Undefined Name -- Typo: typeError --> typeError

* Move non-vital flake8 run to Python3 before_script

This run is merely about "style violations" that do not adversely effect Python runtime behavior.  Putting it in the __before_script_ keeps the output under a twisty.  We get quite similar results when running the style tests under Py2 and Py3 so just run them once.

* env: MLDB_URL="ftp://ftp.ics.uci.edu/pub/machine-learning-databases"

* Reinsert branches: only: - master
  • Loading branch information
cclauss authored and hoffmansc committed Sep 26, 2018
1 parent ff3b11f commit ea07e11
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 30 deletions.
51 changes: 22 additions & 29 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,36 @@
dist: trusty
sudo: false

language: python
python:
- "2.7"
- "3.6"

install: pip install -r requirements.txt
env: MLDB_URL="ftp://ftp.ics.uci.edu/pub/machine-learning-databases"

branches:
only:
- master

install:
- pip install -r requirements.txt
- pip install flake8
- wget ${MLDB_URL}/adult/adult.data -P aif360/data/raw/adult/
- wget ${MLDB_URL}/adult/adult.test -P aif360/data/raw/adult/
- wget ${MLDB_URL}/adult/adult.names -P aif360/data/raw/adult/
- wget ${MLDB_URL}/statlog/german/german.data -P aif360/data/raw/german/
- wget ${MLDB_URL}/statlog/german/german.doc -P aif360/data/raw/german/
- wget https://raw.githubusercontent.com/propublica/compas-analysis/master/compas-scores-two-years.csv -P aif360/data/raw/compas/

matrix:
# different requirements for different python versions
# Python 2.7 has a special requirement for BlackBoxAuditing
include:
- python: "2.7"
before_script:
- wget ftp://ftp.ics.uci.edu/pub/machine-learning-databases/adult/adult.data -P aif360/data/raw/adult/
- wget ftp://ftp.ics.uci.edu/pub/machine-learning-databases/adult/adult.test -P aif360/data/raw/adult/
- wget ftp://ftp.ics.uci.edu/pub/machine-learning-databases/adult/adult.names -P aif360/data/raw/adult/
- wget ftp://ftp.ics.uci.edu/pub/machine-learning-databases/statlog/german/german.data -P aif360/data/raw/german/
- wget ftp://ftp.ics.uci.edu/pub/machine-learning-databases/statlog/german/german.doc -P aif360/data/raw/german/
- wget https://raw.githubusercontent.com/propublica/compas-analysis/master/compas-scores-two-years.csv -P aif360/data/raw/compas/
- git clone https://github.com/algofairness/BlackBoxAuditing.git /tmp/BlackBoxAuditing/
- echo -n /tmp/BlackBoxAuditing/BlackBoxAuditing/weka.jar > /tmp/BlackBoxAuditing/python2_source/BlackBoxAuditing/model_factories/weka.path
- echo include python2_source/BlackBoxAuditing/model_factories/weka.path >> /tmp/BlackBoxAuditing/MANIFEST.in
- pip install --no-deps /tmp/BlackBoxAuditing/
# workaround to exclude extraneous builds
- python: "3.6"
before_script:
- wget ftp://ftp.ics.uci.edu/pub/machine-learning-databases/adult/adult.data -P aif360/data/raw/adult/
- wget ftp://ftp.ics.uci.edu/pub/machine-learning-databases/adult/adult.test -P aif360/data/raw/adult/
- wget ftp://ftp.ics.uci.edu/pub/machine-learning-databases/adult/adult.names -P aif360/data/raw/adult/
- wget ftp://ftp.ics.uci.edu/pub/machine-learning-databases/statlog/german/german.data -P aif360/data/raw/german/
- wget ftp://ftp.ics.uci.edu/pub/machine-learning-databases/statlog/german/german.doc -P aif360/data/raw/german/
- wget https://raw.githubusercontent.com/propublica/compas-analysis/master/compas-scores-two-years.csv -P aif360/data/raw/compas/
exclude:
- python: "2.7"
- python: "3.6"

branches:
only:
- master
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
- flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics

script: travis_wait pytest tests
script:
# stop the build if there are Python syntax errors or undefined names
- flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics
- travis_wait pytest tests
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def init_coef(self, itype, X, y, s):
clr.fit(X[s == i, :], y[s == i])
coef[i, :] = clr.coef_
else:
raise typeError
raise TypeError

def fit(self, X, y, ns=N_S, itype=0, **kwargs):
""" train this model
Expand Down

0 comments on commit ea07e11

Please sign in to comment.