Repository: iterative/dvc

Issue:
dvc gc: bug of looking for remote path at local machine
My setup:
```
$ dvc version
DVC version: 0.40.1
Python version: 3.7.3
Platform: Linux-4.4.0-43-Microsoft-x86_64-with-debian-stretch-sid
```
See all documentation regarding the bug from [this Discord message](https://discordapp.com/channels/485586884165107732/563406153334128681/582841112461574184) and 15 messages forward.





Comments:

Patch:
diff --git a/dvc/config.py b/dvc/config.py
--- a/dvc/config.py
+++ b/dvc/config.py
@@ -498,7 +498,15 @@ def get_remote_settings(self, name):
             >>> get_remote_settings("server")
             {'url': 'ssh://localhost/'}
         """
-        settings = self.config[self.SECTION_REMOTE_FMT.format(name)]
+        settings = self.config.get(
+            self.SECTION_REMOTE_FMT.format(name.lower())
+        )
+
+        if settings is None:
+            raise ConfigError(
+                "unable to find remote section '{}'".format(name)
+            )
+
         parsed = urlparse(settings["url"])
 
         # Support for cross referenced remotes.
diff --git a/dvc/data_cloud.py b/dvc/data_cloud.py
--- a/dvc/data_cloud.py
+++ b/dvc/data_cloud.py
@@ -43,10 +43,16 @@ class DataCloud(object):
         "https": RemoteHTTP,
     }
 
-    def __init__(self, repo, config=None):
+    def __init__(self, repo):
         self.repo = repo
-        self._config = config
-        self._core = self._config[Config.SECTION_CORE]
+
+    @property
+    def _config(self):
+        return self.repo.config.config
+
+    @property
+    def _core(self):
+        return self._config.get(Config.SECTION_CORE, {})
 
     def get_remote(self, remote=None, command="<command>"):
         if not remote:
@@ -69,13 +75,8 @@ def get_remote(self, remote=None, command="<command>"):
         )
 
     def _init_remote(self, remote):
-        section = Config.SECTION_REMOTE_FMT.format(remote).lower()
-        cloud_config = self._config.get(section, None)
-        if not cloud_config:
-            msg = "can't find remote section '{}' in config"
-            raise ConfigError(msg.format(section))
-
-        return Remote(self.repo, cloud_config)
+        config = self.repo.config.get_remote_settings(remote)
+        return Remote(self.repo, config)
 
     def _init_compat(self):
         name = self._core.get(Config.SECTION_CORE_CLOUD, "").strip().lower()
diff --git a/dvc/remote/local/slow_link_detection.py b/dvc/remote/local/slow_link_detection.py
--- a/dvc/remote/local/slow_link_detection.py
+++ b/dvc/remote/local/slow_link_detection.py
@@ -48,7 +48,7 @@ def __call__(self, *args, **kwargs):
 def slow_link_guard(method):
     def call(remote_local, *args, **kwargs):
         cache_config = remote_local.repo.config.config.get(
-            Config.SECTION_CACHE
+            Config.SECTION_CACHE, {}
         )
         should_warn = cache_config.get(
             Config.SECTION_CACHE_SLOW_LINK_WARNING, True
diff --git a/dvc/repo/__init__.py b/dvc/repo/__init__.py
--- a/dvc/repo/__init__.py
+++ b/dvc/repo/__init__.py
@@ -75,7 +75,7 @@ def __init__(self, root_dir=None):
             logger.setLevel(level.upper())
 
         self.cache = Cache(self)
-        self.cloud = DataCloud(self, config=self.config.config)
+        self.cloud = DataCloud(self)
         self.updater = Updater(self.dvc_dir)
 
         self.metrics = Metrics(self)


Test patch:
diff --git a/tests/func/test_data_cloud.py b/tests/func/test_data_cloud.py
--- a/tests/func/test_data_cloud.py
+++ b/tests/func/test_data_cloud.py
@@ -235,7 +235,8 @@ def get_oss_url():
 
 class TestDataCloud(TestDvc):
     def _test_cloud(self, config, cl):
-        cloud = DataCloud(self.dvc, config=config)
+        self.dvc.config.config = config
+        cloud = DataCloud(self.dvc)
         self.assertIsInstance(cloud.get_remote(), cl)
 
     def test(self):
@@ -285,7 +286,8 @@ def _setup_cloud(self):
         config = copy.deepcopy(TEST_CONFIG)
         config[TEST_SECTION][Config.SECTION_REMOTE_URL] = repo
         config[TEST_SECTION][Config.SECTION_REMOTE_KEY_FILE] = keyfile
-        self.cloud = DataCloud(self.dvc, config)
+        self.dvc.config.config = config
+        self.cloud = DataCloud(self.dvc)
 
         self.assertIsInstance(self.cloud.get_remote(), self._get_cloud_class())
 
@@ -394,7 +396,8 @@ def _setup_cloud(self):
         config[TEST_SECTION][
             Config.SECTION_GCP_CREDENTIALPATH
         ] = TEST_GCP_CREDS_FILE
-        self.cloud = DataCloud(self.dvc, config)
+        self.dvc.config.config = config
+        self.cloud = DataCloud(self.dvc)
 
         self.assertIsInstance(self.cloud.get_remote(), self._get_cloud_class())