From 297a566b46b47a144edd620db5dad0531f65511e Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Tue, 6 Nov 2012 16:24:14 -0500 Subject: [PATCH 01/11] Incorporate @phd's patch. --- flake8/run.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/flake8/run.py b/flake8/run.py index 30944b5..3687251 100644 --- a/flake8/run.py +++ b/flake8/run.py @@ -21,6 +21,8 @@ pep8style = None def check_file(path, complexity=-1): + if pep8style.excluded(path): + return 0 warnings = pyflakes.checkPath(path) warnings += pep8style.input_file(path) if complexity > -1: From a08b0387e558cd7a925091a062a6aed16652264c Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Tue, 6 Nov 2012 17:25:40 -0500 Subject: [PATCH 02/11] Should have included @phd's name in CONTRIBUTORS.txt --- CONTRIBUTORS.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index f41e5d4..dfb59e9 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -14,3 +14,4 @@ Contributors (by order of appearance) : - Miki Tebeka - David Cramer - Peter Teichman +- Oleg Broytman From 5b6b4cd1e485fa9c4c09c075f147a9a289b3c8a9 Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Tue, 6 Nov 2012 17:46:51 -0500 Subject: [PATCH 03/11] Fixes #12. Not important but might as well. --- setup.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 setup.py diff --git a/setup.py b/setup.py old mode 100755 new mode 100644 From d126c3503ee1341cf9e7f84f21fe04c08c915327 Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Wed, 7 Nov 2012 12:20:05 -0500 Subject: [PATCH 04/11] Fixes #20. --- flake8/pyflakes.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/flake8/pyflakes.py b/flake8/pyflakes.py index 4705224..94e57f6 100644 --- a/flake8/pyflakes.py +++ b/flake8/pyflakes.py @@ -336,6 +336,9 @@ class Checker(object): if node.name is not None: if isinstance(node.name, str): name = node.name + elif hasattr(node.name, 'elts'): + names = [e.id for e in node.name.elts] + name = '({0})'.format(', '.join(names)) else: name = node.name.id self.addBinding(node.lineno, Assignment(name, node)) From a4ebc1c5c423cf68b9cd304468af05df05ba061d Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Wed, 7 Nov 2012 12:40:49 -0500 Subject: [PATCH 05/11] Fix #21. ``init`` can also be used elsewhere. Sane defaults are awesome. Also, I hope mercurial uses similar commit messages to git. ;) --- flake8/run.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/flake8/run.py b/flake8/run.py index 3687251..ee77a59 100644 --- a/flake8/run.py +++ b/flake8/run.py @@ -54,9 +54,14 @@ def _get_python_files(paths): yield path -def main(): +def init(parse_argv=False, config_file=True, **kwargs): global pep8style - pep8style = pep8.StyleGuide(parse_argv=True, config_file=True) + pep8style = pep8.StyleGuide(parse_argv=parse_argv, + config_file=config_file) + + +def main(): + init(True) options = pep8style.options complexity = options.max_complexity builtins = set(options.builtins) @@ -138,9 +143,7 @@ def run(command): def git_hook(complexity=-1, strict=False, ignore=None): - global pep8style - pep8style = pep8.StyleGuide(config_file=True) - + init() _initpep8() if ignore: pep8.options.ignore = ignore @@ -203,8 +206,7 @@ else: yield "%s.py" % filename def run(self): - global pep8style - pep8style = pep8.StyleGuide(config_file=True) + init() _initpep8() From 82ea7edadc968b849f3df3bd827f3064e59e672c Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Thu, 8 Nov 2012 09:03:54 -0500 Subject: [PATCH 06/11] Fixes #14 and #19. @BackSeat contributed the patch. Signature changes are mentioned in README. --- README | 5 ++++- flake8/pyflakes.py | 8 ++++---- flake8/run.py | 6 +++--- flake8/util.py | 4 +++- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/README b/README index 064e3fd..6dcfffd 100644 --- a/README +++ b/README @@ -223,8 +223,11 @@ CHANGES ======= 1.6 +--- -XXX +- changed the signatures of the ``check_file`` function in flake8/run.py, + ``skip_warning`` in flake8/util.py and the ``check``, ``checkPath`` + functions in flake8/pyflakes.py. 1.5 - 2012-10-13 diff --git a/flake8/pyflakes.py b/flake8/pyflakes.py index 94e57f6..3d65e7d 100644 --- a/flake8/pyflakes.py +++ b/flake8/pyflakes.py @@ -649,21 +649,21 @@ class Checker(object): self.addBinding(node.lineno, importation) -def checkPath(filename): +def checkPath(filename, ignore=[]): """ Check the given path, printing out any warnings detected. @return: the number of warnings printed """ try: - return check(open(filename, 'U').read() + '\n', filename) + return check(open(filename, 'U').read() + '\n', ignore, filename) except IOError: msg = sys.exc_info()[1] sys.stderr.write("%s: %s\n" % (filename, msg.args[1])) return 1 -def check(codeString, filename='(code)'): +def check(codeString, ignore, filename='(code)'): """ Check the Python source given by C{codeString} for flakes. @@ -714,7 +714,7 @@ def check(codeString, filename='(code)'): valid_warnings = 0 for warning in w.messages: - if skip_warning(warning): + if skip_warning(warning, ignore): continue print(warning) valid_warnings += 1 diff --git a/flake8/run.py b/flake8/run.py index 75fb669..32249e5 100644 --- a/flake8/run.py +++ b/flake8/run.py @@ -20,10 +20,10 @@ from flake8 import mccabe pep8style = None -def check_file(path, complexity=-1): +def check_file(path, ignore=[], complexity=-1): if pep8style.excluded(path): return 0 - warnings = pyflakes.checkPath(path) + warnings = pyflakes.checkPath(path, ignore) warnings += pep8style.input_file(path) if complexity > -1: warnings += mccabe.get_module_complexity(path, complexity) @@ -68,7 +68,7 @@ def main(): if pep8style.paths and options.filename is not None: for path in _get_python_files(pep8style.paths): - warnings += check_file(path, complexity) + warnings += check_file(path, options.ignore, complexity) else: # wait for 1 second on the stdin fd reads, __, __ = select.select([sys.stdin], [], [], 1.) diff --git a/flake8/util.py b/flake8/util.py index bb3f4b6..6e9735b 100644 --- a/flake8/util.py +++ b/flake8/util.py @@ -3,8 +3,10 @@ import re import os -def skip_warning(warning): +def skip_warning(warning, ignore=[]): # XXX quick dirty hack, just need to keep the line in the warning + if warning.message.split()[0] in ignore: + return True if not os.path.isfile(warning.filename): return False From 01471f885d2cf9dc5d0adf04c13e2c583b12b8df Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Thu, 8 Nov 2012 13:44:17 -0500 Subject: [PATCH 07/11] Add lazy option to the git_hook. --- flake8/run.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/flake8/run.py b/flake8/run.py index 32249e5..ab4a033 100644 --- a/flake8/run.py +++ b/flake8/run.py @@ -140,14 +140,18 @@ def run(command): [line.strip() for line in p.stderr.readlines()]) -def git_hook(complexity=-1, strict=False, ignore=None): +def git_hook(complexity=-1, strict=False, ignore=None, lazy=False): _initpep8() if ignore: pep8.options.ignore = ignore warnings = 0 - _, files_modified, _ = run("git diff-index --cached --name-only HEAD") + gitcmd = "git diff-index --cached --name-only HEAD" + if lazy: + gitcmd = gitcmd.replace('--cached ', '') + + _, files_modified, _ = run(gitcmd) for filename in files_modified: ext = os.path.splitext(filename)[-1] if ext != '.py': From 72bd7ee8cf643d4f7bbea696955e4cdc4b82ecf1 Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Thu, 8 Nov 2012 13:45:31 -0500 Subject: [PATCH 08/11] Forgot to document the ``lazy`` param. --- README | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README b/README index 6dcfffd..0d4cf7d 100644 --- a/README +++ b/README @@ -101,6 +101,9 @@ standard output. is emited. If you don't specify it or set it to **-1**, it's just ignored. If specified, it must be a positive value. 12 is usually a good value. +*lazy* when set to ``True`` will also take into account files not added to the +index. + Also, make sure the file is executable and adapt the shebang line so it point to your python interpreter. From 547f71b2439e9d7153f082b6ca1bde9d3eaf185c Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Mon, 12 Nov 2012 10:00:06 -0500 Subject: [PATCH 09/11] Closes #38. Check to see if the file exists before checking to see if it should be skipped. --- flake8/util.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/flake8/util.py b/flake8/util.py index 6e9735b..1cd61b0 100644 --- a/flake8/util.py +++ b/flake8/util.py @@ -29,6 +29,8 @@ def skip_file(path): # flake8: noqa """ + if not os.path.isfile(path): + return False f = open(path) try: content = f.read() From 2484edfbc8517c124eef6752163e3eeb544961d2 Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Wed, 14 Nov 2012 11:59:34 -0500 Subject: [PATCH 10/11] Two problems I didn't see before that are now fixed. First, I never got around to testing my changes to @kilian's patch for #23 and just found that I had mistyped a variable. Also, on more complex code that what I had tested on previously, my patch to pep8 was insufficient. This should work without error now. --- flake8/pep8.py | 6 ++++-- flake8/run.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/flake8/pep8.py b/flake8/pep8.py index 01d512e..da9a112 100644 --- a/flake8/pep8.py +++ b/flake8/pep8.py @@ -482,6 +482,9 @@ def continuation_line_indentation(logical_line, tokens, indent_level, verbose): print(">>> " + tokens[0][4].rstrip()) for token_type, text, start, end, line in tokens: + if line.strip().lower().endswith('# nopep8'): + continue + newline = row < start[0] - first_row if newline: row = start[0] - first_row @@ -1205,8 +1208,7 @@ class Checker(object): self.line_number += 1 if self.line_number > len(self.lines): return '' - line = self.lines[self.line_number - 1] - return '' if line.lower().strip().endswith('# nopep8') else line + return self.lines[self.line_number - 1] def readline_check_physical(self): """ diff --git a/flake8/run.py b/flake8/run.py index f5cb831..f7b5b52 100644 --- a/flake8/run.py +++ b/flake8/run.py @@ -52,7 +52,7 @@ def _get_python_files(paths): yield fullpath else: - if not skip_file(path) or pep8style.excluded(fullpath): + if not skip_file(path) or pep8style.excluded(path): yield path From 13ee10c91433d4d58147b47827e69f8b82e539b9 Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Thu, 15 Nov 2012 14:16:32 -0500 Subject: [PATCH 11/11] =?UTF-8?q?Add=20Marc=20Labb=C3=A9=20to=20the=20CONT?= =?UTF-8?q?RIBUTORS=20file.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit He forgot to add himself and never used his email address. --- CONTRIBUTORS.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index dfb59e9..0c9e151 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -15,3 +15,4 @@ Contributors (by order of appearance) : - David Cramer - Peter Teichman - Oleg Broytman +- Marc Labbé