* [PATCH] codeparser: Add support for correct linenumbers
@ 2016-01-04 17:31 Richard Purdie
0 siblings, 0 replies; only message in thread
From: Richard Purdie @ 2016-01-04 17:31 UTC (permalink / raw)
To: bitbake-devel
Currently, if there is something like a python indentation error in a
python function, the linenumbers and even file aren't reported correctly.
This allows lineno and filename parameters to be passed in to correct this.
The lack of a lineno parameter to python's compile() function is worked
around by using empty linefeeds. Ugly, but effective and with minimal
performance overhead.
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
diff --git a/bitbake/lib/bb/codeparser.py b/bitbake/lib/bb/codeparser.py
index 6c9a42d..577b427 100644
--- a/bitbake/lib/bb/codeparser.py
+++ b/bitbake/lib/bb/codeparser.py
@@ -28,6 +28,10 @@ def check_indent(codestr):
return codestr
if codestr[i-1] == "\t" or codestr[i-1] == " ":
+ if codestr[0] == "\n":
+ # Since we're adding a line, we need to remove one line of any empty padding
+ # to ensure line numbers are correct
+ codestr = codestr[1:]
return "if 1:\n" + codestr
return codestr
@@ -248,7 +252,7 @@ class PythonParser():
self.unhandled_message = "in call of %s, argument '%s' is not a string literal"
self.unhandled_message = "while parsing %s, %s" % (name, self.unhandled_message)
- def parse_python(self, node):
+ def parse_python(self, node, lineno=0, filename="<string>"):
if not node or not node.strip():
return
@@ -270,7 +274,9 @@ class PythonParser():
self.contains[i] = set(codeparsercache.pythoncacheextras[h].contains[i])
return
- code = compile(check_indent(str(node)), "<string>", "exec",
+ # We can't add to the linenumbers for compile, we can pad to the correct number of blank lines though
+ node = "\n" * int(lineno) + node
+ code = compile(check_indent(str(node)), filename, "exec",
ast.PyCF_ONLY_AST)
for n in ast.walk(code):
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2016-01-04 17:31 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-04 17:31 [PATCH] codeparser: Add support for correct linenumbers Richard Purdie
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.