From 654358010076d1c20d90edbab39733cc27c598e0 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Wed, 31 May 2023 05:00:36 +0300 Subject: [PATCH] dvcfs: don't use datafs isout/isdvc --- dvc/fs/dvc.py | 21 ++++++++++++++------- pyproject.toml | 2 +- tests/unit/fs/test_data.py | 8 -------- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/dvc/fs/dvc.py b/dvc/fs/dvc.py index 6ae1ae360..188ccee0a 100644 --- a/dvc/fs/dvc.py +++ b/dvc/fs/dvc.py @@ -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"] @@ -263,10 +268,10 @@ class _DVCFileSystem(AbstractFileSystem): # pylint:disable=abstract-method 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 @@ -314,7 +319,9 @@ class _DVCFileSystem(AbstractFileSystem): # pylint:disable=abstract-method 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) @@ -370,7 +377,7 @@ class _DVCFileSystem(AbstractFileSystem): # pylint:disable=abstract-method 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 diff --git a/pyproject.toml b/pyproject.toml index 774ba1344..c6a92f66a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", diff --git a/tests/unit/fs/test_data.py b/tests/unit/fs/test_data.py index b6ae9431a..a0d770416 100644 --- a/tests/unit/fs/test_data.py +++ b/tests/unit/fs/test_data.py @@ -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"])