@@ -132,37 +132,55 @@ def report_execution_time():
132
132
133
133
@click .command ()
134
134
@click .version_option (__version__ )
135
- @click .argument ("root_path" , type = click .Path (exists = True ))
135
+ @click .argument ("root_path" , type = click .Path (exists = True ), metavar = "PACKAGE_PATH" )
136
136
@click .option (
137
137
"-o" ,
138
138
"--out-dir" ,
139
139
type = click .Path (file_okay = False ),
140
+ metavar = "PATH" ,
140
141
help = "Set output directory explicitly." ,
141
142
)
142
143
@click .option (
143
144
"--config" ,
144
145
"config_path" ,
145
146
type = click .Path (exists = True , dir_okay = False ),
147
+ metavar = "PATH" ,
146
148
help = "Set configuration file explicitly." ,
147
149
)
148
150
@click .option (
149
151
"--group-errors" ,
150
152
is_flag = True ,
151
- help = "Group errors by type and content. "
152
- "Will delay showing errors until all files have been processed." ,
153
+ help = "Group identical errors together and list where they occured. "
154
+ "Will delay showing errors until all files have been processed. "
155
+ "Otherwise, simply report errors as the occur." ,
153
156
)
154
- @click .option ("-v" , "--verbose" , count = True , help = "Log more details." )
157
+ @click .option (
158
+ "--allow-errors" ,
159
+ type = click .IntRange (min = 0 ),
160
+ default = 0 ,
161
+ show_default = True ,
162
+ metavar = "INT" ,
163
+ help = "Allow this many or fewer errors. "
164
+ "If docstub reports more, exit with error code '1'." ,
165
+ )
166
+ @click .option ("-v" , "--verbose" , count = True , help = "Print more details (repeatable)." )
155
167
@click .help_option ("-h" , "--help" )
156
168
@report_execution_time ()
157
- def main (root_path , out_dir , config_path , group_errors , verbose ):
158
- """Generate Python stub files from docstrings.
169
+ def main (root_path , out_dir , config_path , group_errors , allow_errors , verbose ):
170
+ """Generate Python stub files with type annotations from docstrings.
171
+
172
+ Given a path `PACKAGE_PATH` to a Python package, generate stub files for it.
173
+ Type descriptions in docstrings will be used to fill in missing inline type
174
+ annotations or to override them.
159
175
\f
160
176
161
177
Parameters
162
178
----------
163
179
source_dir : Path
164
180
out_dir : Path
165
181
config_path : Path
182
+ group_errors : bool
183
+ allow_errors : int
166
184
verbose : str
167
185
"""
168
186
@@ -232,10 +250,18 @@ def main(root_path, out_dir, config_path, group_errors, verbose):
232
250
233
251
unknown_doctypes = types_db .stats ["unknown_doctypes" ]
234
252
if unknown_doctypes :
235
- click .secho (f"{ len (unknown_doctypes )} unknown doctypes: " , fg = "red" )
253
+ click .secho (f"{ len (unknown_doctypes )} unknown doctypes" , fg = "red" )
236
254
counter = Counter (unknown_doctypes )
237
- for item , count in sorted (counter .items (), key = lambda x : x [1 ]):
255
+ sorted_item_counts = sorted (counter .items (), key = lambda x : x [1 ], reverse = True )
256
+ for item , count in sorted_item_counts :
238
257
click .echo (f" { item } (x{ count } )" )
239
258
240
- if unknown_doctypes or syntax_error_count :
259
+ total_errors = len (unknown_doctypes ) + syntax_error_count
260
+ total_msg = f"{ total_errors } total errors"
261
+ if allow_errors :
262
+ total_msg = f"{ total_msg } (allowed { allow_errors } )"
263
+ click .secho (total_msg , bold = True )
264
+
265
+ if allow_errors < total_errors :
266
+ logger .debug ("number of allowed errors %i was exceeded" )
241
267
sys .exit (1 )
0 commit comments