[hawkmoth] Re: [PATCH 1/8] parser: add parse_to_string to get parse results as string

  • From: Jani Nikula <jani@xxxxxxxxxx>
  • To: Bruno Santos <brunomanuelsantos@xxxxxxxxxxxxxxxxxx>, hawkmoth@xxxxxxxxxxxxx
  • Date: Sun, 16 Dec 2018 20:06:56 +0200

On Sat, 15 Dec 2018, Bruno Santos <brunomanuelsantos@xxxxxxxxxxxxxxxxxx> wrote:

On 12/13/18 10:11 PM, Jani Nikula wrote:
Prep work for converting tests to python unittest.
---
 hawkmoth/hawkmoth.py | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/hawkmoth/hawkmoth.py b/hawkmoth/hawkmoth.py
index 1aa8b6c74f67..aacb957f2981 100755
--- a/hawkmoth/hawkmoth.py
+++ b/hawkmoth/hawkmoth.py
@@ -349,6 +349,15 @@ def parse(filename, **options):
 
     return result
 
+def parse_to_string(filename, verbose, **options):
+    s=""

I know it's nitpicking, but I'd prefer if we aimed for a consistent style. 
Case
in point, string delimiters should be '' instead of "".

Agreed, sloppy of me. Fixed locally.

BR,
Jani.


+    comments = parse(filename, **options)
+    for (comment, meta) in comments:
+        if verbose:
+            s += ('# ' + str(meta) + '\n')
+        s += comment + "\n"

Same.

+    return s
+
 def main():
     parser = argparse.ArgumentParser(description='Hawkmoth.')
     parser.add_argument('file', metavar='FILE', type=str, action='store',
@@ -366,11 +375,9 @@ def main():
 
     filename = args.file
 
-    comments = parse(filename, compat=args.compat, clang=args.clang)
-    for (comment, meta) in comments:
-        if args.verbose:
-            print('# ' + str(meta))
-        print(comment)
+    comments = parse_to_string(filename, args.verbose,
+                               compat=args.compat, clang=args.clang)
+    sys.stdout.write(comments)
 
 if __name__ == '__main__':
     main()


-- 
Bruno Santos

PGP KEY: 941052CD (pool.sks-keyservers.net)

Other related posts: