Skip to content

Commit

Permalink
cleanup index, and add test for used_objs (#6390)
Browse files Browse the repository at this point in the history
  • Loading branch information
skshetry committed Aug 6, 2021
1 parent 3d604a8 commit fd76e09
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
3 changes: 1 addition & 2 deletions dvc/repo/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def outs(self) -> Iterator["Output"]:
yield from stage.outs

@property
def decorated_outputs(self) -> Iterator["Output"]:
def decorated_outs(self) -> Iterator["Output"]:
for output in self.outs:
if output.is_decorated:
yield output
Expand Down Expand Up @@ -218,7 +218,6 @@ def discard(self, stage: "Stage") -> "Index":
return self.remove(stage, ignore_not_existing=True)

def difference(self, stages: Iterable["Stage"]) -> "Index":
# this does not preserve the order
stages_set = set(self.stages) - set(stages)
return Index(self.repo, self.fs, stages=list(stages_set))

Expand Down
3 changes: 0 additions & 3 deletions dvc/repo/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,5 @@ def run(
else:
stage.run(no_commit=no_commit, run_cache=run_cache)

new_index = self.index.add(stage)
new_index.check_graph()

stage.dump(update_lock=not no_exec)
return stage
51 changes: 50 additions & 1 deletion tests/func/test_repo_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def test_deps_outs_getters(tmp_dir, dvc, run_copy_metrics):

assert outputs_equal(index.outs, expected_outs)
assert outputs_equal(index.deps, expected_deps)
assert outputs_equal(index.decorated_outputs, [metrics, plots])
assert outputs_equal(index.decorated_outs, [metrics, plots])
assert outputs_equal(index.metrics, [metrics])
assert outputs_equal(index.plots, [plots])
assert outputs_equal(index.params, [params])
Expand Down Expand Up @@ -245,3 +245,52 @@ def test_skip_graph_checks(dvc, mocker):
dvc._skip_graph_checks = False
Index(dvc).check_graph()
assert mock_build_graph.called


def get_index(dvc, rev):
if rev:
brancher = dvc.brancher(revs=[rev])
if rev != "workspace":
assert next(brancher) == "workspace"
next(brancher)
return Index(dvc)


@pytest.mark.parametrize("rev", ["workspace", "HEAD"])
def test_used_objs(tmp_dir, scm, dvc, run_copy, rev):
from dvc.hash_info import HashInfo

dvc.config["core"]["autostage"] = True
tmp_dir.dvc_gen({"dir": {"subdir": {"file": "file"}}, "foo": "foo"})
run_copy("foo", "bar", name="copy-foo-bar")
scm.commit("commit")

index = get_index(dvc, rev)

expected_objs = [
HashInfo(
name="md5",
value="acbd18db4cc2f85cedef654fccc4a4d8",
size=3,
obj_name="bar",
),
HashInfo(
name="md5",
value="8c7dd922ad47494fc02c388e12c00eac",
obj_name="dir/subdir/file",
),
HashInfo(
name="md5",
value="d28c9e28591aeb7e303dc6772ffa6f6b.dir",
size=4,
nfiles=1,
obj_name="dir",
),
]

assert index.used_objs() == {None: set(expected_objs)}
assert index.used_objs("dir") == {None: set(expected_objs[1:])}
assert index.used_objs(".", recursive=True) == {None: set(expected_objs)}
assert index.used_objs("copy-foo-bar", with_deps=True) == {
None: {expected_objs[0]}
}

0 comments on commit fd76e09

Please sign in to comment.