dvcfs: handle NotADirectoryError from datafs.ls (#9746)

* dvc_fs: ignore NotADirectoryError in ls

* deps: bump dvc-data to >= 2.6.0

* add test

---------

Co-authored-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
Dave Berenbaum
2023-07-19 20:54:55 +03:00
committed by GitHub
co-authored by Ruslan Kuprieiev
parent ea5f7d40c1
commit 41194b7975
3 changed files with 12 additions and 2 deletions
+1 -1
View File
@@ -288,7 +288,7 @@ class _DVCFileSystem(AbstractFileSystem): # pylint:disable=abstract-method
dvc_infos = {} dvc_infos = {}
if dvc_fs: if dvc_fs:
dvc_path = _get_dvc_path(dvc_fs, subkey) dvc_path = _get_dvc_path(dvc_fs, subkey)
with suppress(FileNotFoundError): with suppress(FileNotFoundError, NotADirectoryError):
for info in dvc_fs.ls(dvc_path, detail=True): for info in dvc_fs.ls(dvc_path, detail=True):
dvc_infos[dvc_fs.path.name(info["name"])] = info dvc_infos[dvc_fs.path.name(info["name"])] = info
dvc_exists = bool(dvc_infos) or dvc_fs.exists(dvc_path) dvc_exists = bool(dvc_infos) or dvc_fs.exists(dvc_path)
+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>=2.5.0,<2.6.0", "dvc-data>=2.6.0,<2.7.0",
"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",
+10
View File
@@ -162,6 +162,16 @@ def test_isdir_mixed(tmp_dir, dvc):
assert not fs.isfile("dir") assert not fs.isfile("dir")
def test_ls_dirty(tmp_dir, dvc):
tmp_dir.dvc_gen({"data": "data"})
(tmp_dir / "data").unlink()
tmp_dir.gen({"data": {"foo": "foo", "bar": "bar"}})
fs = DVCFileSystem(repo=dvc)
assert set(fs.ls("data")) == {"data/foo", "data/bar"}
@pytest.mark.parametrize( @pytest.mark.parametrize(
"dvcfiles,extra_expected", "dvcfiles,extra_expected",
[ [