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 all 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
4 changes: 0 additions & 4 deletions dvc/repo/diff.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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():
"""
Expand Down
5 changes: 3 additions & 2 deletions dvc/scm/__init__.py
Original file line number Diff line number Diff line change
@@ -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):
karajan1001 marked this conversation as resolved.
Show resolved Hide resolved
raise NoSCMError


def SCM(
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):
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."""

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


Expand Down
11 changes: 11 additions & 0 deletions tests/func/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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()