moved default check out of RemoteConfig

This commit is contained in:
Mayur Kularni
2019-12-11 10:54:59 +05:30
parent e6285f70c5
commit e1e0cbd038
2 changed files with 20 additions and 18 deletions
+20 -3
View File
@@ -4,11 +4,12 @@ import os
import tempfile
from contextlib import contextmanager
from distutils.dir_util import copy_tree
from funcy import retry
from dvc.config import NoRemoteError, ConfigError
from dvc.exceptions import NoRemoteInExternalRepoError
from dvc.remote import RemoteConfig
from dvc.config import NoRemoteError
from dvc.exceptions import NoOutputInExternalRepoError
from dvc.exceptions import OutputNotFoundError
from dvc.utils.fs import remove
@@ -73,11 +74,11 @@ 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 rconfig.default_remote_set():
if not _default_remote_set(rconfig):
original_repo = Repo(url)
try:
rconfig.add(
"aut-generated-upstream",
"auto-generated-upstream",
original_repo.cache.local.cache_dir,
default=True,
level=Config.LEVEL_LOCAL,
@@ -129,3 +130,19 @@ def _clone_repo(url, path):
git = Git.clone(url, path)
git.close()
def _default_remote_set(rconfig):
"""
Checks if default remote config is present.
Args:
rconfig: a remote config
Returns:
True if the default remote config is set, else False
"""
try:
rconfig.get_default()
return True
except ConfigError:
return False
-15
View File
@@ -155,18 +155,3 @@ class RemoteConfig(object):
return self.config.get(
Config.SECTION_CORE, Config.SECTION_CORE_REMOTE, level=level
)
def default_remote_set(self):
"""
Checks if default remote config is present.
Args:
rconfig: a remote config
Returns:
True if the default remote config is set, else False
"""
try:
self.get_default()
return True
except ConfigError:
return False