MCPcopy Index your code
hub / github.com/RustPython/RustPython / main

Function main

Lib/ast.py:627–677  ·  view source on GitHub ↗
(args=None)

Source from the content-addressed store, hash-verified

625
626
627def main(args=None):
628 import argparse
629 import sys
630
631 parser = argparse.ArgumentParser(color=True)
632 parser.add_argument('infile', nargs='?', default='-',
633 help='the file to parse; defaults to stdin')
634 parser.add_argument('-m', '--mode', default='exec',
635 choices=('exec', 'single', 'eval', 'func_type'),
636 help='specify what kind of code must be parsed')
637 parser.add_argument('--no-type-comments', default=True, action='store_false',
638 help="don't add information about type comments")
639 parser.add_argument('-a', '--include-attributes', action='store_true',
640 help='include attributes such as line numbers and '
641 'column offsets')
642 parser.add_argument('-i', '--indent', type=int, default=3,
643 help='indentation of nodes (number of spaces)')
644 parser.add_argument('--feature-version',
645 type=str, default=None, metavar='VERSION',
646 help='Python version in the format 3.x '
647 '(for example, 3.10)')
648 parser.add_argument('-O', '--optimize',
649 type=int, default=-1, metavar='LEVEL',
650 help='optimization level for parser (default -1)')
651 parser.add_argument('--show-empty', default=False, action='store_true',
652 help='show empty lists and fields in dump output')
653 args = parser.parse_args(args)
654
655 if args.infile == '-':
656 name = '<stdin>'
657 source = sys.stdin.buffer.read()
658 else:
659 name = args.infile
660 with open(args.infile, 'rb') as infile:
661 source = infile.read()
662
663 # Process feature_version
664 feature_version = None
665 if args.feature_version:
666 try:
667 major, minor = map(int, args.feature_version.split('.', 1))
668 except ValueError:
669 parser.error('Invalid format for --feature-version; '
670 'expected format 3.x (for example, 3.10)')
671
672 feature_version = (major, minor)
673
674 tree = parse(source, name, args.mode, type_comments=args.no_type_comments,
675 feature_version=feature_version, optimize=args.optimize)
676 print(dump(tree, include_attributes=args.include_attributes,
677 indent=args.indent, show_empty=args.show_empty))
678
679if __name__ == '__main__':
680 main()

Callers 1

ast.pyFile · 0.70

Calls 9

parse_argsMethod · 0.95
errorMethod · 0.95
openFunction · 0.70
parseFunction · 0.70
dumpFunction · 0.70
printFunction · 0.50
add_argumentMethod · 0.45
readMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected