Skip to content

Commit

Permalink
list: support tracked file path as a target (#4204)
Browse files Browse the repository at this point in the history
* list: support tracked file path as a target

Fixes #4202

* erepo: add __str__ to improve error readablity

Related to #4202
  • Loading branch information
efiop authored Jul 14, 2020
1 parent c1b04b8 commit 66def03
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
3 changes: 3 additions & 0 deletions dvc/external_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ class BaseExternalRepo:

_local_cache = None

def __str__(self):
return self.url

@property
def local_cache(self):
if hasattr(self, "cache"):
Expand Down
3 changes: 2 additions & 1 deletion dvc/repo/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def _is_cached(out):
return outs

def _get_granular_checksum(self, path, out, remote=None):
assert isinstance(path, PathInfo)
if not self.fetch and not self.stream:
raise FileNotFoundError
dir_cache = out.get_dir_cache(remote=remote)
Expand Down Expand Up @@ -128,7 +129,7 @@ def isdir(self, path):
# for dir checksum, we need to check if this is a file inside the
# directory
try:
self._get_granular_checksum(path, out)
self._get_granular_checksum(path_info, out)
return False
except FileNotFoundError:
return True
Expand Down
30 changes: 30 additions & 0 deletions tests/func/test_ls.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,3 +472,33 @@ def test_ls_granular(erepo_dir):
{"isout": False, "isdir": False, "isexec": False, "path": "2"},
{"isout": False, "isdir": True, "isexec": False, "path": "subdir"},
]


@pytest.mark.parametrize("use_scm", [True, False])
def test_ls_target(erepo_dir, use_scm):
with erepo_dir.chdir():
gen = erepo_dir.scm_gen if use_scm else erepo_dir.dvc_gen
gen(
{
"dir": {
"1": "1",
"2": "2",
"subdir": {"foo": "foo", "bar": "bar"},
}
},
commit="create dir",
)

def _ls(path):
return Repo.ls(os.fspath(erepo_dir), path)

assert _ls(os.path.join("dir", "1")) == [
{"isout": False, "isdir": False, "isexec": False, "path": "1"}
]
assert _ls(os.path.join("dir", "subdir", "foo")) == [
{"isout": False, "isdir": False, "isexec": False, "path": "foo"}
]
assert _ls(os.path.join("dir", "subdir")) == [
{"isdir": False, "isexec": 0, "isout": False, "path": "bar"},
{"isdir": False, "isexec": 0, "isout": False, "path": "foo"},
]
2 changes: 1 addition & 1 deletion tests/func/test_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def test_repotree_cache_save(tmp_dir, dvc, scm, erepo_dir, local_cloud):
# into dvc.cache, not fetched or streamed from a remote
tree = RepoTree(erepo_dir.dvc, stream=True)
expected = [
tree.get_file_hash(erepo_dir / path)
tree.get_file_hash(PathInfo(erepo_dir / path))
for path in ("dir/bar", "dir/subdir/foo")
]

Expand Down

0 comments on commit 66def03

Please sign in to comment.