Skip to content

Commit

Permalink
tree -> fs
Browse files Browse the repository at this point in the history
  • Loading branch information
efiop committed Feb 14, 2021
1 parent fd512b7 commit 1ce4eae
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 25 deletions.
11 changes: 6 additions & 5 deletions dvc/cache/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from copy import copy
from typing import Optional

from dvc.exceptions import DvcException
from dvc.progress import Tqdm

from ..objects import HashFile, ObjectFormatError
Expand Down Expand Up @@ -428,9 +429,9 @@ def _load_config(self):
from dvc.odb.config import CONFIG_FILENAME, load_config, migrate_config
from dvc.odb.versions import ODB_VERSION

config_path = self.tree.path_info / CONFIG_FILENAME
config_path = self.fs.path_info / CONFIG_FILENAME
self._config = load_config(
self.tree.path_info / CONFIG_FILENAME, self.tree
self.fs.path_info / CONFIG_FILENAME, self.fs
)

dos2unix = self.repo.config["core"].get("dos2unix", False)
Expand All @@ -443,12 +444,12 @@ def _load_config(self):
if not dos2unix and self.version != ODB_VERSION.V2:
migrate_config(self._config)
self._config_modified = True
elif not self.tree.exists(config_path):
elif not self.fs.exists(config_path):
self._config_modified = True

def _dump_config(self):
from dvc.odb.config import CONFIG_FILENAME, dump_config

config_path = self.tree.path_info / CONFIG_FILENAME
dump_config(self._config, config_path, self.tree)
config_path = self.fs.path_info / CONFIG_FILENAME
dump_config(self._config, config_path, self.fs)
self._config_modified = False
2 changes: 1 addition & 1 deletion dvc/fs/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from itertools import takewhile
from typing import TYPE_CHECKING, Callable, Optional, Tuple, Type, Union

from funcy import cached_property, lfilter, wrap_with
from funcy import lfilter, wrap_with

from dvc.path_info import PathInfo

Expand Down
16 changes: 8 additions & 8 deletions dvc/odb/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from dvc.exceptions import DvcException

if TYPE_CHECKING:
from dvc.fs.base import BaseFileSystem
from dvc.path_info import PathInfo
from dvc.tree.base import BaseTree

logger = logging.getLogger(__name__)

Expand All @@ -19,11 +19,11 @@ class ODBConfigFormatError(DvcException):
pass


def load_config(path_info: "PathInfo", tree: "BaseTree",) -> dict:
def load_config(path_info: "PathInfo", fs: "BaseFileSystem",) -> dict:
from dvc.utils.serialize import load_yaml

if tree.exists(path_info):
data = load_yaml(path_info, tree=tree)
if fs.exists(path_info):
data = load_yaml(path_info, fs=fs)
else:
data = {}

Expand All @@ -36,14 +36,14 @@ def load_config(path_info: "PathInfo", tree: "BaseTree",) -> dict:


def dump_config(
config: dict, path_info: "PathInfo", tree: "BaseTree",
config: dict, path_info: "PathInfo", fs: "BaseFileSystem",
):
from dvc.utils.serialize import modify_yaml

logger.debug("Writing ODB config '%s'", path_info)
if not tree.exists(path_info.parent):
tree.makedirs(path_info.parent)
with modify_yaml(path_info, tree=tree) as data:
if not fs.exists(path_info.parent):
fs.makedirs(path_info.parent)
with modify_yaml(path_info, fs=fs) as data:
data.update(config)


Expand Down
10 changes: 5 additions & 5 deletions dvc/remote/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,9 +570,9 @@ def _load_config(self):
from dvc.odb.config import CONFIG_FILENAME, load_config, migrate_config
from dvc.odb.versions import ODB_VERSION

config_path = self.tree.path_info / CONFIG_FILENAME
config_path = self.fs.path_info / CONFIG_FILENAME
self._config = load_config(
self.tree.path_info / CONFIG_FILENAME, self.tree
self.fs.path_info / CONFIG_FILENAME, self.fs
)

dos2unix = self.repo.config["core"].get("dos2unix", False)
Expand All @@ -585,12 +585,12 @@ def _load_config(self):
if not dos2unix and self.version != ODB_VERSION.V2:
migrate_config(self._config)
self._config_modified = True
elif not self.tree.exists(config_path):
elif not self.fs.exists(config_path):
self._config_modified = True

def _dump_config(self):
from dvc.odb.config import CONFIG_FILENAME, dump_config

config_path = self.tree.path_info / CONFIG_FILENAME
dump_config(self._config, config_path, self.tree)
config_path = self.fs.path_info / CONFIG_FILENAME
dump_config(self._config, config_path, self.fs)
self._config_modified = False
2 changes: 1 addition & 1 deletion tests/func/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def test_file_md5_crlf(tmp_dir, dos2unix):
tmp_dir.gen("crlf", b"a\r\nb\r\nc")
fs = LocalFileSystem(None, {})
eq = utils.file_md5("cr", fs, enable_d2u=dos2unix) == utils.file_md5(
"crlf", enable_d2u=dos2unix
"crlf", fs, enable_d2u=dos2unix
)
assert eq == dos2unix

Expand Down
6 changes: 3 additions & 3 deletions tests/unit/remote/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def test_hashes_exist(object_exists, traverse, dvc, mocker):
def test_list_hashes_traverse(_path_to_hash, list_hashes, dvc, mocker):
mocker.patch.object(CloudCache, "_load_config")
cache = CloudCache(BaseFileSystem(dvc, {}))
cache.tree.path_info = PathInfo("foo")
cache.fs.path_info = PathInfo("foo")

# parallel traverse
size = 256 / cache.fs.JOBS * cache.fs.LIST_OBJECT_PAGE_SIZE
Expand All @@ -125,7 +125,7 @@ def test_list_hashes_traverse(_path_to_hash, list_hashes, dvc, mocker):
def test_list_hashes(dvc, mocker):
mocker.patch.object(CloudCache, "_load_config")
cache = CloudCache(BaseFileSystem(dvc, {}))
cache.tree.path_info = PathInfo("foo")
cache.fs.path_info = PathInfo("foo")

with mock.patch.object(
cache, "_list_paths", return_value=["12/3456", "bar"]
Expand All @@ -137,7 +137,7 @@ def test_list_hashes(dvc, mocker):
def test_list_paths(dvc, mocker):
mocker.patch.object(CloudCache, "_load_config")
cache = CloudCache(BaseFileSystem(dvc, {}))
cache.tree.path_info = PathInfo("foo")
cache.fs.path_info = PathInfo("foo")

with mock.patch.object(
cache.fs, "walk_files", return_value=[]
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ def test_info_in_broken_git_repo(tmp_dir, dvc, scm, caplog):


def test_caches(tmp_dir, dvc, caplog, mocker):
from dvc.tree.ssh import SSHTree
from dvc.fs.ssh import SSHFileSystem

mocker.patch.object(SSHTree, "exists", return_value=False)
mocker.patch.object(SSHFileSystem, "exists", return_value=False)
tmp_dir.add_remote(
name="sshcache", url="ssh://example.com/path", default=False
)
Expand Down

0 comments on commit 1ce4eae

Please sign in to comment.