[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Using _python_files() for custom style checks
commit 49bfd123ef9ee2706b797958b8b6b5eea75302d9
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Thu Jan 2 08:56:13 2014 -0800
Using _python_files() for custom style checks
Oops, we pretty much duplicated _python_files() for a bit of our checks.
---
test/util.py | 70 +++++++++++++++++++++++++++-------------------------------
1 file changed, 33 insertions(+), 37 deletions(-)
diff --git a/test/util.py b/test/util.py
index 6f54a91..295f883 100644
--- a/test/util.py
+++ b/test/util.py
@@ -278,43 +278,39 @@ def get_stylistic_issues(paths):
style_checker = pep8.StyleGuide(ignore = CONFIG["pep8.ignore"], reporter = StyleReport)
style_checker.check_files(list(_python_files(paths)))
- for path in paths:
- for file_path in stem.util.system.files_with_suffix(path, '.py'):
- if _is_test_data(file_path):
- continue
-
- with open(file_path) as f:
- file_contents = f.read()
-
- lines, prev_indent = file_contents.split("\n"), 0
- is_block_comment = False
-
- for index, line in enumerate(lines):
- whitespace, content = re.match("^(\s*)(.*)$", line).groups()
-
- # TODO: This does not check that block indentations are two spaces
- # because differentiating source from string blocks ("""foo""") is more
- # of a pita than I want to deal with right now.
-
- if '"""' in content:
- is_block_comment = not is_block_comment
-
- if "\t" in whitespace:
- issues.setdefault(file_path, []).append((index + 1, "indentation has a tab"))
- elif "\r" in content:
- issues.setdefault(file_path, []).append((index + 1, "contains a windows newline"))
- elif content != content.rstrip():
- issues.setdefault(file_path, []).append((index + 1, "line has trailing whitespace"))
- elif content.lstrip().startswith("except") and content.endswith(", exc:"):
- # Python 2.6 - 2.7 supports two forms for exceptions...
- #
- # except ValueError, exc:
- # except ValueError as exc:
- #
- # The former is the old method and no longer supported in python 3
- # going forward.
-
- issues.setdefault(file_path, []).append((index + 1, "except clause should use 'as', not comma"))
+ for path in _python_files(paths):
+ with open(path) as f:
+ file_contents = f.read()
+
+ lines, prev_indent = file_contents.split("\n"), 0
+ is_block_comment = False
+
+ for index, line in enumerate(lines):
+ whitespace, content = re.match("^(\s*)(.*)$", line).groups()
+
+ # TODO: This does not check that block indentations are two spaces
+ # because differentiating source from string blocks ("""foo""") is more
+ # of a pita than I want to deal with right now.
+
+ if '"""' in content:
+ is_block_comment = not is_block_comment
+
+ if "\t" in whitespace:
+ issues.setdefault(path, []).append((index + 1, "indentation has a tab"))
+ elif "\r" in content:
+ issues.setdefault(path, []).append((index + 1, "contains a windows newline"))
+ elif content != content.rstrip():
+ issues.setdefault(path, []).append((index + 1, "line has trailing whitespace"))
+ elif content.lstrip().startswith("except") and content.endswith(", exc:"):
+ # Python 2.6 - 2.7 supports two forms for exceptions...
+ #
+ # except ValueError, exc:
+ # except ValueError as exc:
+ #
+ # The former is the old method and no longer supported in python 3
+ # going forward.
+
+ issues.setdefault(path, []).append((index + 1, "except clause should use 'as', not comma"))
return issues
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits