From 38642eb12713a3d6f6bada8fb051cdb108e632ca Mon Sep 17 00:00:00 2001 From: pared Date: Mon, 17 Jun 2019 19:21:17 +0200 Subject: [PATCH 1/3] metrics: show: remove active branch from tags only show call --- dvc/repo/metrics/show.py | 3 +++ tests/func/test_metrics.py | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/dvc/repo/metrics/show.py b/dvc/repo/metrics/show.py index 6ce9f8e71..ef953a996 100644 --- a/dvc/repo/metrics/show.py +++ b/dvc/repo/metrics/show.py @@ -269,6 +269,9 @@ def show( if metrics: res[branch] = metrics + if all_tags and not all_branches: + res.pop(repo.scm.active_branch()) + if not res: if path: raise BadMetricError(path) diff --git a/tests/func/test_metrics.py b/tests/func/test_metrics.py index 806afcca7..01636ca74 100644 --- a/tests/func/test_metrics.py +++ b/tests/func/test_metrics.py @@ -829,3 +829,26 @@ class TestShouldDisplayMetricsEvenIfMetricIsMissing(object): in caplog.text ) assert 0 == ret + + +def test_should_not_display_current_branch_on_display_tag( + git, dvc_repo, repo_dir +): + def write_metric_code(metric_filename, metric_value): + return "with open('{}', 'w') as fobj:\n fobj.write('{}')".format( + metric_filename, metric_value + ) + + metric_filename = "metric" + metric_stage = metric_filename + Stage.STAGE_FILE_SUFFIX + code = write_metric_code(metric_filename, 0.5) + run_command = 'python -c "{}"' + + dvc_repo.run(cmd=run_command.format(code), metrics=[metric_filename]) + git.index.add([metric_filename, metric_stage]) + git.index.commit("first") + tag = "v1.0" + git.git.tag(tag) + + metrics = dvc_repo.metrics.show(all_tags=True) + assert set(metrics.keys()) == {tag} From 005a6016aa07fc06151e765451dd636791ced909 Mon Sep 17 00:00:00 2001 From: pawel Date: Mon, 17 Jun 2019 22:41:15 +0200 Subject: [PATCH 2/3] brancher refactor --- dvc/repo/brancher.py | 4 ++-- dvc/repo/metrics/show.py | 3 --- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/dvc/repo/brancher.py b/dvc/repo/brancher.py index e84fcaf70..be1dacf1c 100644 --- a/dvc/repo/brancher.py +++ b/dvc/repo/brancher.py @@ -36,9 +36,9 @@ def brancher( # noqa: E302 if all_tags: tags = scm.list_tags() - if branches is None: + if branches is None and not (all_tags and not all_branches): revs.extend([scm.active_branch()]) - else: + elif branches is not None: revs.extend(branches) if tags is not None: diff --git a/dvc/repo/metrics/show.py b/dvc/repo/metrics/show.py index ef953a996..6ce9f8e71 100644 --- a/dvc/repo/metrics/show.py +++ b/dvc/repo/metrics/show.py @@ -269,9 +269,6 @@ def show( if metrics: res[branch] = metrics - if all_tags and not all_branches: - res.pop(repo.scm.active_branch()) - if not res: if path: raise BadMetricError(path) From 362fe1337e0aa17fd498c493ca67bad46d7f621f Mon Sep 17 00:00:00 2001 From: pawel Date: Tue, 18 Jun 2019 15:28:01 +0200 Subject: [PATCH 3/3] brancher: include working tree in every method call --- dvc/repo/brancher.py | 14 ++++++-------- tests/func/test_metrics.py | 25 ++----------------------- 2 files changed, 8 insertions(+), 31 deletions(-) diff --git a/dvc/repo/brancher.py b/dvc/repo/brancher.py index be1dacf1c..72b066bee 100644 --- a/dvc/repo/brancher.py +++ b/dvc/repo/brancher.py @@ -1,3 +1,6 @@ +from dvc.scm.tree import WorkingTree + + def brancher( # noqa: E302 self, branches=None, all_branches=False, tags=None, all_tags=False ): @@ -24,11 +27,8 @@ def brancher( # noqa: E302 scm = self.scm - if self.scm.is_dirty(): - from dvc.scm.tree import WorkingTree - - self.tree = WorkingTree(self.root_dir) - yield "Working Tree" + self.tree = WorkingTree(self.root_dir) + yield "working tree" if all_branches: branches = scm.list_branches() @@ -36,9 +36,7 @@ def brancher( # noqa: E302 if all_tags: tags = scm.list_tags() - if branches is None and not (all_tags and not all_branches): - revs.extend([scm.active_branch()]) - elif branches is not None: + if branches is not None: revs.extend(branches) if tags is not None: diff --git a/tests/func/test_metrics.py b/tests/func/test_metrics.py index 01636ca74..ab137fd99 100644 --- a/tests/func/test_metrics.py +++ b/tests/func/test_metrics.py @@ -706,6 +706,7 @@ class TestCachedMetrics(TestDvc): "master": {"metrics.json": ["master"]}, "one": {"metrics.json": ["one"]}, "two": {"metrics.json": ["two"]}, + "working tree": {"metrics.json": ["two"]}, }, ) @@ -719,6 +720,7 @@ class TestCachedMetrics(TestDvc): "master": {"metrics.json": ["master"]}, "one": {"metrics.json": ["one"]}, "two": {"metrics.json": ["two"]}, + "working tree": {"metrics.json": ["two"]}, }, ) @@ -829,26 +831,3 @@ class TestShouldDisplayMetricsEvenIfMetricIsMissing(object): in caplog.text ) assert 0 == ret - - -def test_should_not_display_current_branch_on_display_tag( - git, dvc_repo, repo_dir -): - def write_metric_code(metric_filename, metric_value): - return "with open('{}', 'w') as fobj:\n fobj.write('{}')".format( - metric_filename, metric_value - ) - - metric_filename = "metric" - metric_stage = metric_filename + Stage.STAGE_FILE_SUFFIX - code = write_metric_code(metric_filename, 0.5) - run_command = 'python -c "{}"' - - dvc_repo.run(cmd=run_command.format(code), metrics=[metric_filename]) - git.index.add([metric_filename, metric_stage]) - git.index.commit("first") - tag = "v1.0" - git.git.tag(tag) - - metrics = dvc_repo.metrics.show(all_tags=True) - assert set(metrics.keys()) == {tag}