Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(265)

Unified Diff: recipe_engine/third_party/astunparse/__main__.py

Issue 2387763003: Add initial postprocess unit test thingy. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: recipe_engine/third_party/astunparse/__main__.py
diff --git a/recipe_engine/third_party/astunparse/__main__.py b/recipe_engine/third_party/astunparse/__main__.py
new file mode 100644
index 0000000000000000000000000000000000000000..1efec7b467dc964c66aed83ffffcd4ab0f54e1f2
--- /dev/null
+++ b/recipe_engine/third_party/astunparse/__main__.py
@@ -0,0 +1,48 @@
+from __future__ import print_function
+import sys
+import os
+import argparse
+from .unparser import roundtrip
+from . import dump
+
+
+def roundtrip_recursive(target, dump_tree=False):
+ if os.path.isfile(target):
+ print(target)
+ print("=" * len(target))
+ if dump_tree:
+ dump(target)
+ else:
+ roundtrip(target)
+ print()
+ elif os.path.isdir(target):
+ for item in os.listdir(target):
+ if item.endswith(".py"):
+ roundtrip_recursive(os.path.join(target, item), dump_tree)
+ else:
+ print(
+ "WARNING: skipping '%s', not a file or directory" % target,
+ file=sys.stderr
+ )
+
+
+def main(args):
+ parser = argparse.ArgumentParser(prog="astunparse")
+ parser.add_argument(
+ 'target',
+ nargs='+',
+ help="Files or directories to show roundtripped source for"
+ )
+ parser.add_argument(
+ '--dump',
+ type='bool',
+ help="Show a pretty-printed AST instead of the source"
+ )
+
+ arguments = parser.parse_args(args)
+ for target in arguments.target:
+ roundtrip_recursive(target, dump_tree=arguments.dump)
+
+
+if __name__ == "__main__":
+ main(sys.argv[1:])

Powered by Google App Engine
This is Rietveld 408576698