Skip to content

Commit

Permalink
Fixed docs build and pyright issue
Browse files Browse the repository at this point in the history
  • Loading branch information
wolph committed Feb 25, 2024
1 parent 76fb9b1 commit 3b2fe80
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 65 deletions.
111 changes: 57 additions & 54 deletions progressbar/bar.py
Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
18 changes: 11 additions & 7 deletions progressbar/env.py
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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',
Expand Down
4 changes: 1 addition & 3 deletions progressbar/terminal/os_specific/__init__.py
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Expand Up @@ -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',
Expand Down

0 comments on commit 3b2fe80

Please sign in to comment.