Skip to content

Commit

Permalink
cli: fix cache dir command
Browse files Browse the repository at this point in the history
  • Loading branch information
efiop committed Dec 30, 2020
1 parent a678028 commit 54937cc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
17 changes: 14 additions & 3 deletions dvc/command/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,21 @@
class CmdCacheDir(CmdConfig):
def run(self):
if self.args.value is None and not self.args.unset:
logger.info(self.config["cache"]["dir"])
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")
logger.info(conf["cache"]["dir"])
return 0
with self.config.edit(level=self.args.level) as edit:
edit["cache"]["dir"] = self.args.value
with self.config.edit(level=self.args.level) as conf:
if self.args.unset:
self._check(conf, False, "cache", "dir")
del conf["cache"]["dir"]
else:
self._check(conf, False, "cache")
conf["cache"]["dir"] = self.args.value
return 0


Expand Down
25 changes: 25 additions & 0 deletions tests/func/test_cache.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import stat
import textwrap

import configobj
import pytest
Expand Down Expand Up @@ -213,3 +214,27 @@ def test_shared_cache(tmp_dir, dvc, group, dir_mode):
for fname in fnames:
path = os.path.join(root, fname)
assert stat.S_IMODE(os.stat(path).st_mode) == 0o444


def test_cache_dir_local(tmp_dir, dvc, caplog):
(tmp_dir / ".dvc" / "config.local").write_text(
textwrap.dedent(
"""\
[cache]
dir = some/path
"""
)
)
path = os.path.join(dvc.dvc_dir, "some", "path")

caplog.clear()
assert main(["cache", "dir", "--local"]) == 0
assert path in caplog.text

caplog.clear()
assert main(["cache", "dir"]) == 0
assert path in caplog.text

caplog.clear()
assert main(["cache", "dir", "--repo"]) == 251
assert "option 'dir' doesn't exist in section 'cache'" in caplog.text

0 comments on commit 54937cc

Please sign in to comment.