From 5d53d59a37247dd9e4663dd86ca79b16cbc92d9b Mon Sep 17 00:00:00 2001 From: Rick van Hattem Date: Tue, 30 Apr 2024 00:53:49 +0200 Subject: [PATCH 1/5] Update README.rst --- README.rst | 8 -------- 1 file changed, 8 deletions(-) diff --git a/README.rst b/README.rst index 4614d19..ec4f7b9 100644 --- a/README.rst +++ b/README.rst @@ -71,14 +71,6 @@ of widgets: The progressbar module is very easy to use, yet very powerful. It will also automatically enable features like auto-resizing when the system supports it. -****************************************************************************** -Security contact information -****************************************************************************** - -To report a security vulnerability, please use the -`Tidelift security contact `_. -Tidelift will coordinate the fix and disclosure. - ****************************************************************************** Known issues ****************************************************************************** From abcba3ace7c2bd088a1e9bc7dd7bf67c75147b6d Mon Sep 17 00:00:00 2001 From: John Dykstra Date: Sat, 1 Jun 2024 16:34:16 -0500 Subject: [PATCH 2/5] Handle OSError exception from format_time() in ETA.__call__() In Windows CPython, format_time() can throw "OSError: [Errno 22] Invalid argument" when passed a very large date. Ignore this in ETA.__call__() with contextlib.suppress(). Fixes #297. --- progressbar/widgets.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/progressbar/widgets.py b/progressbar/widgets.py index e5046b6..fd9408e 100644 --- a/progressbar/widgets.py +++ b/progressbar/widgets.py @@ -547,7 +547,7 @@ def __call__( data['eta'] = None if data['eta_seconds']: - with contextlib.suppress(ValueError, OverflowError): + with contextlib.suppress(ValueError, OverflowError, OSError): data['eta'] = utils.format_time(data['eta_seconds']) if data['value'] == progress.min_value: @@ -560,7 +560,7 @@ def __call__( fmt = self.format_NA else: fmt = self.format_zero - +: return Timer.__call__(self, progress, data, format=fmt) From cd19e8a5c09615852b94e7c16e08b38389967650 Mon Sep 17 00:00:00 2001 From: Rick van Hattem Date: Sun, 18 Aug 2024 03:51:45 +0200 Subject: [PATCH 3/5] Update stale.yml --- .github/workflows/stale.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 7101b3f..5c47a9d 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -11,7 +11,7 @@ jobs: steps: - uses: actions/stale@v8 with: - days-before-stale: 30 + days-before-issue-stale: 30 exempt-issue-labels: in-progress,help-wanted,pinned,security,enhancement - exempt-all-pr-assignees: true + exempt-all-assignees: true From ece74b8709352bab212cee2d52b8027ebe2fe62d Mon Sep 17 00:00:00 2001 From: Rick van Hattem Date: Fri, 23 Aug 2024 01:54:08 +0200 Subject: [PATCH 4/5] several ruff fixes --- examples.py | 2 +- progressbar/bar.py | 100 ++++++++++++++++++------------------- progressbar/utils.py | 2 +- tests/original_examples.py | 2 +- tests/test_utils.py | 2 + tests/test_widgets.py | 2 +- 6 files changed, 56 insertions(+), 54 deletions(-) diff --git a/examples.py b/examples.py index 00e565e..bf265d1 100644 --- a/examples.py +++ b/examples.py @@ -20,7 +20,7 @@ def example(fn): @functools.wraps(fn) def wrapped(*args, **kwargs): try: - sys.stdout.write('Running: %s\n' % fn.__name__) + sys.stdout.write(f'Running: {fn.__name__}\n') fn(*args, **kwargs) sys.stdout.write('\n') except KeyboardInterrupt: diff --git a/progressbar/bar.py b/progressbar/bar.py index 7a048bf..8fe0f5d 100644 --- a/progressbar/bar.py +++ b/progressbar/bar.py @@ -188,13 +188,13 @@ class DefaultFdMixin(ProgressBarMixinBase): enable_colors: progressbar.env.ColorSupport = progressbar.env.COLOR_SUPPORT def __init__( - self, - fd: base.TextIO = sys.stderr, - is_terminal: bool | None = None, - line_breaks: bool | None = None, - enable_colors: progressbar.env.ColorSupport | None = None, - line_offset: int = 0, - **kwargs, + self, + fd: base.TextIO = sys.stderr, + is_terminal: bool | None = None, + line_breaks: bool | None = None, + enable_colors: progressbar.env.ColorSupport | None = None, + line_offset: int = 0, + **kwargs, ): if fd is sys.stdout: fd = utils.streams.original_stdout @@ -211,9 +211,9 @@ def __init__( super().__init__(**kwargs) def _apply_line_offset( - self, - fd: base.TextIO, - line_offset: int, + self, + fd: base.TextIO, + line_offset: int, ) -> base.TextIO: if line_offset: return progressbar.terminal.stream.LineOffsetStreamWrapper( @@ -233,8 +233,8 @@ def _determine_line_breaks(self, line_breaks: bool | None) -> bool | None: return line_breaks def _determine_enable_colors( - self, - enable_colors: progressbar.env.ColorSupport | None, + self, + enable_colors: progressbar.env.ColorSupport | None, ) -> progressbar.env.ColorSupport: ''' Determines the color support for the progress bar. @@ -314,9 +314,9 @@ def update(self, *args: types.Any, **kwargs: types.Any) -> None: self.fd.write(types.cast(str, line.encode('ascii', 'replace'))) def finish( - self, - *args: types.Any, - **kwargs: types.Any, + self, + *args: types.Any, + **kwargs: types.Any, ) -> None: # pragma: no cover os_specific.reset_console_mode() @@ -348,8 +348,8 @@ def _format_widgets(self): for index, widget in enumerate(self.widgets): if isinstance( - widget, - widgets.WidgetBase, + widget, + widgets.WidgetBase, ) and not widget.check_size(self): continue elif isinstance(widget, widgets.AutoWidthWidgetBase): @@ -427,10 +427,10 @@ class StdRedirectMixin(DefaultFdMixin): _stderr: base.IO def __init__( - self, - redirect_stderr: bool = False, - redirect_stdout: bool = False, - **kwargs, + self, + redirect_stderr: bool = False, + redirect_stdout: bool = False, + **kwargs, ): DefaultFdMixin.__init__(self, **kwargs) self.redirect_stderr = redirect_stderr @@ -558,23 +558,23 @@ class ProgressBar( paused: bool = False def __init__( - self, - min_value: NumberT = 0, - max_value: NumberT | types.Type[base.UnknownLength] | None = None, - widgets: types.Optional[ - types.Sequence[widgets_module.WidgetBase | str] - ] = None, - left_justify: bool = True, - initial_value: NumberT = 0, - poll_interval: types.Optional[float] = None, - widget_kwargs: types.Optional[types.Dict[str, types.Any]] = None, - custom_len: types.Callable[[str], int] = utils.len_color, - max_error=True, - prefix=None, - suffix=None, - variables=None, - min_poll_interval=None, - **kwargs, + self, + min_value: NumberT = 0, + max_value: NumberT | types.Type[base.UnknownLength] | None = None, + widgets: types.Optional[ + types.Sequence[widgets_module.WidgetBase | str] + ] = None, + left_justify: bool = True, + initial_value: NumberT = 0, + poll_interval: types.Optional[float] = None, + widget_kwargs: types.Optional[types.Dict[str, types.Any]] = None, + custom_len: types.Callable[[str], int] = utils.len_color, + max_error=True, + prefix=None, + suffix=None, + variables=None, + min_poll_interval=None, + **kwargs, ): # sourcery skip: low-code-quality '''Initializes a progress bar with sane defaults.''' StdRedirectMixin.__init__(self, **kwargs) @@ -639,8 +639,8 @@ def __init__( default=None, ) self._MINIMUM_UPDATE_INTERVAL = ( - utils.deltas_to_seconds(self._MINIMUM_UPDATE_INTERVAL) - or self._MINIMUM_UPDATE_INTERVAL + utils.deltas_to_seconds(self._MINIMUM_UPDATE_INTERVAL) + or self._MINIMUM_UPDATE_INTERVAL ) # Note that the _MINIMUM_UPDATE_INTERVAL sets the minimum in case of @@ -656,8 +656,8 @@ def __init__( self.variables = utils.AttributeDict(variables or {}) for widget in self.widgets: if ( - isinstance(widget, widgets_module.VariableMixin) - and widget.name not in self.variables + isinstance(widget, widgets_module.VariableMixin) + and widget.name not in self.variables ): self.variables[widget.name] = None @@ -778,7 +778,7 @@ def data(self) -> types.Dict[str, types.Any]: total_seconds_elapsed=total_seconds_elapsed, # The seconds since the bar started modulo 60 seconds_elapsed=(elapsed.seconds % 60) - + (elapsed.microseconds / 1000000.0), + + (elapsed.microseconds / 1000000.0), # The minutes since the bar started modulo 60 minutes_elapsed=(elapsed.seconds / 60) % 60, # The hours since the bar started modulo 24 @@ -908,9 +908,9 @@ def update(self, value=None, force=False, **kwargs): self.start() if ( - value is not None - and value is not base.UnknownLength - and isinstance(value, (int, float)) + value is not None + and value is not base.UnknownLength + and isinstance(value, (int, float)) ): if self.max_value is base.UnknownLength: # Can't compare against unknown lengths so just update @@ -1033,11 +1033,11 @@ def _init_prefix(self): def _verify_max_value(self): if ( - self.max_value is not base.UnknownLength - and self.max_value is not None - and self.max_value < 0 # type: ignore + self.max_value is not base.UnknownLength + and self.max_value is not None + and self.max_value < 0 # type: ignore ): - raise ValueError('max_value out of range, got %r' % self.max_value) + raise ValueError(f'max_value out of range, got {self.max_value!r}') def _calculate_poll_interval(self) -> None: self.num_intervals = max(100, self.term_width) diff --git a/progressbar/utils.py b/progressbar/utils.py index 46d0cb2..9b167a8 100644 --- a/progressbar/utils.py +++ b/progressbar/utils.py @@ -97,7 +97,7 @@ def no_color(value: StringT) -> StringT: elif isinstance(value, str): return re.sub('\x1b\\[.*?[@-~]', '', value) # type: ignore else: - raise TypeError('`value` must be a string or bytes, got %r' % value) + raise TypeError(f'`value` must be a string or bytes, got {value!r}') def len_color(value: types.StringTypes) -> int: diff --git a/tests/original_examples.py b/tests/original_examples.py index 7f745d0..b9ba57e 100644 --- a/tests/original_examples.py +++ b/tests/original_examples.py @@ -32,7 +32,7 @@ def example(fn): def wrapped(): try: - sys.stdout.write('Running: %s\n' % name) + sys.stdout.write(f'Running: {name}\n') fn() sys.stdout.write('\n') except KeyboardInterrupt: diff --git a/tests/test_utils.py b/tests/test_utils.py index 8003204..47ab093 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -15,11 +15,13 @@ ('t', True), ('yes', True), ('true', True), + ('True', True), ('0', False), ('n', False), ('f', False), ('no', False), ('false', False), + ('False', False), ], ) def test_env_flag(value, expected, monkeypatch): diff --git a/tests/test_widgets.py b/tests/test_widgets.py index 9872f0b..fc1eeca 100644 --- a/tests/test_widgets.py +++ b/tests/test_widgets.py @@ -58,7 +58,7 @@ def test_widgets_large_values(max_value): def test_format_widget(): widgets = [ - progressbar.FormatLabel('%%(%s)r' % mapping) + progressbar.FormatLabel(f'%({mapping})r') for mapping in progressbar.FormatLabel.mapping ] p = progressbar.ProgressBar(widgets=widgets) From 604342dab49b1fdb9373d2485bc449122196e14d Mon Sep 17 00:00:00 2001 From: Rick van Hattem Date: Fri, 23 Aug 2024 02:35:16 +0200 Subject: [PATCH 5/5] Incrementing version to v4.4.3 --- progressbar/__about__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/progressbar/__about__.py b/progressbar/__about__.py index 914b679..d374388 100644 --- a/progressbar/__about__.py +++ b/progressbar/__about__.py @@ -21,7 +21,7 @@ '''.strip().split(), ) __email__ = 'wolph@wol.ph' -__version__ = '4.4.2' +__version__ = '4.4.3' __license__ = 'BSD' __copyright__ = 'Copyright 2015 Rick van Hattem (Wolph)' __url__ = 'https://github.com/WoLpH/python-progressbar'