Skip to content

Commit

Permalink
ui: make progress bars respect --quiet (iterative#3316)
Browse files Browse the repository at this point in the history
* ui: default no_progress_bar=None instead of False

Fixes iterative#3314

* ui: catch remaining missing auto-quiet progress

* progress: treat disable=False as None

* test: progress.Tqdm(disable=False)

* revert no_progress_bar=None <= False

partially reverts e0342a8
  • Loading branch information
casperdcl authored Feb 14, 2020
1 parent 77f24af commit 276a2b0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
5 changes: 3 additions & 2 deletions dvc/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def __init__(
desc : persists after `close()`
level : effective logging level for determining `disable`;
used only if `disable` is unspecified
disable : If (default: None), will be determined by logging level.
disable : If (default: None) or False,
will be determined by logging level.
May be overridden to `True` due to non-TTY status.
Skip override by specifying env var `DVC_IGNORE_ISATTY`.
kwargs : anything accepted by `tqdm.tqdm()`
Expand All @@ -69,7 +70,7 @@ def __init__(
file = sys.stderr
self.desc_persist = desc
# auto-disable based on `logger.level`
if disable is None:
if not disable:
disable = logger.getEffectiveLevel() > level
# auto-disable based on TTY
if (
Expand Down
4 changes: 2 additions & 2 deletions dvc/repo/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def add(repo, targets, recursive=False, no_commit=False, fname=None):
total=len(stages),
desc="Processing",
unit="file",
disable=True if len(stages) == 1 else None,
disable=len(stages) == 1,
) as pbar_stages:
for stage in stages:
try:
Expand Down Expand Up @@ -120,7 +120,7 @@ def _create_stages(repo, targets, fname, pbar=None):
for out in Tqdm(
targets,
desc="Creating DVC-files",
disable=True if len(targets) < LARGE_DIR_SIZE else None,
disable=len(targets) < LARGE_DIR_SIZE,
unit="file",
):
stage = Stage.create(
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/test_progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ def test_quiet_logging(caplog, capsys):
assert out_err.err == ""


def test_quiet_logging_disable_false(caplog, capsys):
with caplog.at_level(logging.CRITICAL, logger="dvc"):
# simulate interactive terminal
with mock.patch.object(sys.stderr, "isatty", return_value=True):
for _ in Tqdm(range(10), disable=False):
pass
out_err = capsys.readouterr()
assert out_err.out == ""
assert out_err.err == ""


def test_quiet_notty(caplog, capsys):
with caplog.at_level(logging.INFO, logger="dvc"):
for _ in Tqdm(range(10)):
Expand Down

0 comments on commit 276a2b0

Please sign in to comment.