Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 64f43b6

Browse files
committed
Merge branch 'release/4.4.2'
2 parents 7803dd0 + 73e6f7a commit 64f43b6

File tree

3 files changed

+59
-52
lines changed

3 files changed

+59
-52
lines changed

progressbar/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
'''.strip().split(),
2222
)
2323
__email__ = '[email protected]'
24-
__version__ = '4.4.1'
24+
__version__ = '4.4.2'
2525
__license__ = 'BSD'
2626
__copyright__ = 'Copyright 2015 Rick van Hattem (Wolph)'
2727
__url__ = 'https://github.com/WoLpH/python-progressbar'

progressbar/bar.py

Lines changed: 56 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
widgets,
2626
widgets as widgets_module, # Avoid name collision
2727
)
28+
from .terminal import os_specific
2829

2930
logger = logging.getLogger(__name__)
3031

@@ -187,13 +188,13 @@ class DefaultFdMixin(ProgressBarMixinBase):
187188
enable_colors: progressbar.env.ColorSupport = progressbar.env.COLOR_SUPPORT
188189

189190
def __init__(
190-
self,
191-
fd: base.TextIO = sys.stderr,
192-
is_terminal: bool | None = None,
193-
line_breaks: bool | None = None,
194-
enable_colors: progressbar.env.ColorSupport | None = None,
195-
line_offset: int = 0,
196-
**kwargs,
191+
self,
192+
fd: base.TextIO = sys.stderr,
193+
is_terminal: bool | None = None,
194+
line_breaks: bool | None = None,
195+
enable_colors: progressbar.env.ColorSupport | None = None,
196+
line_offset: int = 0,
197+
**kwargs,
197198
):
198199
if fd is sys.stdout:
199200
fd = utils.streams.original_stdout
@@ -210,9 +211,9 @@ def __init__(
210211
super().__init__(**kwargs)
211212

212213
def _apply_line_offset(
213-
self,
214-
fd: base.TextIO,
215-
line_offset: int,
214+
self,
215+
fd: base.TextIO,
216+
line_offset: int,
216217
) -> base.TextIO:
217218
if line_offset:
218219
return progressbar.terminal.stream.LineOffsetStreamWrapper(
@@ -232,8 +233,8 @@ def _determine_line_breaks(self, line_breaks: bool | None) -> bool | None:
232233
return line_breaks
233234

234235
def _determine_enable_colors(
235-
self,
236-
enable_colors: progressbar.env.ColorSupport | None,
236+
self,
237+
enable_colors: progressbar.env.ColorSupport | None,
237238
) -> progressbar.env.ColorSupport:
238239
'''
239240
Determines the color support for the progress bar.
@@ -294,6 +295,10 @@ def _determine_enable_colors(
294295
def print(self, *args: types.Any, **kwargs: types.Any) -> None:
295296
print(*args, file=self.fd, **kwargs)
296297

298+
def start(self, **kwargs):
299+
os_specific.set_console_mode()
300+
super().start()
301+
297302
def update(self, *args: types.Any, **kwargs: types.Any) -> None:
298303
ProgressBarMixinBase.update(self, *args, **kwargs)
299304

@@ -309,10 +314,12 @@ def update(self, *args: types.Any, **kwargs: types.Any) -> None:
309314
self.fd.write(types.cast(str, line.encode('ascii', 'replace')))
310315

311316
def finish(
312-
self,
313-
*args: types.Any,
314-
**kwargs: types.Any,
317+
self,
318+
*args: types.Any,
319+
**kwargs: types.Any,
315320
) -> None: # pragma: no cover
321+
os_specific.reset_console_mode()
322+
316323
if self._finished:
317324
return
318325

@@ -341,8 +348,8 @@ def _format_widgets(self):
341348

342349
for index, widget in enumerate(self.widgets):
343350
if isinstance(
344-
widget,
345-
widgets.WidgetBase,
351+
widget,
352+
widgets.WidgetBase,
346353
) and not widget.check_size(self):
347354
continue
348355
elif isinstance(widget, widgets.AutoWidthWidgetBase):
@@ -420,10 +427,10 @@ class StdRedirectMixin(DefaultFdMixin):
420427
_stderr: base.IO
421428

422429
def __init__(
423-
self,
424-
redirect_stderr: bool = False,
425-
redirect_stdout: bool = False,
426-
**kwargs,
430+
self,
431+
redirect_stderr: bool = False,
432+
redirect_stdout: bool = False,
433+
**kwargs,
427434
):
428435
DefaultFdMixin.__init__(self, **kwargs)
429436
self.redirect_stderr = redirect_stderr
@@ -551,23 +558,23 @@ class ProgressBar(
551558
paused: bool = False
552559

553560
def __init__(
554-
self,
555-
min_value: NumberT = 0,
556-
max_value: NumberT | types.Type[base.UnknownLength] | None = None,
557-
widgets: types.Optional[
558-
types.Sequence[widgets_module.WidgetBase | str]
559-
] = None,
560-
left_justify: bool = True,
561-
initial_value: NumberT = 0,
562-
poll_interval: types.Optional[float] = None,
563-
widget_kwargs: types.Optional[types.Dict[str, types.Any]] = None,
564-
custom_len: types.Callable[[str], int] = utils.len_color,
565-
max_error=True,
566-
prefix=None,
567-
suffix=None,
568-
variables=None,
569-
min_poll_interval=None,
570-
**kwargs,
561+
self,
562+
min_value: NumberT = 0,
563+
max_value: NumberT | types.Type[base.UnknownLength] | None = None,
564+
widgets: types.Optional[
565+
types.Sequence[widgets_module.WidgetBase | str]
566+
] = None,
567+
left_justify: bool = True,
568+
initial_value: NumberT = 0,
569+
poll_interval: types.Optional[float] = None,
570+
widget_kwargs: types.Optional[types.Dict[str, types.Any]] = None,
571+
custom_len: types.Callable[[str], int] = utils.len_color,
572+
max_error=True,
573+
prefix=None,
574+
suffix=None,
575+
variables=None,
576+
min_poll_interval=None,
577+
**kwargs,
571578
): # sourcery skip: low-code-quality
572579
'''Initializes a progress bar with sane defaults.'''
573580
StdRedirectMixin.__init__(self, **kwargs)
@@ -632,8 +639,8 @@ def __init__(
632639
default=None,
633640
)
634641
self._MINIMUM_UPDATE_INTERVAL = (
635-
utils.deltas_to_seconds(self._MINIMUM_UPDATE_INTERVAL)
636-
or self._MINIMUM_UPDATE_INTERVAL
642+
utils.deltas_to_seconds(self._MINIMUM_UPDATE_INTERVAL)
643+
or self._MINIMUM_UPDATE_INTERVAL
637644
)
638645

639646
# Note that the _MINIMUM_UPDATE_INTERVAL sets the minimum in case of
@@ -649,8 +656,8 @@ def __init__(
649656
self.variables = utils.AttributeDict(variables or {})
650657
for widget in self.widgets:
651658
if (
652-
isinstance(widget, widgets_module.VariableMixin)
653-
and widget.name not in self.variables
659+
isinstance(widget, widgets_module.VariableMixin)
660+
and widget.name not in self.variables
654661
):
655662
self.variables[widget.name] = None
656663

@@ -771,7 +778,7 @@ def data(self) -> types.Dict[str, types.Any]:
771778
total_seconds_elapsed=total_seconds_elapsed,
772779
# The seconds since the bar started modulo 60
773780
seconds_elapsed=(elapsed.seconds % 60)
774-
+ (elapsed.microseconds / 1000000.0),
781+
+ (elapsed.microseconds / 1000000.0),
775782
# The minutes since the bar started modulo 60
776783
minutes_elapsed=(elapsed.seconds / 60) % 60,
777784
# The hours since the bar started modulo 24
@@ -901,9 +908,9 @@ def update(self, value=None, force=False, **kwargs):
901908
self.start()
902909

903910
if (
904-
value is not None
905-
and value is not base.UnknownLength
906-
and isinstance(value, (int, float))
911+
value is not None
912+
and value is not base.UnknownLength
913+
and isinstance(value, (int, float))
907914
):
908915
if self.max_value is base.UnknownLength:
909916
# Can't compare against unknown lengths so just update
@@ -1026,9 +1033,9 @@ def _init_prefix(self):
10261033

10271034
def _verify_max_value(self):
10281035
if (
1029-
self.max_value is not base.UnknownLength
1030-
and self.max_value is not None
1031-
and self.max_value < 0 # type: ignore
1036+
self.max_value is not base.UnknownLength
1037+
and self.max_value is not None
1038+
and self.max_value < 0 # type: ignore
10321039
):
10331040
raise ValueError('max_value out of range, got %r' % self.max_value)
10341041

progressbar/env.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ def is_terminal(fd: base.IO, is_terminal: bool | None = None) -> bool | None:
162162

163163
# Enable Windows full color mode if possible
164164
if os.name == 'nt':
165-
from .terminal import os_specific
165+
pass
166166

167-
os_specific.set_console_mode()
167+
# os_specific.set_console_mode()
168168

169169
JUPYTER = bool(
170170
os.environ.get('JUPYTER_COLUMNS')

0 commit comments

Comments
 (0)