From deba7e95da6f7f174618f9da2fe46bbf5d3d103a Mon Sep 17 00:00:00 2001 From: pawel Date: Fri, 8 Nov 2019 17:46:04 +0100 Subject: [PATCH 1/4] get/import: more meaningful message on NoRemoteError --- dvc/exceptions.py | 7 +++++++ dvc/repo/get.py | 4 ++++ dvc/repo/imp.py | 9 ++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/dvc/exceptions.py b/dvc/exceptions.py index 07a0ce8061..9bab2eeaf7 100644 --- a/dvc/exceptions.py +++ b/dvc/exceptions.py @@ -328,3 +328,10 @@ def __init__(self, target_infos): class CollectCacheError(DvcException): pass + + +class RemoteNotSpecifiedInTargetRepoError(DvcException): + def __init__(self, url): + super(RemoteNotSpecifiedInTargetRepoError, self).__init__( + "No DVC remote is specified in target repository '{}'".format(url) + ) diff --git a/dvc/repo/get.py b/dvc/repo/get.py index 0117006840..1f1afdb6d9 100644 --- a/dvc/repo/get.py +++ b/dvc/repo/get.py @@ -3,9 +3,11 @@ import shortuuid +from dvc.config import NoRemoteError from dvc.exceptions import GetDVCFileError from dvc.exceptions import NotDvcRepoError from dvc.exceptions import OutputNotFoundError +from dvc.exceptions import RemoteNotSpecifiedInTargetRepoError from dvc.exceptions import UrlNotDvcRepoError from dvc.external_repo import external_repo from dvc.path_info import PathInfo @@ -56,6 +58,8 @@ def get(url, path, out=None, rev=None): with o.repo.state: o.checkout() + except NoRemoteError: + raise RemoteNotSpecifiedInTargetRepoError(url) except NotDvcRepoError: raise UrlNotDvcRepoError(url) except OutputNotFoundError: diff --git a/dvc/repo/imp.py b/dvc/repo/imp.py index 68ead389b6..d15697dbd1 100644 --- a/dvc/repo/imp.py +++ b/dvc/repo/imp.py @@ -1,6 +1,13 @@ +from dvc.config import NoRemoteError +from dvc.exceptions import RemoteNotSpecifiedInTargetRepoError + + def imp(self, url, path, out=None, rev=None): erepo = {"url": url} if rev is not None: erepo["rev"] = rev - return self.imp_url(path, out=out, erepo=erepo, locked=True) + try: + return self.imp_url(path, out=out, erepo=erepo, locked=True) + except NoRemoteError: + raise RemoteNotSpecifiedInTargetRepoError(url) From 76fb6616550020cca6d4b564a3e1b9b5cd0878b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Redzy=C5=84ski?= Date: Tue, 12 Nov 2019 13:23:14 +0100 Subject: [PATCH 2/4] get/import: handle NoRepoError with external_repo --- dvc/exceptions.py | 4 ++-- dvc/external_repo.py | 7 ++++++- dvc/repo/get.py | 4 ---- dvc/repo/imp.py | 9 +-------- 4 files changed, 9 insertions(+), 15 deletions(-) diff --git a/dvc/exceptions.py b/dvc/exceptions.py index 9bab2eeaf7..7a70821ace 100644 --- a/dvc/exceptions.py +++ b/dvc/exceptions.py @@ -330,8 +330,8 @@ class CollectCacheError(DvcException): pass -class RemoteNotSpecifiedInTargetRepoError(DvcException): +class RemoteNotSpecifiedInExternalRepoError(DvcException): def __init__(self, url): - super(RemoteNotSpecifiedInTargetRepoError, self).__init__( + super(RemoteNotSpecifiedInExternalRepoError, self).__init__( "No DVC remote is specified in target repository '{}'".format(url) ) diff --git a/dvc/external_repo.py b/dvc/external_repo.py index ccdadf6e6b..6fab519dff 100644 --- a/dvc/external_repo.py +++ b/dvc/external_repo.py @@ -7,6 +7,8 @@ from funcy import retry +from dvc.config import NoRemoteError +from dvc.exceptions import RemoteNotSpecifiedInExternalRepoError from dvc.utils import remove @@ -19,7 +21,10 @@ def external_repo(url=None, rev=None, rev_lock=None, cache_dir=None): path = _external_repo(url=url, rev=rev_lock or rev, cache_dir=cache_dir) repo = Repo(path) - yield repo + try: + yield repo + except NoRemoteError: + raise RemoteNotSpecifiedInExternalRepoError(url) repo.close() diff --git a/dvc/repo/get.py b/dvc/repo/get.py index 1f1afdb6d9..0117006840 100644 --- a/dvc/repo/get.py +++ b/dvc/repo/get.py @@ -3,11 +3,9 @@ import shortuuid -from dvc.config import NoRemoteError from dvc.exceptions import GetDVCFileError from dvc.exceptions import NotDvcRepoError from dvc.exceptions import OutputNotFoundError -from dvc.exceptions import RemoteNotSpecifiedInTargetRepoError from dvc.exceptions import UrlNotDvcRepoError from dvc.external_repo import external_repo from dvc.path_info import PathInfo @@ -58,8 +56,6 @@ def get(url, path, out=None, rev=None): with o.repo.state: o.checkout() - except NoRemoteError: - raise RemoteNotSpecifiedInTargetRepoError(url) except NotDvcRepoError: raise UrlNotDvcRepoError(url) except OutputNotFoundError: diff --git a/dvc/repo/imp.py b/dvc/repo/imp.py index d15697dbd1..68ead389b6 100644 --- a/dvc/repo/imp.py +++ b/dvc/repo/imp.py @@ -1,13 +1,6 @@ -from dvc.config import NoRemoteError -from dvc.exceptions import RemoteNotSpecifiedInTargetRepoError - - def imp(self, url, path, out=None, rev=None): erepo = {"url": url} if rev is not None: erepo["rev"] = rev - try: - return self.imp_url(path, out=out, erepo=erepo, locked=True) - except NoRemoteError: - raise RemoteNotSpecifiedInTargetRepoError(url) + return self.imp_url(path, out=out, erepo=erepo, locked=True) From 48d16f6cc5194773f5256b346a11d17b21eb397a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Redzy=C5=84ski?= Date: Tue, 12 Nov 2019 15:19:05 +0100 Subject: [PATCH 3/4] Update dvc/exceptions.py Co-Authored-By: Ruslan Kuprieiev --- dvc/exceptions.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dvc/exceptions.py b/dvc/exceptions.py index 7a70821ace..45322bbe57 100644 --- a/dvc/exceptions.py +++ b/dvc/exceptions.py @@ -333,5 +333,7 @@ class CollectCacheError(DvcException): class RemoteNotSpecifiedInExternalRepoError(DvcException): def __init__(self, url): super(RemoteNotSpecifiedInExternalRepoError, self).__init__( - "No DVC remote is specified in target repository '{}'".format(url) + "No DVC remote is specified in the target repository '{}'".format( + url + ) ) From 4a6a1b662dda5dff46e9a74b9aad96353548a751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Redzy=C5=84ski?= Date: Wed, 13 Nov 2019 10:58:38 +0100 Subject: [PATCH 4/4] Update dvc/external_repo.py Co-Authored-By: Ruslan Kuprieiev --- dvc/exceptions.py | 5 +++-- dvc/external_repo.py | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/dvc/exceptions.py b/dvc/exceptions.py index 45322bbe57..2916066146 100644 --- a/dvc/exceptions.py +++ b/dvc/exceptions.py @@ -331,9 +331,10 @@ class CollectCacheError(DvcException): class RemoteNotSpecifiedInExternalRepoError(DvcException): - def __init__(self, url): + def __init__(self, url, cause=None): super(RemoteNotSpecifiedInExternalRepoError, self).__init__( "No DVC remote is specified in the target repository '{}'".format( url - ) + ), + cause=cause, ) diff --git a/dvc/external_repo.py b/dvc/external_repo.py index 6fab519dff..874240bc7f 100644 --- a/dvc/external_repo.py +++ b/dvc/external_repo.py @@ -23,8 +23,8 @@ def external_repo(url=None, rev=None, rev_lock=None, cache_dir=None): repo = Repo(path) try: yield repo - except NoRemoteError: - raise RemoteNotSpecifiedInExternalRepoError(url) + except NoRemoteError as exc: + raise RemoteNotSpecifiedInExternalRepoError(url, cause=exc) repo.close()