Patchwork [2,of,7,v2] import-checker: track SyntaxErrors

login
register
mail settings
Submitter timeless@mozdev.org
Date April 13, 2016, 5:21 p.m.
Message ID <f5294c92fb0fdc4b4954.1460568105@waste.org>
Download mbox | patch
Permalink /patch/14591/
State Accepted
Delegated to: Yuya Nishihara
Headers show

Comments

timeless@mozdev.org - April 13, 2016, 5:21 p.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1460565379 0
#      Wed Apr 13 16:36:19 2016 +0000
# Node ID f5294c92fb0fdc4b4954198dc306bfde4373ac76
# Parent  20a703ce76f7cda378d2ce950b7daa971b508d74
import-checker: track SyntaxErrors

We don't really need to report SyntaxErrors, since in theory
docchecker or a test will catch them, but they happen, and
we can't just have the code crash, so for now, we're reporting
them.
Yuya Nishihara - April 15, 2016, 1:52 p.m.
On Wed, 13 Apr 2016 12:21:45 -0500, timeless wrote:
> # HG changeset patch
> # User timeless <timeless@mozdev.org>
> # Date 1460565379 0
> #      Wed Apr 13 16:36:19 2016 +0000
> # Node ID f5294c92fb0fdc4b4954198dc306bfde4373ac76
> # Parent  20a703ce76f7cda378d2ce950b7daa971b508d74
> import-checker: track SyntaxErrors

> +            except SyntaxError as e:
> +                print('SyntaxError %s:%d: %s' %
> +                      (source_path, e.lineno, e))

I've adjusted the format to '%s:%d: SyntaxError: %s', which is more friendly
for parsers such as emacs' compilation-mode.

Patch

diff --git a/contrib/import-checker.py b/contrib/import-checker.py
--- a/contrib/import-checker.py
+++ b/contrib/import-checker.py
@@ -587,12 +587,17 @@ 
         localmods[modname] = source_path
     for localmodname, source_path in sorted(localmods.items()):
         for src, modname in sources(source_path, localmodname):
-            used_imports[modname] = sorted(
-                imported_modules(src, modname, localmods, ignore_nested=True))
-            for error, lineno in verify_import_convention(modname, src,
-                                                          localmods):
-                any_errors = True
-                print('%s:%d: %s' % (source_path, lineno, error))
+            try:
+                used_imports[modname] = sorted(
+                    imported_modules(src, modname, localmods,
+                                     ignore_nested=True))
+                for error, lineno in verify_import_convention(modname, src,
+                                                              localmods):
+                    any_errors = True
+                    print('%s:%d: %s' % (source_path, lineno, error))
+            except SyntaxError as e:
+                print('SyntaxError %s:%d: %s' %
+                      (source_path, e.lineno, e))
     cycles = find_cycles(used_imports)
     if cycles:
         firstmods = set()