Skip to content

Commit

Permalink
dvcfs: don't use datafs isout/isdvc
Browse files Browse the repository at this point in the history
  • Loading branch information
efiop committed May 31, 2023
1 parent a1b891c commit 6543580
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
21 changes: 14 additions & 7 deletions dvc/fs/dvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,17 @@ def _is_dvc_file(fname):
return is_valid_filename(fname) or fname == DvcIgnore.DVCIGNORE_FILE


def _merge_info(repo, fs_info, dvc_info):
def _merge_info(repo, key, fs_info, dvc_info):
from . import utils

ret = {"repo": repo}

if dvc_info:
dvc_info["isout"] = any(
(len(out_key) <= len(key) and key[: len(out_key)] == out_key)
for out_key in repo.index.data_keys["repo"]
)
dvc_info["isdvc"] = dvc_info["isout"]
ret["dvc_info"] = dvc_info
ret["type"] = dvc_info["type"]
ret["size"] = dvc_info["size"]
Expand Down Expand Up @@ -263,10 +268,10 @@ def _open(

def isdvc(self, path, **kwargs) -> bool:
"""Is this entry dvc-tracked?"""
key = self._get_key_from_relative(path)
_, dvc_fs, subkey = self._get_subrepo_info(key)
dvc_path = _get_dvc_path(dvc_fs, subkey)
return dvc_fs is not None and dvc_fs.isdvc(dvc_path, **kwargs)
try:
return self.info(path).get("dvc_info", {}).get("isout", False)
except FileNotFoundError:
return False

def ls( # pylint: disable=arguments-differ # noqa: C901
self, path, detail=True, dvc_only=False, **kwargs
Expand Down Expand Up @@ -314,7 +319,9 @@ def ls( # pylint: disable=arguments-differ # noqa: C901
continue

entry_path = self.path.join(path, name)
info = _merge_info(repo, fs_infos.get(name), dvc_infos.get(name))
info = _merge_info(
repo, (*subkey, name), fs_infos.get(name), dvc_infos.get(name)
)
info["name"] = entry_path
infos.append(info)
paths.append(entry_path)
Expand Down Expand Up @@ -370,7 +377,7 @@ def _info( # noqa: C901, PLR0912
if not dvc_info and not fs_info:
raise FileNotFoundError

info = _merge_info(repo, fs_info, dvc_info)
info = _merge_info(repo, subkey, fs_info, dvc_info)
info["name"] = path
return info

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ dependencies = [
"configobj>=5.0.6",
"distro>=1.3",
"dpath<3,>=2.1.0",
"dvc-data>=0.51.0,<0.52",
"dvc-data>=0.53.0,<0.54",
"dvc-http>=2.29.0",
"dvc-render>=0.3.1,<1",
"dvc-studio-client>=0.9.2,<1",
Expand Down
8 changes: 0 additions & 8 deletions tests/unit/fs/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,6 @@ def test_walk_not_a_dir(tmp_dir, dvc):
pass


def test_isdvc(tmp_dir, dvc):
tmp_dir.gen({"foo": "foo", "bar": "bar"})
dvc.add("foo")
fs = DataFileSystem(index=dvc.index.data["repo"])
assert fs.isdvc("foo")
assert not fs.isdvc("bar")


def test_get_hash_file(tmp_dir, dvc):
tmp_dir.dvc_gen({"foo": "foo"})
fs = DataFileSystem(index=dvc.index.data["repo"])
Expand Down

0 comments on commit 6543580

Please sign in to comment.