MCPcopy Create free account
hub / github.com/dropbox/pyannotate / main

Function main

pyannotate_tools/annotations/__main__.py:87–145  ·  view source on GitHub ↗
(args_override=None)

Source from the content-addressed store, hash-verified

85
86
87def main(args_override=None):
88 # type: (Optional[List[str]]) -> None
89
90 # Parse command line.
91 args = parser.parse_args(args_override)
92 if not args.files and not args.dump:
93 parser.error("At least one file/directory is required")
94
95 if args.python_version not in ('2', '3'):
96 sys.exit('--python-version must be 2 or 3')
97
98 annotation_style = 'py' + args.python_version
99
100 # Set up logging handler.
101 level = logging.DEBUG if args.verbose else logging.INFO
102 logging.basicConfig(format='%(message)s', level=level)
103
104 if args.dump:
105 dump_annotations(args.type_info, args.files)
106 return
107
108 if args.auto_any:
109 fixers = ['pyannotate_tools.fixes.fix_annotate']
110 else:
111 # Produce nice error message if type_info.json not found.
112 try:
113 with open(args.type_info) as f:
114 contents = f.read()
115 except IOError as err:
116 sys.exit("Can't open type info file: %s" % err)
117
118 # Run pass 2 with output into a variable.
119 if args.uses_signature:
120 data = json.loads(contents) # type: List[Any]
121 else:
122 data = generate_annotations_json_string(
123 args.type_info,
124 only_simple=args.only_simple)
125
126 # Run pass 3 with input from that variable.
127 FixAnnotateJson.init_stub_json_from_data(data, args.files[0])
128 fixers = ['pyannotate_tools.fixes.fix_annotate_json']
129
130 flags = {'print_function': args.print_function,
131 'annotation_style': annotation_style}
132 rt = ModifiedRefactoringTool(
133 fixers=fixers,
134 options=flags,
135 explicit=fixers,
136 nobackups=True,
137 show_diffs=not args.quiet)
138 if not rt.errors:
139 rt.refactor(args.files, write=args.write, num_processes=args.processes)
140 if args.processes == 1:
141 rt.summarize()
142 else:
143 logging.info("(In multi-process per-file warnings are lost)")
144 if not args.write:

Callers 1

__main__.pyFile · 0.70

Calls 4

dump_annotationsFunction · 0.85

Tested by

no test coverage detected