dvcfs: don't use datafs isout/isdvc

This commit is contained in:
Ruslan Kuprieiev
2023-05-31 23:14:28 +03:00
parent a1b891ce01
commit 6543580100
3 changed files with 15 additions and 16 deletions
+14 -7
View File
@@ -38,12 +38,17 @@ def _is_dvc_file(fname):
return is_valid_filename(fname) or fname == DvcIgnore.DVCIGNORE_FILE 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 from . import utils
ret = {"repo": repo} ret = {"repo": repo}
if dvc_info: 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["dvc_info"] = dvc_info
ret["type"] = dvc_info["type"] ret["type"] = dvc_info["type"]
ret["size"] = dvc_info["size"] ret["size"] = dvc_info["size"]
@@ -263,10 +268,10 @@ class _DVCFileSystem(AbstractFileSystem): # pylint:disable=abstract-method
def isdvc(self, path, **kwargs) -> bool: def isdvc(self, path, **kwargs) -> bool:
"""Is this entry dvc-tracked?""" """Is this entry dvc-tracked?"""
key = self._get_key_from_relative(path) try:
_, dvc_fs, subkey = self._get_subrepo_info(key) return self.info(path).get("dvc_info", {}).get("isout", False)
dvc_path = _get_dvc_path(dvc_fs, subkey) except FileNotFoundError:
return dvc_fs is not None and dvc_fs.isdvc(dvc_path, **kwargs) return False
def ls( # pylint: disable=arguments-differ # noqa: C901 def ls( # pylint: disable=arguments-differ # noqa: C901
self, path, detail=True, dvc_only=False, **kwargs self, path, detail=True, dvc_only=False, **kwargs
@@ -314,7 +319,9 @@ class _DVCFileSystem(AbstractFileSystem): # pylint:disable=abstract-method
continue continue
entry_path = self.path.join(path, name) 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 info["name"] = entry_path
infos.append(info) infos.append(info)
paths.append(entry_path) paths.append(entry_path)
@@ -370,7 +377,7 @@ class _DVCFileSystem(AbstractFileSystem): # pylint:disable=abstract-method
if not dvc_info and not fs_info: if not dvc_info and not fs_info:
raise FileNotFoundError raise FileNotFoundError
info = _merge_info(repo, fs_info, dvc_info) info = _merge_info(repo, subkey, fs_info, dvc_info)
info["name"] = path info["name"] = path
return info return info
+1 -1
View File
@@ -34,7 +34,7 @@ dependencies = [
"configobj>=5.0.6", "configobj>=5.0.6",
"distro>=1.3", "distro>=1.3",
"dpath<3,>=2.1.0", "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-http>=2.29.0",
"dvc-render>=0.3.1,<1", "dvc-render>=0.3.1,<1",
"dvc-studio-client>=0.9.2,<1", "dvc-studio-client>=0.9.2,<1",
-8
View File
@@ -209,14 +209,6 @@ def test_walk_not_a_dir(tmp_dir, dvc):
pass 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): def test_get_hash_file(tmp_dir, dvc):
tmp_dir.dvc_gen({"foo": "foo"}) tmp_dir.dvc_gen({"foo": "foo"})
fs = DataFileSystem(index=dvc.index.data["repo"]) fs = DataFileSystem(index=dvc.index.data["repo"])