@@ -81,19 +81,19 @@ def _calc_verbosity(*, verbose, quiet):
8181
8282 Parameters
8383 ----------
84- verbose : {0, 1, 2 }
84+ verbose : {0, 1, 3 }
8585 quiet : {0, 1, 2}
8686
8787 Returns
8888 -------
89- verbosity : {-2, -1, 0, 1, 2}
89+ verbosity : {-2, -1, 0, 1, 2, 3 }
9090 """
9191 if verbose and quiet :
9292 raise click .UsageError (
9393 "Options '-v/--verbose' and '-q/--quiet' cannot be used together"
9494 )
9595 verbose -= quiet
96- verbose = min (2 , max (- 2 , verbose )) # Limit to range [-2, 2 ]
96+ verbose = min (3 , max (- 2 , verbose )) # Limit to range [-2, 3 ]
9797 return verbose
9898
9999
@@ -156,24 +156,38 @@ def _collect_type_info(root_path, *, ignore=(), cache=False):
156156 return types , collected_type_prefixes
157157
158158
159- def _format_unknown_names (unknown_names ):
159+ def _format_unknown_names (names ):
160160 """Format unknown type names as a list for printing.
161161
162162 Parameters
163163 ----------
164- unknown_names : Iterable[str]
164+ names : Iterable[str]
165165
166166 Returns
167167 -------
168168 formatted : str
169169 A multiline string.
170+
171+ Examples
172+ --------
173+ >>> names = ["path-like", "values", "arrays", "values"] + ["string"] * 11
174+ >>> print(_format_unknown_names(names))
175+ 11 string
176+ 2 values
177+ 1 arrays
178+ 1 path-like
170179 """
171- lines = [click .style (f"Unknown type names: { len (unknown_names )} " , bold = True )]
172- counter = Counter (unknown_names )
173- sorted_item_counts = sorted (counter .items (), key = lambda x : x [1 ], reverse = True )
174- for item , count in sorted_item_counts :
175- lines .append (f" { item } (x{ count } )" )
176- return "\n " .join (lines )
180+ counter = Counter (names )
181+ sorted_alphabetical = sorted (counter .items (), key = lambda x : x [0 ])
182+ sorted_by_frequency = sorted (sorted_alphabetical , key = lambda x : x [1 ], reverse = True )
183+
184+ lines = []
185+ pad_left = len (str (sorted_by_frequency [0 ][1 ]))
186+ for item , count in sorted_by_frequency :
187+ count_fmt = f"{ count } " .rjust (pad_left )
188+ lines .append (f"{ count_fmt } { item } " )
189+ formatted = "\n " .join (lines )
190+ return formatted
177191
178192
179193@contextmanager
@@ -208,6 +222,34 @@ def cli():
208222 """Generate Python stub files from docstrings."""
209223
210224
225+ def _add_verbosity_options (func ):
226+ """Add verbose and quiet command line options.
227+
228+ Parameters
229+ ----------
230+ func : Callable
231+
232+ Returns
233+ -------
234+ decorated : Callable
235+ """
236+ func = click .option (
237+ "-q" ,
238+ "--quiet" ,
239+ count = True ,
240+ help = "Print less details. Use once to hide warnings. "
241+ "Use -qq to completely silence output." ,
242+ )(func )
243+ func = click .option (
244+ "-v" ,
245+ "--verbose" ,
246+ count = True ,
247+ help = "Print more details. Use once to show information messages. "
248+ "Use -vv to print debug messages." ,
249+ )(func )
250+ return func
251+
252+
211253# Preserve click.command below to keep type checker happy
212254# docstub: off
213255@cli .command ()
@@ -269,20 +311,7 @@ def cli():
269311 is_flag = True ,
270312 help = "Ignore pre-existing cache and don't create a new one." ,
271313)
272- @click .option (
273- "-v" ,
274- "--verbose" ,
275- count = True ,
276- help = "Print more details. Use once to show information messages. "
277- "Use '-vv' to print debug messages." ,
278- )
279- @click .option (
280- "-q" ,
281- "--quiet" ,
282- count = True ,
283- help = "Print less details. Use once to hide warnings. "
284- "Use '-qq' to completely silence output." ,
285- )
314+ @_add_verbosity_options
286315@click .help_option ("-h" , "--help" )
287316@log_execution_time ()
288317def run (
@@ -426,7 +455,11 @@ def run(
426455 if syntax_error_count :
427456 logger .warning ("Syntax errors: %i" , syntax_error_count )
428457 if unknown_type_names :
429- logger .warning (_format_unknown_names (unknown_type_names ))
458+ logger .warning (
459+ "Unknown type names: %i" ,
460+ len (unknown_type_names ),
461+ extra = {"details" : _format_unknown_names (unknown_type_names )},
462+ )
430463 if total_errors :
431464 logger .error ("Total errors: %i" , total_errors )
432465
@@ -440,20 +473,7 @@ def run(
440473# docstub: off
441474@cli .command ()
442475# docstub: on
443- @click .option (
444- "-v" ,
445- "--verbose" ,
446- count = True ,
447- help = "Print more details. Use once to show information messages. "
448- "Use '-vv' to print debug messages." ,
449- )
450- @click .option (
451- "-q" ,
452- "--quiet" ,
453- count = True ,
454- help = "Print less details. Use once to hide warnings. "
455- "Use '-qq' to completely silence output." ,
456- )
476+ @_add_verbosity_options
457477@click .help_option ("-h" , "--help" )
458478def clean (verbose , quiet ):
459479 """Clean the cache.
0 commit comments