2222# ScanCode is a free software code scanning tool from nexB Inc. and others.
2323# Visit https://github.com/nexB/scancode-toolkit/ for support and download.
2424
25- from __future__ import absolute_import
26- from __future__ import division
27- from __future__ import print_function
28- from __future__ import unicode_literals
29-
30- from collections import OrderedDict
3125import sys
3226
3327import click
3428click .disable_unicode_literals_warning = True
3529from click .utils import echo
3630from click .termui import style
3731from click .types import BoolParamType
38- # FIXME: this is NOT API
32+ # FIXME: this is NOT API
3933from click ._termui_impl import ProgressBar
40- from six import string_types
4134
42- from commoncode import compat
4335from commoncode .fileutils import file_name
4436from commoncode .fileutils import splitext
4537from commoncode .text import toascii
4638
47-
4839# Tracing flags
4940TRACE = False
5041
@@ -60,10 +51,9 @@ def logger_debug(*args):
6051 logger .setLevel (logging .DEBUG )
6152
6253 def logger_debug (* args ):
63- return logger .debug (' ' .join (isinstance (a , string_types )
54+ return logger .debug (' ' .join (isinstance (a , str )
6455 and a or repr (a ) for a in args ))
6556
66-
6757"""
6858Command line UI utilities for improved options, help and progress reporting.
6959"""
@@ -85,15 +75,21 @@ def get_usage(self, ctx):
8575 """
8676 return super (BaseCommand , self ).get_usage (ctx ) + self .short_usage_help
8777
88- def main (self , args = None , prog_name = None , complete_var = None ,
89- standalone_mode = True , ** extra ):
78+ def main (
79+ self , args = None , prog_name = None , complete_var = None ,
80+ standalone_mode = True , ** extra ,
81+ ):
9082 """
9183 Workaround click 4.0 bug https://github.com/mitsuhiko/click/issues/365
9284 """
93- return click .Command .main (self , args = args , prog_name = self .name ,
94- complete_var = complete_var ,
95- standalone_mode = standalone_mode , ** extra )
96-
85+ return click .Command .main (
86+ self ,
87+ args = args ,
88+ prog_name = self .name ,
89+ complete_var = complete_var ,
90+ standalone_mode = standalone_mode ,
91+ ** extra ,
92+ )
9793
9894
9995class GroupedHelpCommand (BaseCommand ):
@@ -105,25 +101,27 @@ class GroupedHelpCommand(BaseCommand):
105101 short_usage_help = '''
106102Try the '--help' option for help on options and arguments.'''
107103
108- def __init__ (self , name , context_settings = None , callback = None , params = None ,
109- help = None , # NOQA
110- epilog = None , short_help = None ,
111- options_metavar = '[OPTIONS]' , add_help_option = True ,
112- plugin_options = ()):
104+ def __init__ (
105+ self , name , context_settings = None , callback = None , params = None ,
106+ help = None , # NOQA
107+ epilog = None , short_help = None ,
108+ options_metavar = '[OPTIONS]' , add_help_option = True ,
109+ plugin_options = (),
110+ ):
113111 """
114112 Create a new GroupedHelpCommand using the `plugin_options` list of
115113 PluggableCommandLineOption instances.
116114 """
117115
118116 super (GroupedHelpCommand , self ).__init__ (
119- name ,
120- context_settings ,
117+ name ,
118+ context_settings ,
121119 callback ,
122- params ,
123- help ,
124- epilog ,
125- short_help ,
126- options_metavar ,
120+ params ,
121+ help ,
122+ epilog ,
123+ short_help ,
124+ options_metavar ,
127125 add_help_option ,
128126 )
129127
@@ -137,7 +135,7 @@ def format_options(self, ctx, formatter):
137135 to MISC_GROUP group.
138136 """
139137 # this mapping defines the CLI help presentation order
140- help_groups = OrderedDict ([
138+ help_groups = dict ([
141139 (SCAN_GROUP , []),
142140 (OTHER_SCAN_GROUP , []),
143141 (SCAN_OPTIONS_GROUP , []),
@@ -220,14 +218,13 @@ def render_finish(self):
220218
221219
222220BAR_WIDTH = 20
223- BAR_SEP = ' '
224- BAR_SEP_LEN = len (BAR_SEP )
221+ BAR_SEP_LEN = len (' ' )
225222
226223
227224def progressmanager (iterable = None , length = None , label = None , show_eta = True ,
228225 show_percent = None , show_pos = True , item_show_func = None ,
229226 fill_char = '#' , empty_char = '-' , bar_template = None ,
230- info_sep = BAR_SEP , width = BAR_WIDTH , file = None , color = None , # NOQA
227+ info_sep = ' ' , width = BAR_WIDTH , file = None , color = None , # NOQA
231228 verbose = False ):
232229
233230 """
@@ -243,7 +240,7 @@ def progressmanager(iterable=None, length=None, label=None, show_eta=True,
243240 progress_class = ProgressLogger
244241 else :
245242 progress_class = EnhancedProgressBar
246- bar_template = ('[%(bar)s]' + BAR_SEP + '%(info)s'
243+ bar_template = ('[%(bar)s]' + ' ' + '%(info)s'
247244 if bar_template is None else bar_template )
248245
249246 return progress_class (iterable = iterable , length = length ,
@@ -292,22 +289,21 @@ def fixed_width_file_name(path, max_length=25):
292289 return '{prefix}{ellipsis}{suffix}{ext}' .format (** locals ())
293290
294291
295- def file_name_max_len (used_width = BAR_WIDTH + BAR_SEP_LEN + 7 + BAR_SEP_LEN + 8 + BAR_SEP_LEN ):
292+ def file_name_max_len (used_width = BAR_WIDTH + 1 + 7 + 1 + 8 + 1 ):
296293 """
297294 Return the max length of a path given the current terminal width.
298295
299296 A progress bar is composed of these elements:
300297 [-----------------------------------#] 1667 Scanned: tu-berlin.yml
301298 - the bar proper which is BAR_WIDTH characters
302- - one BAR_SEP
299+ - one space
303300 - the number of files. We set it to 7 chars, eg. 9 999 999 files
304- - one BAR_SEP
301+ - one space
305302 - the word Scanned: 8 chars
306- - one BAR_SEP
303+ - one space
307304 - the file name proper
308305 The space usage is therefore:
309- BAR_WIDTH + BAR_SEP_LEN + 7 + BAR_SEP_LEN + 8 + BAR_SEP_LEN
310- + the file name length
306+ BAR_WIDTH + 1 + 7 + 1 + 8 + 1 + the file name length
311307 """
312308 term_width , _height = click .get_terminal_size ()
313309 max_filename_length = term_width - used_width
@@ -323,7 +319,7 @@ def path_progress_message(item, verbose=False, prefix='Scanned: '):
323319 return ''
324320 location = item [0 ]
325321 errors = item [2 ]
326- location = compat . unicode ( toascii (location ) )
322+ location = toascii (location )
327323 progress_line = location
328324 if not verbose :
329325 max_file_name_len = file_name_max_len ()
@@ -336,7 +332,6 @@ def path_progress_message(item, verbose=False, prefix='Scanned: '):
336332 return style (prefix ) + style (progress_line , fg = color )
337333
338334
339-
340335# CLI help groups
341336SCAN_GROUP = 'primary scans'
342337SCAN_OPTIONS_GROUP = 'scan options'
@@ -391,11 +386,21 @@ def __init__(
391386 ** kwargs
392387 ):
393388
394- super (PluggableCommandLineOption , self ).__init__ (param_decls , show_default ,
395- prompt , confirmation_prompt ,
396- hide_input , is_flag , flag_value ,
397- multiple , count , allow_from_autoenv ,
398- type , help , ** kwargs )
389+ super (PluggableCommandLineOption , self ).__init__ (
390+ param_decls ,
391+ show_default ,
392+ prompt ,
393+ confirmation_prompt ,
394+ hide_input ,
395+ is_flag ,
396+ flag_value ,
397+ multiple ,
398+ count ,
399+ allow_from_autoenv ,
400+ type ,
401+ help ,
402+ ** kwargs
403+ )
399404
400405 self .help_group = help_group
401406 self .sort_order = sort_order
@@ -410,12 +415,16 @@ def __repr__(self, *args, **kwargs):
410415 required_options = self .required_options
411416 conflicting_options = self .conflicting_options
412417
413- return ('PluggableCommandLineOption<name=%(name)r, '
414- 'required_options=%(required_options)r, conflicting_options=%(conflicting_options)r>' % locals ())
418+ return (
419+ 'PluggableCommandLineOption<name=%(name)r, '
420+ 'required_options=%(required_options)r, '
421+ 'conflicting_options=%(conflicting_options)r>' % locals ()
422+ )
415423
416424 def validate_dependencies (self , ctx , value ):
417425 """
418- Validate `value` against declared `required_options` or `conflicting_options` dependencies.
426+ Validate `value` against declared `required_options` or
427+ `conflicting_options` dependencies.
419428 """
420429 _validate_option_dependencies (ctx , self , value , self .required_options , required = True )
421430 _validate_option_dependencies (ctx , self , value , self .conflicting_options , required = False )
@@ -427,8 +436,8 @@ def get_help_record(self, ctx):
427436
428437def validate_option_dependencies (ctx ):
429438 """
430- Validate all PluggableCommandLineOption dependencies in the `ctx` Click context.
431- Ignore eager flags.
439+ Validate all PluggableCommandLineOption dependencies in the `ctx` Click
440+ context. Ignore eager flags.
432441 """
433442 values = ctx .params
434443 if TRACE :
@@ -449,8 +458,7 @@ def validate_option_dependencies(ctx):
449458 param .validate_dependencies (ctx , value )
450459
451460
452- def _validate_option_dependencies (ctx , param , value ,
453- other_option_names , required = False ):
461+ def _validate_option_dependencies (ctx , param , value , other_option_names , required = False ):
454462 """
455463 Validate the `other_option_names` option dependencies and return a
456464 UsageError if the `param` `value` is set to a not-None non-default value and
0 commit comments