Skip to content

Commit

Permalink
Use diff_cover.
Browse files Browse the repository at this point in the history
  • Loading branch information
adiroiban committed Jul 31, 2016
1 parent d76a49a commit b8691bb
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ matrix:
# on starting separate jobs.
- python: 2.7
env: TOXENV=narrativedocs,apidocs,pyflakes,topfile,manifest-checker
# Twistedchecker is running as a separate job so that we can ignore if it
# fails.
- python: 2.7
env: TOXENV=txchecker-travis
#
# OSX 10.10
#
Expand All @@ -44,6 +48,9 @@ matrix:
allow_failures:
# For now, OSX run on Travis-CI has a few failures.
- os: osx
# twistedchecker job was introduce as an experimental job.
# Once it is stable we can enforce it
- env: TOXENV=txchecker-travis


addons:
Expand Down
43 changes: 43 additions & 0 deletions .travis/twistedchecker-trunk-diff.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env sh
#
# Helper for running twistedchecker and reporting only errors that are part
# of the changes since trunk.
#
# Call it as:
# * SCRIPT_NAME twisted
# * SCRIPT_NAME twisted/words/
# * SCRIPT_NAME twisted.words

target=$1

# FIXME: https://github.com/twisted/twistedchecker/issues/116
# Since for unknown modules twistedchecker will return the same error, the
# diff will fail to detect that we are trying to check an invalid path or
# module.
# This is why we check that the argument is a path and if not a path, it is
# an importable module.
if [ ! -d "$target" ]; then
python -c "import $target" 2> /dev/null
if [ $? -ne 0 ]; then
>&2 echo "$target does not exists as a path or as a module."
exit 1
fi
fi

# Make sure we have trunk on the local repo.
git fetch origin trunk:refs/remotes/origin/trunk

mkdir -p build/
twistedchecker -f parseable $target > build/twistedchecker-branch.report

# Make sure repo is producing the diff with prefix so that the output of
# `git diff` can be parsed by diff_cover.
git config diff.noprefix false

diff-quality \
--violations=pylint \
--fail-under=100 \
--compare-branch=origin/trunk build/twistedchecker-branch.report

diff_exit_code=$?
exit $diff_exit_code
10 changes: 9 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
; coverage results to codecov.io. It should be called after running the
; standard coverage environment.
;
; A non-default `txchecker-travis` environment is used to run twistedchecker
; on travis in --diff mode
;
[tox]
skip_missing_interpreters=True
toxworkdir=build/
Expand Down Expand Up @@ -40,8 +43,9 @@ deps =

; Code quality checkers
pyflakes: pyflakes
twistedchecker: twistedchecker
manifest-checker: check-manifest
{twistedchecker,txchecker}: twistedchecker>=0.6.0
txchecker: diff_cover

; Documentation
apidocs: pydoctor
Expand Down Expand Up @@ -87,6 +91,10 @@ commands =
codecov-publish: codecov {env:CODECOV_OPTIONS:}

twistedchecker: twistedchecker {posargs:twisted}

# Run twistedchecker with a diff base on trunk.
txchecker-travis: {toxinidir}/.travis/twistedchecker-trunk-diff.sh {posargs:twisted}

pyflakes: pyflakes {posargs:twisted admin bin}

apidocs: {toxinidir}/bin/admin/build-apidocs {toxinidir} apidocs
Expand Down

0 comments on commit b8691bb

Please sign in to comment.