mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-01 23:08:43 +01:00
cleanup index, and add test for used_objs (#6390)
This commit is contained in:
+1
-2
@@ -110,7 +110,7 @@ class Index:
|
||||
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
|
||||
@@ -218,7 +218,6 @@ class 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))
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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])
|
||||
@@ -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]}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user