Skip to content

Disabled Progress should not start attached Live#1125

Merged
willmcgugan merged 4 commits intoTextualize:masterfrom
JoshKarpel:really-disable-pbar
Mar 26, 2021
Merged

Disabled Progress should not start attached Live#1125
willmcgugan merged 4 commits intoTextualize:masterfrom
JoshKarpel:really-disable-pbar

Conversation

@JoshKarpel
Copy link
Contributor

@JoshKarpel JoshKarpel commented Mar 21, 2021

Type of changes

  • Bug fix
  • New feature
  • Documentation / docstrings
  • Tests
  • Other

Checklist

  • I've run the latest black with default args on new code.
  • I've updated CHANGELOG.md and CONTRIBUTORS.md where appropriate.
  • I've added tests for new code.
  • I accept that @willmcgugan may be pedantic in the code review.

Description

If you make a Progress that is disabled, it will still display an initial version of itself because it is the renderable of its attached Live, and the Live is started unconditionally in Progress.start. Example:

from rich.progress import Progress

with Progress(disable=True) as progress:
    task = progress.add_task("foobar", total=100)
    progress.update(task, advance=1)

print("done")

Running this produces this output:
image

With this patch, it produces this:
image


I added some tests for this, but they're poking around the internals to do it - let me know if this isn't your preferred style.

@codecov
Copy link

codecov bot commented Mar 21, 2021

Codecov Report

Merging #1125 (34c5620) into master (e08a838) will increase coverage by 0.06%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1125      +/-   ##
==========================================
+ Coverage   99.77%   99.84%   +0.06%     
==========================================
  Files          69       69              
  Lines        6322     6323       +1     
==========================================
+ Hits         6308     6313       +5     
+ Misses         14       10       -4     
Flag Coverage Δ
unittests 99.84% <100.00%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
rich/progress.py 98.04% <100.00%> (+0.98%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 472ed32...34c5620. Read the comment docs.

@JoshKarpel JoshKarpel marked this pull request as ready for review March 21, 2021 15:39
@willmcgugan
Copy link
Member

Thanks for this. Would you mind also testing the output? i.e. confirm that when disable=True nothing gets written. Just to catch any regression.

@willmcgugan
Copy link
Member

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants