From d2e6835090cdefac63ce32c7a93148e476be0eb1 Mon Sep 17 00:00:00 2001 From: myname Date: Sun, 19 Apr 2020 11:03:42 +0800 Subject: [PATCH 1/9] fix #3605 --- dvc/scm/base.py | 4 ++++ tests/func/test_metrics.py | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/dvc/scm/base.py b/dvc/scm/base.py index 017263de12..a625f7b11d 100644 --- a/dvc/scm/base.py +++ b/dvc/scm/base.py @@ -155,3 +155,7 @@ def belongs_to_scm(self, path): def close(self): """ Method to close the files """ + + def resolve_rev(self, rev): + """Pick out and massage parameters""" + raise SCMError("only supported for Git repositories") diff --git a/tests/func/test_metrics.py b/tests/func/test_metrics.py index fab19c86d6..f020da372c 100644 --- a/tests/func/test_metrics.py +++ b/tests/func/test_metrics.py @@ -1005,3 +1005,14 @@ def test_metrics_diff_deleted_metric(tmp_dir, scm, dvc): "a.b.e": {"old": "3", "new": None}, } } + + +def test_metrics_without_scm(tmp_dir, dvc): + metrics = {"acc": 0.97, "recall": 0.95} + metrics_name = "metrics.json" + tmp_dir.gen({metrics_name: json.dumps(metrics)}) + dvc.add(metrics_name) + dvc.metrics.add(metrics_name) + with pytest.raises(DvcException) as msg: + dvc.metrics.diff() + assert "only supported for Git repositories" in str(msg.value) From dae884fdacfea618e367400575b79f9e6c442972 Mon Sep 17 00:00:00 2001 From: myname Date: Sun, 19 Apr 2020 11:33:34 +0800 Subject: [PATCH 2/9] changed exception raise position --- dvc/repo/brancher.py | 3 +++ dvc/scm/base.py | 4 ---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/dvc/repo/brancher.py b/dvc/repo/brancher.py index 67a3b19b36..841d5fd691 100644 --- a/dvc/repo/brancher.py +++ b/dvc/repo/brancher.py @@ -1,6 +1,7 @@ from funcy import group_by from dvc.scm.tree import WorkingTree +from dvc.exceptions import DvcException def brancher( # noqa: E302 @@ -46,5 +47,7 @@ def brancher( # noqa: E302 for sha, names in group_by(scm.resolve_rev, revs).items(): self.tree = scm.get_tree(sha) yield ", ".join(names) + except AttributeError: + raise DvcException("only supported for Git repositories") finally: self.tree = saved_tree diff --git a/dvc/scm/base.py b/dvc/scm/base.py index a625f7b11d..017263de12 100644 --- a/dvc/scm/base.py +++ b/dvc/scm/base.py @@ -155,7 +155,3 @@ def belongs_to_scm(self, path): def close(self): """ Method to close the files """ - - def resolve_rev(self, rev): - """Pick out and massage parameters""" - raise SCMError("only supported for Git repositories") From cea9229bdf9f4af640a7e89dd824da7f4db3df89 Mon Sep 17 00:00:00 2001 From: karajan1001 Date: Sun, 19 Apr 2020 16:46:23 +0800 Subject: [PATCH 3/9] Updated error msg --- dvc/repo/brancher.py | 4 ++-- dvc/repo/diff.py | 4 ++-- dvc/scm/base.py | 10 ++++++++++ tests/func/test_metrics.py | 3 +-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/dvc/repo/brancher.py b/dvc/repo/brancher.py index 841d5fd691..702ed9dc97 100644 --- a/dvc/repo/brancher.py +++ b/dvc/repo/brancher.py @@ -1,7 +1,7 @@ from funcy import group_by from dvc.scm.tree import WorkingTree -from dvc.exceptions import DvcException +from dvc.scm.base import NOSCMError def brancher( # noqa: E302 @@ -48,6 +48,6 @@ def brancher( # noqa: E302 self.tree = scm.get_tree(sha) yield ", ".join(names) except AttributeError: - raise DvcException("only supported for Git repositories") + raise NOSCMError() finally: self.tree = saved_tree diff --git a/dvc/repo/diff.py b/dvc/repo/diff.py index d18389e05c..d6e59ffb4e 100644 --- a/dvc/repo/diff.py +++ b/dvc/repo/diff.py @@ -1,9 +1,9 @@ import os -from dvc.exceptions import DvcException from dvc.repo import locked from dvc.scm.git import Git from dvc.scm.tree import is_working_tree +from dvc.scm.base import NOSCMError @locked @@ -16,7 +16,7 @@ def diff(self, a_rev="HEAD", b_rev=None): `dvc diff` would be the same as `dvc diff HEAD`. """ if type(self.scm) is not Git: - raise DvcException("only supported for Git repositories") + raise NOSCMError def _paths_checksums(): """ diff --git a/dvc/scm/base.py b/dvc/scm/base.py index 017263de12..8d74222cd5 100644 --- a/dvc/scm/base.py +++ b/dvc/scm/base.py @@ -24,6 +24,16 @@ class RevError(SCMError): pass +class NOSCMError(SCMError): + def __init__(self): + msg = ( + "only supported for Git repositories. If you had\n already " + "initialized a git repo, this may be caused by dvc configuration. " + "Use\n `dvc config core.no_scm False` to update it." + ) + super().__init__(msg) + + class Base(object): """Base class for source control management driver implementations.""" diff --git a/tests/func/test_metrics.py b/tests/func/test_metrics.py index f020da372c..872c2250e7 100644 --- a/tests/func/test_metrics.py +++ b/tests/func/test_metrics.py @@ -1013,6 +1013,5 @@ def test_metrics_without_scm(tmp_dir, dvc): tmp_dir.gen({metrics_name: json.dumps(metrics)}) dvc.add(metrics_name) dvc.metrics.add(metrics_name) - with pytest.raises(DvcException) as msg: + with pytest.raises(DvcException, match=r"only supported for Git repos"): dvc.metrics.diff() - assert "only supported for Git repositories" in str(msg.value) From 9ea88210a5c7e14557996dbf89b27b3d9569575f Mon Sep 17 00:00:00 2001 From: karajan1001 Date: Mon, 20 Apr 2020 22:06:06 +0800 Subject: [PATCH 4/9] message changed --- dvc/scm/base.py | 6 +++--- tests/func/test_diff.py | 2 +- tests/func/test_metrics.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dvc/scm/base.py b/dvc/scm/base.py index 8d74222cd5..fba52be180 100644 --- a/dvc/scm/base.py +++ b/dvc/scm/base.py @@ -27,9 +27,9 @@ class RevError(SCMError): class NOSCMError(SCMError): def __init__(self): msg = ( - "only supported for Git repositories. If you had\n already " - "initialized a git repo, this may be caused by dvc configuration. " - "Use\n `dvc config core.no_scm False` to update it." + "Only supported for Git repositories. If you're\n" + "seeing this error in a Git repo, try updating the DVC " + "configuration with\n`dvc config core.no_scm False`." ) super().__init__(msg) diff --git a/tests/func/test_diff.py b/tests/func/test_diff.py index 4c3a660ddf..f1ebdf9edd 100644 --- a/tests/func/test_diff.py +++ b/tests/func/test_diff.py @@ -16,7 +16,7 @@ def digest(text): def test_no_scm(tmp_dir, dvc): tmp_dir.dvc_gen("file", "text") - with pytest.raises(DvcException, match=r"only supported for Git repos"): + with pytest.raises(DvcException, match=r"Only supported for Git repos"): dvc.diff() diff --git a/tests/func/test_metrics.py b/tests/func/test_metrics.py index 872c2250e7..3c40ad2da2 100644 --- a/tests/func/test_metrics.py +++ b/tests/func/test_metrics.py @@ -1013,5 +1013,5 @@ def test_metrics_without_scm(tmp_dir, dvc): tmp_dir.gen({metrics_name: json.dumps(metrics)}) dvc.add(metrics_name) dvc.metrics.add(metrics_name) - with pytest.raises(DvcException, match=r"only supported for Git repos"): + with pytest.raises(DvcException, match=r"Only supported for Git repos"): dvc.metrics.diff() From e013602246f3d03b75083bec1269996544608733 Mon Sep 17 00:00:00 2001 From: Jorge Orpinel Date: Tue, 21 Apr 2020 00:11:49 -0500 Subject: [PATCH 5/9] metrics diff: output edits per per https://github.com/iterative/dvc/pull/3650 and https://github.com/iterative/dvc/pull/3650#pullrequestreview-396837915 --- dvc/scm/base.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dvc/scm/base.py b/dvc/scm/base.py index fba52be180..e1bedc242a 100644 --- a/dvc/scm/base.py +++ b/dvc/scm/base.py @@ -24,12 +24,12 @@ class RevError(SCMError): pass -class NOSCMError(SCMError): +class NoSCMError(SCMError): def __init__(self): msg = ( - "Only supported for Git repositories. If you're\n" + "Only supported for Git repositories. If you're " "seeing this error in a Git repo, try updating the DVC " - "configuration with\n`dvc config core.no_scm False`." + "configuration with `dvc config core.no_scm false`." ) super().__init__(msg) From eddeaa2629a068446ad8249ccc74232c12685857 Mon Sep 17 00:00:00 2001 From: karajan1001 Date: Tue, 21 Apr 2020 14:10:03 +0800 Subject: [PATCH 6/9] Update tests/func/test_metrics.py Co-Authored-By: Ruslan Kuprieiev --- tests/func/test_metrics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/func/test_metrics.py b/tests/func/test_metrics.py index 3c40ad2da2..56713d2b20 100644 --- a/tests/func/test_metrics.py +++ b/tests/func/test_metrics.py @@ -1013,5 +1013,5 @@ def test_metrics_without_scm(tmp_dir, dvc): tmp_dir.gen({metrics_name: json.dumps(metrics)}) dvc.add(metrics_name) dvc.metrics.add(metrics_name) - with pytest.raises(DvcException, match=r"Only supported for Git repos"): + with pytest.raises(NoSCMError): dvc.metrics.diff() From 4915ddc949f353285c1c2ea901120bf7d860c0a3 Mon Sep 17 00:00:00 2001 From: karajan1001 Date: Tue, 21 Apr 2020 20:20:15 +0800 Subject: [PATCH 7/9] NoSCM now had a default attribute getting method `NoSCM` Object now raise `NoSCMError` when calling attributes which only in `Git` Object --- dvc/repo/brancher.py | 3 --- dvc/repo/diff.py | 4 ---- dvc/scm/__init__.py | 4 +++- tests/func/test_metrics.py | 1 + 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/dvc/repo/brancher.py b/dvc/repo/brancher.py index 702ed9dc97..67a3b19b36 100644 --- a/dvc/repo/brancher.py +++ b/dvc/repo/brancher.py @@ -1,7 +1,6 @@ from funcy import group_by from dvc.scm.tree import WorkingTree -from dvc.scm.base import NOSCMError def brancher( # noqa: E302 @@ -47,7 +46,5 @@ def brancher( # noqa: E302 for sha, names in group_by(scm.resolve_rev, revs).items(): self.tree = scm.get_tree(sha) yield ", ".join(names) - except AttributeError: - raise NOSCMError() finally: self.tree = saved_tree diff --git a/dvc/repo/diff.py b/dvc/repo/diff.py index d6e59ffb4e..5a83ed8008 100644 --- a/dvc/repo/diff.py +++ b/dvc/repo/diff.py @@ -1,9 +1,7 @@ import os from dvc.repo import locked -from dvc.scm.git import Git from dvc.scm.tree import is_working_tree -from dvc.scm.base import NOSCMError @locked @@ -15,8 +13,6 @@ def diff(self, a_rev="HEAD", b_rev=None): the concept of `index`, but it keeps the same interface, thus, `dvc diff` would be the same as `dvc diff HEAD`. """ - if type(self.scm) is not Git: - raise NOSCMError def _paths_checksums(): """ diff --git a/dvc/scm/__init__.py b/dvc/scm/__init__.py index dbf524cc76..782e0caaa7 100644 --- a/dvc/scm/__init__.py +++ b/dvc/scm/__init__.py @@ -1,13 +1,15 @@ """Manages source control systems (e.g. Git).""" from dvc.scm.base import Base +from dvc.scm.base import NoSCMError from dvc.scm.git import Git # Syntactic sugar to signal that this is an actual implementation for a DVC # project under no SCM control. class NoSCM(Base): - pass + def __getattr__(self, name): + raise NoSCMError def SCM( diff --git a/tests/func/test_metrics.py b/tests/func/test_metrics.py index 56713d2b20..f50972fe23 100644 --- a/tests/func/test_metrics.py +++ b/tests/func/test_metrics.py @@ -12,6 +12,7 @@ from dvc.repo import Repo as DvcRepo from dvc.repo.metrics.show import NO_METRICS_FILE_AT_REFERENCE_WARNING from dvc.utils import relpath +from dvc.scm.base import NoSCMError from tests.basic_env import TestDvcGit From 44c454b2e08839c02c58fe7a8b7c9184f7a3620b Mon Sep 17 00:00:00 2001 From: karajan1001 Date: Tue, 21 Apr 2020 20:38:17 +0800 Subject: [PATCH 8/9] Joined lines Mail change test --- dvc/scm/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dvc/scm/__init__.py b/dvc/scm/__init__.py index 782e0caaa7..9a0b0f4a04 100644 --- a/dvc/scm/__init__.py +++ b/dvc/scm/__init__.py @@ -1,7 +1,6 @@ """Manages source control systems (e.g. Git).""" -from dvc.scm.base import Base -from dvc.scm.base import NoSCMError +from dvc.scm.base import Base, NoSCMError from dvc.scm.git import Git From 55d451b2d7c2ba2190f956bad8f8acb5f76f648b Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Tue, 21 Apr 2020 20:56:08 +0300 Subject: [PATCH 9/9] tests: diff: use NoSCMError --- tests/func/test_diff.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/func/test_diff.py b/tests/func/test_diff.py index f1ebdf9edd..96776d6fe2 100644 --- a/tests/func/test_diff.py +++ b/tests/func/test_diff.py @@ -14,9 +14,11 @@ def digest(text): def test_no_scm(tmp_dir, dvc): + from dvc.scm.base import NoSCMError + tmp_dir.dvc_gen("file", "text") - with pytest.raises(DvcException, match=r"Only supported for Git repos"): + with pytest.raises(NoSCMError): dvc.diff()