config: don't set default cache dir

Setting default values is very untypical for all other applications and the
info config has is not enough to make a decision on the default cache dir,
especially when dealing with gitfs.

Fixes #8705
This commit is contained in:
Ruslan Kuprieiev
2023-02-17 07:57:39 +02:00
parent d7ea7c358d
commit 4f49023a08
3 changed files with 33 additions and 8 deletions
+22 -2
View File
@@ -1,3 +1,5 @@
import os
from dvc.fs import GitFileSystem, Schemes
from dvc_data.hashfile.db import get_odb
@@ -28,16 +30,34 @@ class CacheManager:
self.config = config = repo.config["cache"]
self._odb = {}
default = None
if repo and repo.dvc_dir:
if isinstance(repo.fs, GitFileSystem):
relparts = ()
if repo.root_dir != "/":
# subrepo
relparts = repo.fs.path.relparts(repo.root_dir, "/")
dvc_dir = os.path.join(
repo.scm.root_dir,
*relparts,
repo.DVC_DIR,
)
if os.path.exists(dvc_dir):
default = os.path.join(dvc_dir, self.CACHE_DIR)
else:
default = repo.fs.path.join(repo.dvc_dir, self.CACHE_DIR)
local = config.get("local")
if local:
settings = {"name": local}
elif "dir" not in config:
elif "dir" not in config and not default:
settings = None
else:
from dvc.config_schema import LOCAL_COMMON
settings = {"url": config["dir"]}
url = config.get("dir") or default
settings = {"url": url}
for opt in LOCAL_COMMON:
if opt in config:
settings[str(opt)] = config.get(opt)
+11 -2
View File
@@ -1,4 +1,5 @@
import argparse
import os
from dvc.cli import completion
from dvc.cli.utils import append_doc_link, fix_subparsers
@@ -9,13 +10,21 @@ from dvc.ui import ui
class CmdCacheDir(CmdConfig):
def run(self):
if self.args.value is None and not self.args.unset:
from dvc.config import ConfigError
if self.args.level:
conf = self.config.read(level=self.args.level)
else:
# Use merged config with default values
conf = self.config
self._check(conf, False, "cache", "dir")
ui.write(conf["cache"]["dir"])
try:
self._check(conf, False, "cache", "dir")
path = conf["cache"]["dir"]
except ConfigError:
if not self.config.dvc_dir or self.args.level:
raise
path = os.path.join(self.config.dvc_dir, "cache")
ui.write(path)
return 0
with self.config.edit(level=self.args.level) as conf:
if self.args.unset:
-4
View File
@@ -170,10 +170,6 @@ class Config(dict):
self.clear()
self.update(conf)
# Add resolved default cache.dir
if not self["cache"].get("dir") and self.dvc_dir:
self["cache"]["dir"] = os.path.join(self.dvc_dir, "cache")
def _get_fs(self, level):
# NOTE: this might be a Gitfs, which doesn't see things outside of
# the repo.