From abbe29e58e65885d7c72c488186a4cc97a33709d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Santos?= Date: Wed, 22 Jan 2020 17:06:14 +0000 Subject: [PATCH 1/4] push: improve 'no remote specified' hint Fixes #3121 --- dvc/config.py | 22 +++++++++++++++------- dvc/data_cloud.py | 4 +++- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/dvc/config.py b/dvc/config.py index 0fd312aa14..f509b90328 100644 --- a/dvc/config.py +++ b/dvc/config.py @@ -24,13 +24,21 @@ def __init__(self, msg): class NoRemoteError(ConfigError): - def __init__(self, command): - msg = ( - "no remote specified. Setup default remote with\n" - " dvc remote default \n" - "or use:\n" - " dvc {} -r \n".format(command) - ) + def __init__(self, command, *, has_any_remote=True): + if has_any_remote: + msg = ( + "no remote specified. Setup default remote with\n" + " dvc remote default \n" + "or use:\n" + " dvc {} -r ".format(command) + ) + else: + msg = ( + "no remote specified. Create a remote with\n" + " dvc remote add \n" + "To create a default remote use the -d flag:\n" + " dvc remote add -d \n" + ) super().__init__(msg) diff --git a/dvc/data_cloud.py b/dvc/data_cloud.py index fadd536bd0..7f8c611504 100644 --- a/dvc/data_cloud.py +++ b/dvc/data_cloud.py @@ -39,7 +39,9 @@ def get_remote(self, remote=None, command=""): if remote: return self._init_remote(remote) - raise NoRemoteError(command) + has_any_remote = any(key.startswith("remote ") for key in self._config) + + raise NoRemoteError(command, has_any_remote=has_any_remote) def _init_remote(self, remote): return Remote(self.repo, name=remote) From 2742a58226e989a5b99d7c3e491b7048f24d48d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Santos?= Date: Thu, 23 Jan 2020 12:23:16 +0000 Subject: [PATCH 2/4] move remote checking option to within NoRemoteError --- dvc/config.py | 10 ++++++++-- dvc/data_cloud.py | 4 +--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/dvc/config.py b/dvc/config.py index f509b90328..4846882e27 100644 --- a/dvc/config.py +++ b/dvc/config.py @@ -24,7 +24,13 @@ def __init__(self, msg): class NoRemoteError(ConfigError): - def __init__(self, command, *, has_any_remote=True): + def __init__(self, command, *, config=None): + has_any_remote = False + if config: + has_any_remote = config.list_options( + Config.SECTION_REMOTE_REGEX, Config.SECTION_REMOTE_URL + ) + if has_any_remote: msg = ( "no remote specified. Setup default remote with\n" @@ -37,7 +43,7 @@ def __init__(self, command, *, has_any_remote=True): "no remote specified. Create a remote with\n" " dvc remote add \n" "To create a default remote use the -d flag:\n" - " dvc remote add -d \n" + " dvc remote add -d " ) super().__init__(msg) diff --git a/dvc/data_cloud.py b/dvc/data_cloud.py index 7f8c611504..a989bf47a0 100644 --- a/dvc/data_cloud.py +++ b/dvc/data_cloud.py @@ -39,9 +39,7 @@ def get_remote(self, remote=None, command=""): if remote: return self._init_remote(remote) - has_any_remote = any(key.startswith("remote ") for key in self._config) - - raise NoRemoteError(command, has_any_remote=has_any_remote) + raise NoRemoteError(command, config=self.repo.config) def _init_remote(self, remote): return Remote(self.repo, name=remote) From 84999f590e18a929b54c228345f829fc85cc8c37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Santos?= Date: Thu, 23 Jan 2020 12:24:30 +0000 Subject: [PATCH 3/4] convert to bool --- dvc/config.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dvc/config.py b/dvc/config.py index 4846882e27..f2334495ef 100644 --- a/dvc/config.py +++ b/dvc/config.py @@ -27,8 +27,10 @@ class NoRemoteError(ConfigError): def __init__(self, command, *, config=None): has_any_remote = False if config: - has_any_remote = config.list_options( - Config.SECTION_REMOTE_REGEX, Config.SECTION_REMOTE_URL + has_any_remote = bool( + config.list_options( + Config.SECTION_REMOTE_REGEX, Config.SECTION_REMOTE_URL + ) ) if has_any_remote: From 2fb6b338bde64af85bec74f3ee0872da13845668 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Santos?= Date: Fri, 24 Jan 2020 15:13:14 +0000 Subject: [PATCH 4/4] move message creation outside of exception --- dvc/config.py | 26 +------------------------- dvc/data_cloud.py | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 26 deletions(-) diff --git a/dvc/config.py b/dvc/config.py index f2334495ef..d2d60d68d1 100644 --- a/dvc/config.py +++ b/dvc/config.py @@ -24,31 +24,7 @@ def __init__(self, msg): class NoRemoteError(ConfigError): - def __init__(self, command, *, config=None): - has_any_remote = False - if config: - has_any_remote = bool( - config.list_options( - Config.SECTION_REMOTE_REGEX, Config.SECTION_REMOTE_URL - ) - ) - - if has_any_remote: - msg = ( - "no remote specified. Setup default remote with\n" - " dvc remote default \n" - "or use:\n" - " dvc {} -r ".format(command) - ) - else: - msg = ( - "no remote specified. Create a remote with\n" - " dvc remote add \n" - "To create a default remote use the -d flag:\n" - " dvc remote add -d " - ) - - super().__init__(msg) + pass def supported_cache_type(types): diff --git a/dvc/data_cloud.py b/dvc/data_cloud.py index a989bf47a0..9babe164a4 100644 --- a/dvc/data_cloud.py +++ b/dvc/data_cloud.py @@ -39,7 +39,26 @@ def get_remote(self, remote=None, command=""): if remote: return self._init_remote(remote) - raise NoRemoteError(command, config=self.repo.config) + has_non_default_remote = bool( + self.repo.config.list_options( + Config.SECTION_REMOTE_REGEX, Config.SECTION_REMOTE_URL + ) + ) + + if has_non_default_remote: + error_msg = ( + "no remote specified. Setup default remote with\n" + " dvc remote default \n" + "or use:\n" + " dvc {} -r ".format(command) + ) + else: + error_msg = ( + "no remote specified. Create a default remote with\n" + " dvc remote add -d " + ) + + raise NoRemoteError(error_msg) def _init_remote(self, remote): return Remote(self.repo, name=remote)