From 3b2fe80afeb0fe6b13f163ec7c6c9e81d4ab5a73 Mon Sep 17 00:00:00 2001 From: Rick van Hattem Date: Sun, 25 Feb 2024 08:32:34 +0100 Subject: [PATCH] Fixed docs build and pyright issue --- progressbar/bar.py | 111 ++++++++++--------- progressbar/env.py | 18 +-- progressbar/terminal/os_specific/__init__.py | 4 +- pyproject.toml | 2 +- 4 files changed, 70 insertions(+), 65 deletions(-) diff --git a/progressbar/bar.py b/progressbar/bar.py index 8b859b2..ca46fd3 100644 --- a/progressbar/bar.py +++ b/progressbar/bar.py @@ -187,13 +187,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 @@ -210,9 +210,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( @@ -232,8 +232,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. @@ -309,9 +309,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 if self._finished: return @@ -341,8 +341,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): @@ -388,9 +388,11 @@ def __init__(self, term_width: int | None = None, **kwargs): import signal self._prev_handle = signal.getsignal( - signal.SIGWINCH) # type: ignore - signal.signal(signal.SIGWINCH, # type: ignore - self._handle_resize) + signal.SIGWINCH # type: ignore + ) + signal.signal( + signal.SIGWINCH, self._handle_resize # type: ignore + ) self.signal_set = True def _handle_resize(self, signum=None, frame=None): @@ -404,8 +406,9 @@ def finish(self): # pragma: no cover with contextlib.suppress(Exception): import signal - signal.signal(signal.SIGWINCH, # type: ignore - self._prev_handle) + signal.signal( + signal.SIGWINCH, self._prev_handle # type: ignore + ) class StdRedirectMixin(DefaultFdMixin): @@ -417,10 +420,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 @@ -548,23 +551,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) @@ -629,8 +632,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 @@ -646,8 +649,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 @@ -768,7 +771,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 @@ -898,9 +901,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 @@ -1023,9 +1026,9 @@ 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) diff --git a/progressbar/env.py b/progressbar/env.py index d7990d2..e29f6fb 100644 --- a/progressbar/env.py +++ b/progressbar/env.py @@ -74,8 +74,8 @@ def from_env(cls): from .terminal.os_specific import windows if ( - windows.get_console_mode() - & windows.WindowsConsoleModeFlags.ENABLE_PROCESSED_OUTPUT + windows.get_console_mode() + & windows.WindowsConsoleModeFlags.ENABLE_PROCESSED_OUTPUT ): return cls.XTERM_TRUECOLOR else: @@ -99,8 +99,8 @@ def from_env(cls): def is_ansi_terminal( - fd: base.IO, - is_terminal: bool | None = None, + fd: base.IO, + is_terminal: bool | None = None, ) -> bool | None: # pragma: no cover if is_terminal is None: # Jupyter Notebooks support progress bars @@ -109,7 +109,8 @@ def is_ansi_terminal( # This works for newer versions of pycharm only. With older versions # there is no way to check. elif os.environ.get('PYCHARM_HOSTED') == '1' and not os.environ.get( - 'PYTEST_CURRENT_TEST'): + 'PYTEST_CURRENT_TEST' + ): is_terminal = True if is_terminal is None: @@ -165,8 +166,11 @@ def is_terminal(fd: base.IO, is_terminal: bool | None = None) -> bool | None: os_specific.set_console_mode() -JUPYTER = bool(os.environ.get('JUPYTER_COLUMNS') or os.environ.get( - 'JUPYTER_LINES') or os.environ.get('JPY_PARENT_PID')) +JUPYTER = bool( + os.environ.get('JUPYTER_COLUMNS') + or os.environ.get('JUPYTER_LINES') + or os.environ.get('JPY_PARENT_PID') +) COLOR_SUPPORT = ColorSupport.from_env() ANSI_TERMS = ( '([xe]|bv)term', diff --git a/progressbar/terminal/os_specific/__init__.py b/progressbar/terminal/os_specific/__init__.py index 4fae3c3..833feeb 100644 --- a/progressbar/terminal/os_specific/__init__.py +++ b/progressbar/terminal/os_specific/__init__.py @@ -11,18 +11,16 @@ else: from .posix import getch as _getch - def _reset_console_mode() -> None: pass - def _set_console_mode() -> bool: return False - def _get_console_mode() -> int: return 0 + getch = _getch reset_console_mode = _reset_console_mode set_console_mode = _set_console_mode diff --git a/pyproject.toml b/pyproject.toml index 904e717..6770f0d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -112,7 +112,7 @@ include-package-data = true progressbar = 'progressbar.cli:main' [project.optional-dependencies] -docs = ['sphinx>=1.8.5', 'sphinx-autodoc-typehints>=1.6.0'] +docs = ['sphinx>=1.8.5', 'sphinx-autodoc-typehints>=1.6.0', 'termios'] tests = [ 'dill>=0.3.6', 'flake8>=3.7.7',