@@ -50,7 +50,7 @@ def __del__(self):
5050 # Never raise during cleanup. We're too late now
5151 logging .debug (
5252 'Exception raised during ProgressBar cleanup' ,
53- exc_info = True
53+ exc_info = True ,
5454 )
5555
5656 def __getstate__ (self ):
@@ -68,10 +68,12 @@ class DefaultFdMixin(ProgressBarMixinBase):
6868 enable_colors : bool = False
6969
7070 def __init__ (
71- self , fd : types .IO = sys .stderr ,
71+ self ,
72+ fd : types .IO = sys .stderr ,
7273 is_terminal : bool | None = None ,
7374 line_breaks : bool | None = None ,
74- enable_colors : bool | None = None , ** kwargs
75+ enable_colors : bool | None = None ,
76+ ** kwargs ,
7577 ):
7678 if fd is sys .stdout :
7779 fd = utils .streams .original_stdout
@@ -91,17 +93,15 @@ def __init__(
9193 # iteractive terminals) or write line breaks (suitable for log files)
9294 if line_breaks is None :
9395 line_breaks = utils .env_flag (
94- 'PROGRESSBAR_LINE_BREAKS' ,
95- not self .is_terminal
96+ 'PROGRESSBAR_LINE_BREAKS' , not self .is_terminal
9697 )
9798 self .line_breaks = bool (line_breaks )
9899
99100 # Check if ANSI escape characters are enabled (suitable for iteractive
100101 # terminals), or should be stripped off (suitable for log files)
101102 if enable_colors is None :
102103 enable_colors = utils .env_flag (
103- 'PROGRESSBAR_ENABLE_COLORS' ,
104- self .is_ansi_terminal
104+ 'PROGRESSBAR_ENABLE_COLORS' , self .is_ansi_terminal
105105 )
106106
107107 self .enable_colors = bool (enable_colors )
@@ -149,7 +149,6 @@ def _format_line(self):
149149
150150
151151class ResizableMixin (ProgressBarMixinBase ):
152-
153152 def __init__ (self , term_width : int | None = None , ** kwargs ):
154153 ProgressBarMixinBase .__init__ (self , ** kwargs )
155154
@@ -160,6 +159,7 @@ def __init__(self, term_width: int | None = None, **kwargs):
160159 try :
161160 self ._handle_resize ()
162161 import signal
162+
163163 self ._prev_handle = signal .getsignal (signal .SIGWINCH )
164164 signal .signal (signal .SIGWINCH , self ._handle_resize )
165165 self .signal_set = True
@@ -177,6 +177,7 @@ def finish(self): # pragma: no cover
177177 if self .signal_set :
178178 try :
179179 import signal
180+
180181 signal .signal (signal .SIGWINCH , self ._prev_handle )
181182 except Exception : # pragma no cover
182183 pass
@@ -191,8 +192,10 @@ class StdRedirectMixin(DefaultFdMixin):
191192 _stderr : types .IO
192193
193194 def __init__ (
194- self , redirect_stderr : bool = False ,
195- redirect_stdout : bool = False , ** kwargs
195+ self ,
196+ redirect_stderr : bool = False ,
197+ redirect_stdout : bool = False ,
198+ ** kwargs ,
196199 ):
197200 DefaultFdMixin .__init__ (self , ** kwargs )
198201 self .redirect_stderr = redirect_stderr
@@ -327,11 +330,21 @@ class ProgressBar(
327330 _MINIMUM_UPDATE_INTERVAL = 0.050
328331
329332 def __init__ (
330- self , min_value = 0 , max_value = None , widgets = None ,
331- left_justify = True , initial_value = 0 , poll_interval = None ,
332- widget_kwargs = None , custom_len = utils .len_color ,
333- max_error = True , prefix = None , suffix = None , variables = None ,
334- min_poll_interval = None , ** kwargs
333+ self ,
334+ min_value = 0 ,
335+ max_value = None ,
336+ widgets = None ,
337+ left_justify = True ,
338+ initial_value = 0 ,
339+ poll_interval = None ,
340+ widget_kwargs = None ,
341+ custom_len = utils .len_color ,
342+ max_error = True ,
343+ prefix = None ,
344+ suffix = None ,
345+ variables = None ,
346+ min_poll_interval = None ,
347+ ** kwargs ,
335348 ):
336349 '''
337350 Initializes a progress bar with sane defaults
@@ -342,22 +355,23 @@ def __init__(
342355 if not max_value and kwargs .get ('maxval' ) is not None :
343356 warnings .warn (
344357 'The usage of `maxval` is deprecated, please use '
345- '`max_value` instead' , DeprecationWarning
358+ '`max_value` instead' ,
359+ DeprecationWarning ,
346360 )
347361 max_value = kwargs .get ('maxval' )
348362
349363 if not poll_interval and kwargs .get ('poll' ):
350364 warnings .warn (
351365 'The usage of `poll` is deprecated, please use '
352- '`poll_interval` instead' , DeprecationWarning
366+ '`poll_interval` instead' ,
367+ DeprecationWarning ,
353368 )
354369 poll_interval = kwargs .get ('poll' )
355370
356371 if max_value :
357372 if min_value > max_value :
358373 raise ValueError (
359- 'Max value needs to be bigger than the min '
360- 'value'
374+ 'Max value needs to be bigger than the min ' 'value'
361375 )
362376 self .min_value = min_value
363377 self .max_value = max_value
@@ -394,8 +408,7 @@ def __init__(
394408 # (downloading a 1GiB file for example) this adds up.
395409 poll_interval = utils .deltas_to_seconds (poll_interval , default = None )
396410 min_poll_interval = utils .deltas_to_seconds (
397- min_poll_interval ,
398- default = None
411+ min_poll_interval , default = None
399412 )
400413 self ._MINIMUM_UPDATE_INTERVAL = utils .deltas_to_seconds (
401414 self ._MINIMUM_UPDATE_INTERVAL
@@ -412,7 +425,7 @@ def __init__(
412425
413426 # A dictionary of names that can be used by Variable and FormatWidget
414427 self .variables = utils .AttributeDict (variables or {})
415- for widget in ( self .widgets or []) :
428+ for widget in self .widgets or []:
416429 if isinstance (widget , widgets_module .VariableMixin ):
417430 if widget .name not in self .variables :
418431 self .variables [widget .name ] = None
@@ -546,7 +559,7 @@ def data(self):
546559 total_seconds_elapsed = total_seconds_elapsed ,
547560 # The seconds since the bar started modulo 60
548561 seconds_elapsed = (elapsed .seconds % 60 )
549- + (elapsed .microseconds / 1000000. ),
562+ + (elapsed .microseconds / 1000000.0 ),
550563 # The minutes since the bar started modulo 60
551564 minutes_elapsed = (elapsed .seconds / 60 ) % 60 ,
552565 # The hours since the bar started modulo 24
@@ -568,20 +581,27 @@ def default_widgets(self):
568581 if self .max_value :
569582 return [
570583 widgets .Percentage (** self .widget_kwargs ),
571- ' ' , widgets .SimpleProgress (
584+ ' ' ,
585+ widgets .SimpleProgress (
572586 format = '(%s)' % widgets .SimpleProgress .DEFAULT_FORMAT ,
573- ** self .widget_kwargs
587+ ** self .widget_kwargs ,
574588 ),
575- ' ' , widgets .Bar (** self .widget_kwargs ),
576- ' ' , widgets .Timer (** self .widget_kwargs ),
577- ' ' , widgets .AdaptiveETA (** self .widget_kwargs ),
589+ ' ' ,
590+ widgets .Bar (** self .widget_kwargs ),
591+ ' ' ,
592+ widgets .Timer (** self .widget_kwargs ),
593+ ' ' ,
594+ widgets .AdaptiveETA (** self .widget_kwargs ),
578595 ]
579596 else :
580597 return [
581598 widgets .AnimatedMarker (** self .widget_kwargs ),
582- ' ' , widgets .BouncingBar (** self .widget_kwargs ),
583- ' ' , widgets .Counter (** self .widget_kwargs ),
584- ' ' , widgets .Timer (** self .widget_kwargs ),
599+ ' ' ,
600+ widgets .BouncingBar (** self .widget_kwargs ),
601+ ' ' ,
602+ widgets .Counter (** self .widget_kwargs ),
603+ ' ' ,
604+ widgets .Timer (** self .widget_kwargs ),
585605 ]
586606
587607 def __call__ (self , iterable , max_value = None ):
@@ -640,8 +660,9 @@ def _format_widgets(self):
640660 data = self .data ()
641661
642662 for index , widget in enumerate (self .widgets ):
643- if isinstance (widget , widgets .WidgetBase ) \
644- and not widget .check_size (self ):
663+ if isinstance (
664+ widget , widgets .WidgetBase
665+ ) and not widget .check_size (self ):
645666 continue
646667 elif isinstance (widget , widgets .AutoWidthWidgetBase ):
647668 result .append (widget )
@@ -656,7 +677,7 @@ def _format_widgets(self):
656677
657678 count = len (expanding )
658679 while expanding :
659- portion = max (int (math .ceil (width * 1. / count )), 0 )
680+ portion = max (int (math .ceil (width * 1.0 / count )), 0 )
660681 index = expanding .pop ()
661682 widget = result [index ]
662683 count -= 1
@@ -725,8 +746,8 @@ def update(self, value=None, force=False, **kwargs):
725746 for key in kwargs :
726747 if key not in self .variables :
727748 raise TypeError (
728- 'update() got an unexpected keyword ' +
729- 'argument {0!r}' .format (key )
749+ 'update() got an unexpected keyword '
750+ + 'argument {0!r}' .format (key )
730751 )
731752 elif self .variables [key ] != kwargs [key ]:
732753 self .variables [key ] = kwargs [key ]
@@ -782,19 +803,15 @@ def start(self, max_value=None, init=True):
782803
783804 if self .prefix :
784805 self .widgets .insert (
785- 0 , widgets .FormatLabel (
786- self .prefix , new_style = True
787- )
806+ 0 , widgets .FormatLabel (self .prefix , new_style = True )
788807 )
789808 # Unset the prefix variable after applying so an extra start()
790809 # won't keep copying it
791810 self .prefix = None
792811
793812 if self .suffix :
794813 self .widgets .append (
795- widgets .FormatLabel (
796- self .suffix , new_style = True
797- )
814+ widgets .FormatLabel (self .suffix , new_style = True )
798815 )
799816 # Unset the suffix variable after applying so an extra start()
800817 # won't keep copying it
@@ -856,7 +873,8 @@ def currval(self):
856873 '''
857874 warnings .warn (
858875 'The usage of `currval` is deprecated, please use '
859- '`value` instead' , DeprecationWarning
876+ '`value` instead' ,
877+ DeprecationWarning ,
860878 )
861879 return self .value
862880
@@ -871,16 +889,22 @@ def default_widgets(self):
871889 if self .max_value :
872890 return [
873891 widgets .Percentage (),
874- ' of ' , widgets .DataSize ('max_value' ),
875- ' ' , widgets .Bar (),
876- ' ' , widgets .Timer (),
877- ' ' , widgets .AdaptiveETA (),
892+ ' of ' ,
893+ widgets .DataSize ('max_value' ),
894+ ' ' ,
895+ widgets .Bar (),
896+ ' ' ,
897+ widgets .Timer (),
898+ ' ' ,
899+ widgets .AdaptiveETA (),
878900 ]
879901 else :
880902 return [
881903 widgets .AnimatedMarker (),
882- ' ' , widgets .DataSize (),
883- ' ' , widgets .Timer (),
904+ ' ' ,
905+ widgets .DataSize (),
906+ ' ' ,
907+ widgets .Timer (),
884908 ]
885909
886910
0 commit comments