Merge pull request #1803 from pallets/progress-show
Before adoption: this commit came in with the history the project adopted, so no landing records it.
don't hide fast progress bars
authored by David Lord · committed by GitHub · parents 3018f57, 3cc31b1 · Browse files · 4 files·+24 added−44 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+24 added−44 removed
- tests:+17 added−38 removed
- other:+7 added−6 removed
Provenance
- Commit
af584b2- Tree
a77432e- Author
David Lord <davidism@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
3018f57- Parent 2
3cc31b1
4 files changed+24 added−44 removed
modified:src/click/_termui_impl.py+2 added-6 removed
100 unmodified lines101 self.entered = False102 self.current_item = None103 self.is_hidden = not isatty(self.file)104 self._last_line = None105- self.short_limit = 0.5105 106 def __enter__(self):107 self.entered = True108 self.render_progress()15 unmodified lines124 # so it is re-entry safe. Calling `next(self.generator())`125 # twice works and does "what you want".126 return next(iter(self))127 129- def is_fast(self):130- return time.time() - self.start <= self.short_limit131-128 def render_finish(self):133- if self.is_hidden or self.is_fast():129+ if self.is_hidden:130 return131 self.file.write(AFTER_BAR)132 self.file.flush()133 124 unmodified lines258 buf.append(" " * (clear_width - line_len))259 line = "".join(buf)260 # Render the line only if it changed.261 266- if line != self._last_line and not self.is_fast():262+ if line != self._last_line:263 self._last_line = line264 echo(line, file=self.file, color=self.color, nl=False)265 self.file.flush()266 422 unmodified linesmodified:src/click/termui.py+3 added
389 unmodified lines390 :param update_min_steps: Render only when this many updates have391 completed. This allows tuning for very fast iterators.392 393 .. versionchanged:: 8.0394+ Output is shown even if execution time is less than 0.5 seconds.395+396+ .. versionchanged:: 8.0397 Labels are echoed if the output is not a TTY. Reverts a change398 in 7.0 that removed all output.399 400 .. versionadded:: 8.0348 unmodified linesmodified:tests/test_termui.py+17 added-38 removed
25 unmodified lines26 return progress27 28 29 def test_progressbar_strip_regression(runner, monkeypatch):30- fake_clock = FakeClock()30 label = " padded line"31 32 @click.command()33 def cli():34 with _create_progress(label=label) as progress:35 for _ in progress:37- fake_clock.advance_time()36+ pass37 39- monkeypatch.setattr(time, "time", fake_clock.time)38 monkeypatch.setattr(click._termui_impl, "isatty", lambda _: True)39 assert label in runner.invoke(cli, []).output40 41 15 unmodified lines57 raise StopIteration58 59 next = __next__60 63- fake_clock = FakeClock()64-61 @click.command()62 def cli():63 with click.progressbar(Hinted(10), label="test") as progress:64 for _ in progress:69- fake_clock.advance_time()65+ pass66 71- monkeypatch.setattr(time, "time", fake_clock.time)67 monkeypatch.setattr(click._termui_impl, "isatty", lambda _: True)68 result = runner.invoke(cli, [])69 assert result.exception is None70 71 72 def test_progressbar_hidden(runner, monkeypatch):78- fake_clock = FakeClock()79-73 @click.command()74 def cli():75 with _create_progress(label="working") as progress:76 for _ in progress:84- fake_clock.advance_time()77+ pass78 86- monkeypatch.setattr(time, "time", fake_clock.time)79 monkeypatch.setattr(click._termui_impl, "isatty", lambda _: False)80 assert runner.invoke(cli, []).output == "working\n"81 82 101 unmodified lines184 iter(progress)185 186 187 def test_progressbar_is_iterator(runner, monkeypatch):196- fake_clock = FakeClock()197-188 @click.command()189 def cli():190 with click.progressbar(range(10), label="test") as progress:191 while True:192 try:193 next(progress)204- fake_clock.advance_time()194 except StopIteration:195 break196 208- monkeypatch.setattr(time, "time", fake_clock.time)197 monkeypatch.setattr(click._termui_impl, "isatty", lambda _: True)210-198 result = runner.invoke(cli, [])199 assert result.exception is None200 201 73 unmodified lines275 output = runner.invoke(cli, []).output276 277 lines = [line for line in output.split("\n") if "[" in line]278 292- assert " 25% 00:00:03" in lines[0]293- assert " 50% 00:00:02" in lines[1]294- assert " 75% 00:00:01" in lines[2]295- assert "100% " in lines[3]279+ assert " 0%" in lines[0]280+ assert " 25% 00:00:03" in lines[1]281+ assert " 50% 00:00:02" in lines[2]282+ assert " 75% 00:00:01" in lines[3]283+ assert "100% " in lines[4]284 285 286 def test_progressbar_item_show_func(runner, monkeypatch):299- fake_clock = FakeClock()300-287 @click.command()288 def cli():289 with click.progressbar(304- range(4), item_show_func=lambda x: f"Custom {x}"290+ range(3), item_show_func=lambda x: f"Custom {x}"291 ) as progress:292 for _ in progress:307- fake_clock.advance_time()308- print("")293+ click.echo()294 310- monkeypatch.setattr(time, "time", fake_clock.time)295 monkeypatch.setattr(click._termui_impl, "isatty", lambda _: True)296 output = runner.invoke(cli, []).output297+ lines = [line for line in output.splitlines() if "[" in line]298+ assert "Custom None" in lines[0]299+ assert "Custom 0" in lines[1]300+ assert "Custom 1" in lines[2]301+ assert "Custom 2" in lines[3]302+ assert "Custom None" in lines[4]303 314- lines = [line for line in output.split("\n") if "[" in line]304 316- assert "Custom 0" in lines[0]317- assert "Custom 1" in lines[1]318- assert "Custom 2" in lines[2]319- assert "Custom None" in lines[3]320-321-305 def test_progressbar_update_with_item_show_func(runner, monkeypatch):323- fake_clock = FakeClock()324-306 @click.command()307 def cli():308 with click.progressbar(309 length=6, item_show_func=lambda x: f"Custom {x}"310 ) as progress:311 while not progress.finished:331- fake_clock.advance_time()312 progress.update(2, progress.pos)333- print("")313+ click.echo()314 335- monkeypatch.setattr(time, "time", fake_clock.time)315 monkeypatch.setattr(click._termui_impl, "isatty", lambda _: True)316 output = runner.invoke(cli, []).output317 318 lines = [line for line in output.split("\n") if "[" in line]132 unmodified linesmodified:CHANGES.rst+2 added
174 unmodified lines175 - ``style()`` supports the ``strikethrough`` style. :issue:`805`176 - Multiline marker is removed from short help text. :issue:`1597`177 - Restore progress bar behavior of echoing only the label if the file178 is not a TTY. :issue:`1138`179+- Progress bar output is shown even if execution time is less than 0.5180+ seconds. :issue:`1648`181 182 183 Version 7.1.2184 -------------635 unmodified lines