repoman: unroll escaped lines so we can check the entirety of it
On Thursday 24 May 2012 00:19:45 Zac Medico wrote:
> On 05/23/2012 09:06 PM, Mike Frysinger wrote: > > Sometimes people wrap long lines in their ebuilds to make it easier to > > read, but this causes us issues when doing line-by-line checking. So > > automatically unroll those lines before passing the full content down > > to our checkers. > > > > This seems to work, but maybe someone can suggest something simpler. > > This code should come right after the line that says "We're not in a > here-document", because we only need it to trigger when we're not in a > here-document. i was thinking this would handle wrapped lines and heredocs together better, but i'll ignore that until i can come up with a concrete case. > I think it's going to be cleaner to detect an escaped newline with a > regular expression, like r'(^|[^])$'. the reason i didn't go the regex route is because this fails with: echo foo \ cow whereas letting python take care of all the escaping works much better -mike |
repoman: unroll escaped lines so we can check the entirety of it
Sometimes people wrap long lines in their ebuilds to make it easier to read, but this causes us issues when doing line-by-line checking. So automatically unroll those lines before passing the full content down to our checkers. Signed-off-by: Mike Frysinger <vapier@gentoo.org> --- v2 - re-order heredoc/multiline checking pym/repoman/checks.py | 60 +++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 48 insertions(+), 12 deletions(-) diff --git a/pym/repoman/checks.py b/pym/repoman/checks.py index c17a0bd..cd8d3d2 100644 --- a/pym/repoman/checks.py +++ b/pym/repoman/checks.py @@ -759,6 +759,7 @@ _ignore_comment_re = re.compile(r'^s*#') def run_checks(contents, pkg): checks = _constant_checks here_doc_delim = None + multiline = None for lc in checks: lc.new(pkg) @@ -772,19 +773,54 @@ def run_checks(contents, pkg): here_doc = _here_doc_re.match(line) if here_doc is not None: here_doc_delim = re.compile(r'^s*%s$' % here_doc.group(1)) + if here_doc_delim is not None: + continue + + # Unroll multiline escaped strings so that we can check things: + # inherit foo bar + # moo + # cow + # This will merge these lines like so: + # inherit foo bar moo cow + try: + # A normal line will end in the two bytes: <> < >. So decoding + # that will result in python thinking the < > is being escaped + # and eat the single <> which makes it hard for us to detect. + # Instead, strip the newline (which we know all lines have), and + # append a <0>. Then when python escapes it, if the line ended + # in a <>, we'll end up with a < |