From 6c33d37b55e634db3d1e57af9122ba05b61b3c38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frederik=20=E2=80=9CFreso=E2=80=9D=20S=2E=20Olesen?= Date: Fri, 28 Apr 2017 12:37:23 +0200 Subject: [PATCH 1/4] Run flake8 in Travis CI --- .travis.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0fa5b57..30eed2c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,14 @@ sudo: required language: bash +env: + - FLAKE8=false + - FLAKE8=true + +matrix: + allow_failures: + - env: FLAKE8=true + install: # Dependencies - sudo apt-get -qq update @@ -11,6 +19,7 @@ install: # Testing dependencies - sudo apt-get -qq install python-twisted-core + - sudo pip install flake8 # Build bundled C utils - cd src @@ -21,4 +30,5 @@ install: - sudo python setup.py install script: - - python -m unittest discover + - if [ ! "$FLAKE8" = true ]; then python -m unittest discover; fi + - if [ "$FLAKE8" = true ]; then flake8; fi From 6be899632d57c9d38fb144226627b7c12955cae9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frederik=20=E2=80=9CFreso=E2=80=9D=20S=2E=20Olesen?= Date: Fri, 28 Apr 2017 12:49:17 +0200 Subject: [PATCH 2/4] Fix flake8 whitespace warnings. Guided by the output of `flake8 --select=W`. --- misc/header.py | 6 +++--- misc/show-coverage.py | 14 +++++++------- whipper/common/task.py | 2 -- whipper/program/utils.py | 4 ++-- whipper/test/test_common_mbngs.py | 2 -- whipper/test/test_image_toc.py | 1 - whipper/test/test_program_cdparanoia.py | 1 - 7 files changed, 12 insertions(+), 18 deletions(-) diff --git a/misc/header.py b/misc/header.py index a7322f4..3eb06aa 100644 --- a/misc/header.py +++ b/misc/header.py @@ -4,16 +4,16 @@ # Copyright (C) 2009 Thomas Vander Stichele # This file is part of whipper. -# +# # whipper is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. -# +# # whipper is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with whipper. If not, see . diff --git a/misc/show-coverage.py b/misc/show-coverage.py index 4b562c7..c48bd04 100644 --- a/misc/show-coverage.py +++ b/misc/show-coverage.py @@ -15,14 +15,14 @@ class Presentation: def show(self, maxlen=20): format = '%%-%ds %%3d %%%% (%%4d / %%4d)' % maxlen print format % (self.name, self.percent, self.covered, self.lines) - + class Coverage: def __init__(self): self.files = [] self.total_lines = 0 self.total_covered = 0 - + def _strip_filename(self, filename): filename = os.path.basename(filename) if filename.endswith('.cover'): @@ -44,10 +44,10 @@ class Coverage: for file in self.files: self.show_one(file) print '-' * (self.maxlen + 23) - + p = Presentation('Total', self.total_lines, self.total_covered) p.show(self.maxlen) - + def show_one(self, filename): f = open(filename) lines = [line for line in f.readlines() @@ -61,7 +61,7 @@ class Coverage: return filename = self._strip_filename(filename) - + p = Presentation(filename, len(lines), len(lines) - len(uncovered_lines)) @@ -69,7 +69,7 @@ class Coverage: self.total_lines += p.lines self.total_covered += p.covered - + def main(args): c = Coverage() files = args[1:] @@ -82,6 +82,6 @@ def main(args): c.add_file(file) c.show_results() - + if __name__ == '__main__': sys.exit(main(sys.argv)) diff --git a/whipper/common/task.py b/whipper/common/task.py index e1f4bcf..8312a08 100644 --- a/whipper/common/task.py +++ b/whipper/common/task.py @@ -145,5 +145,3 @@ class PopenTask(task.Task): Called when the command is missing. """ pass - - diff --git a/whipper/program/utils.py b/whipper/program/utils.py index 8acc80a..d5bec2c 100644 --- a/whipper/program/utils.py +++ b/whipper/program/utils.py @@ -18,8 +18,8 @@ def load_device(device): """ logger.debug("loading (eject -t) device %s", device) os.system('eject -t %s' % device) - - + + def unmount_device(device): """ Unmount the given device if it is mounted, as happens with automounted diff --git a/whipper/test/test_common_mbngs.py b/whipper/test/test_common_mbngs.py index 5127c38..fd1959e 100644 --- a/whipper/test/test_common_mbngs.py +++ b/whipper/test/test_common_mbngs.py @@ -114,5 +114,3 @@ class MetadataTestCase(unittest.TestCase): ';ec07a209-55ff-4084-bc41-9d4d1764e075' ';f626b92e-07b1-4a19-ad13-c09d690db66c' ) - - diff --git a/whipper/test/test_image_toc.py b/whipper/test/test_image_toc.py index c2f16ba..0df4109 100644 --- a/whipper/test/test_image_toc.py +++ b/whipper/test/test_image_toc.py @@ -442,4 +442,3 @@ class SurferRosaTestCase(common.TestCase): self.assertEquals(t.getIndex(2).absolute, 111257 + 3370) # print self.toc.table.cue() - diff --git a/whipper/test/test_program_cdparanoia.py b/whipper/test/test_program_cdparanoia.py index 712864f..cb97848 100644 --- a/whipper/test/test_program_cdparanoia.py +++ b/whipper/test/test_program_cdparanoia.py @@ -91,4 +91,3 @@ class CacheTestCase(common.TestCase): t = AnalyzeFileTask(path) self.runner.run(t) self.failUnless(t.defeatsCache) - From 82c990e0308efd1ab2c16fcb4c73fd7ae6922efb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frederik=20=E2=80=9CFreso=E2=80=9D=20S=2E=20Olesen?= Date: Fri, 28 Apr 2017 13:54:38 +0200 Subject: [PATCH 3/4] Use `in` instead of deprecated `.has_key()` method --- whipper/image/image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/whipper/image/image.py b/whipper/image/image.py index 90d5869..b8c1149 100644 --- a/whipper/image/image.py +++ b/whipper/image/image.py @@ -82,7 +82,7 @@ class Image(object): # CD's have a standard lead-in time of 2 seconds; # checksums that use it should add it there - if verify.lengths.has_key(0): + if 0 in verify.lengths: offset = verify.lengths[0] else: offset = self.cue.table.tracks[0].getIndex(1).relative From 99e146333d518309d3804e6cd9b2b607e462dff5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frederik=20=E2=80=9CFreso=E2=80=9D=20S=2E=20Olesen?= Date: Fri, 28 Apr 2017 14:02:16 +0200 Subject: [PATCH 4/4] Add more statistics to flake8 output --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 30eed2c..7827866 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,4 +31,4 @@ install: script: - if [ ! "$FLAKE8" = true ]; then python -m unittest discover; fi - - if [ "$FLAKE8" = true ]; then flake8; fi + - if [ "$FLAKE8" = true ]; then flake8 --benchmark --statistics; fi