metrics diff error message in --no-scm projects (#3650)

* fix #3605

* changed exception raise position

* Updated error msg

* message changed

* metrics diff: output edits per
per https://github.com/iterative/dvc/pull/3650
and https://github.com/iterative/dvc/pull/3650#pullrequestreview-396837915

* Update tests/func/test_metrics.py

Co-Authored-By: Ruslan Kuprieiev <[email protected]>

* NoSCM now had a default attribute getting method

`NoSCM` Object now raise `NoSCMError` when calling attributes which only in `Git` Object

* Joined lines

Mail change test

* tests: diff: use NoSCMError

Co-authored-by: myname <[email protected]>
Co-authored-by: karajan1001 <[email protected]>
Co-authored-by: Jorge Orpinel <[email protected]>
Co-authored-by: Ruslan Kuprieiev <[email protected]>
Co-authored-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
karajan1001
2020-04-21 21:15:46 +03:00
committed by GitHub
co-authored by Ruslan Kuprieiev myname karajan1001 Jorge Orpinel Ruslan Kuprieiev
parent bca5edf108
commit 254cf83310
5 changed files with 27 additions and 7 deletions
-4
View File
@@ -1,8 +1,6 @@
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
@@ -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 DvcException("only supported for Git repositories")
def _paths_checksums():
"""
+3 -2
View File
@@ -1,13 +1,14 @@
"""Manages source control systems (e.g. Git)."""
from dvc.scm.base import Base
from dvc.scm.base import Base, 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(
+10
View File
@@ -24,6 +24,16 @@ class RevError(SCMError):
pass
class NoSCMError(SCMError):
def __init__(self):
msg = (
"Only supported for Git repositories. If you're "
"seeing this error in a Git repo, try updating the DVC "
"configuration with `dvc config core.no_scm false`."
)
super().__init__(msg)
class Base(object):
"""Base class for source control management driver implementations."""
+3 -1
View File
@@ -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()
+11
View File
@@ -12,6 +12,7 @@ from dvc.main import main
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
@@ -1005,3 +1006,13 @@ 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(NoSCMError):
dvc.metrics.diff()