diff --git a/src/pip/_internal/cli/progress_bars.py b/src/pip/_internal/cli/progress_bars.py index f9a68104e34..7ed224790cf 100644 --- a/src/pip/_internal/cli/progress_bars.py +++ b/src/pip/_internal/cli/progress_bars.py @@ -14,7 +14,7 @@ from pip._internal.utils.typing import MYPY_CHECK_RUNNING if MYPY_CHECK_RUNNING: - from typing import Any, Dict, Iterator, List, Tuple + from typing import Any, Dict, List try: from pip._vendor import colorama @@ -124,7 +124,7 @@ def update(self): class BlueEmojiBar(IncrementalBar): - suffix = "{percent:.0f}%" + suffix = "%(percent)d%%" bar_prefix = " " bar_suffix = " " phases = (u"\U0001F539", u"\U0001F537", u"\U0001F535") # type: Any @@ -203,8 +203,8 @@ class BaseDownloadProgressBar(WindowsMixin, InterruptibleMixin, DownloadProgressMixin): file = sys.stdout - message = "{percent:.0f}%" - suffix = "{downloaded} {download_speed} {pretty_eta}" + message = "%(percent)d%%" + suffix = "%(downloaded)s %(download_speed)s %(pretty_eta)s" # NOTE: The "type: ignore" comments on the following classes are there to # work around https://github.com/python/typing/issues/241 @@ -238,7 +238,7 @@ class DownloadProgressSpinner(WindowsMixin, InterruptibleMixin, DownloadProgressMixin, Spinner): file = sys.stdout - suffix = "{downloaded} {download_speed}" + suffix = "%(downloaded)s %(download_speed)s" def next_phase(self): # type: ignore if not hasattr(self, "_phaser"): @@ -247,21 +247,18 @@ def next_phase(self): # type: ignore def update(self): # type: () -> None - vals = dict(self._load_vals( - 'downloaded', 'download_speed', 'pretty_eta', 'percent')) - message = self.message.format(**vals) + message = self.message % self phase = self.next_phase() - suffix = self.suffix.format(**vals) - line = " ".join(filter(None, (message, phase, suffix))) - self.writeln(line) + suffix = self.suffix % self + line = ''.join([ + message, + " " if message else "", + phase, + " " if suffix else "", + suffix, + ]) - def _load_vals(self, *names): - # type: (*str) -> Iterator[Tuple[str, Any]] - for name in names: - try: - yield name, getattr(self, name) - except Exception: - pass + self.writeln(line) BAR_TYPES = {