Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 9 commits into from
Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions dvc/repo/brancher.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from funcy import group_by

from dvc.scm.tree import WorkingTree
from dvc.scm.base import NOSCMError


def brancher( # noqa: E302
Expand Down Expand Up @@ -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 NOSCMError()
karajan1001 marked this conversation as resolved.
Show resolved Hide resolved
finally:
self.tree = saved_tree
4 changes: 2 additions & 2 deletions dvc/repo/diff.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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():
"""
Expand Down
10 changes: 10 additions & 0 deletions dvc/scm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ class RevError(SCMError):
pass


class NOSCMError(SCMError):
jorgeorpinel marked this conversation as resolved.
Show resolved Hide resolved
def __init__(self):
msg = (
"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`."
jorgeorpinel marked this conversation as resolved.
Show resolved Hide resolved
)
super().__init__(msg)


class Base(object):
"""Base class for source control management driver implementations."""

Expand Down
2 changes: 1 addition & 1 deletion tests/func/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down
10 changes: 10 additions & 0 deletions tests/func/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1005,3 +1005,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(DvcException, match=r"Only supported for Git repos"):
karajan1001 marked this conversation as resolved.
Show resolved Hide resolved
dvc.metrics.diff()