Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config: don't set default cache dir #9037

Merged
merged 1 commit into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions dvc/cachemgr.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

from dvc.fs import GitFileSystem, Schemes
from dvc_data.hashfile.db import get_odb

Expand Down Expand Up @@ -28,16 +30,34 @@ def __init__(self, repo):
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)
Expand Down
13 changes: 11 additions & 2 deletions dvc/commands/cache.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse
import os

from dvc.cli import completion
from dvc.cli.utils import append_doc_link, fix_subparsers
Expand All @@ -9,13 +10,21 @@
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:
Expand Down
4 changes: 0 additions & 4 deletions dvc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,6 @@ def load(self, validate: bool = True, config: Optional["DictStrAny"] = None):
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.
Expand Down