From b27136884551a7dd86a9173764423fddfd122ab2 Mon Sep 17 00:00:00 2001 From: Mayur Kularni Date: Mon, 9 Dec 2019 14:14:49 +0530 Subject: [PATCH] Moved `remote_config_exists` into `RemoteConfig` --- dvc/external_repo.py | 20 ++------------------ dvc/remote/config.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/dvc/external_repo.py b/dvc/external_repo.py index ed4b8b39e..4e9c50e98 100644 --- a/dvc/external_repo.py +++ b/dvc/external_repo.py @@ -8,7 +8,7 @@ from funcy import retry from dvc.exceptions import NoRemoteInExternalRepoError from dvc.remote import RemoteConfig -from dvc.config import NoRemoteError, ConfigError +from dvc.config import NoRemoteError from dvc.exceptions import NoOutputInExternalRepoError from dvc.exceptions import OutputNotFoundError from dvc.utils.fs import remove @@ -73,7 +73,7 @@ def _external_repo(url=None, rev=None, cache_dir=None): # add default remote pointing to the original repo's cache location if os.path.isdir(url): rconfig = RemoteConfig(repo.config) - if not _remote_config_exists(rconfig): + if not rconfig.remote_config_exists(): original_repo = Repo(url) rconfig.add( "upstream", @@ -127,19 +127,3 @@ def _clone_repo(url, path): git = Git.clone(url, path) git.close() - - -def _remote_config_exists(rconfig): - """ - Checks if default remote config is present. - Args: - rconfig: a remote config - - Returns: - True if the remote config exists, else False - """ - try: - default = rconfig.get_default() - except ConfigError: - default = None - return bool(default) diff --git a/dvc/remote/config.py b/dvc/remote/config.py index dccad52ba..e1dc2dfb9 100644 --- a/dvc/remote/config.py +++ b/dvc/remote/config.py @@ -156,3 +156,18 @@ class RemoteConfig(object): return self.config.get( Config.SECTION_CORE, Config.SECTION_CORE_REMOTE, level=level ) + + def remote_config_exists(self): + """ + Checks if default remote config is present. + Args: + rconfig: a remote config + + Returns: + True if the remote config exists, else False + """ + try: + default = self.get_default() + except ConfigError: + default = None + return bool(default)