mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
* repro: introduce --keep-going/--ignore to continue on error `-k`/`--keep-going` will skip all dependents of a stage if it fails. It'll still try to reproduce the other dependencies of the pending targets, before it exits with a non-zero status. `--ignore-errors` will treat any error during stage execution as a success, and will continue executing other dependencies as if it succeeded. Exits with 0 even on failure. Also fixes: * --force-downstream used to force everything even if one upstream nodes changed. This used to work when we supported a single targets, but there could be independent pipelines, so we should not force everything if any node changes. Now we'll force reproduce the stage only if one of its dependency changed upstream or it's upstream node was also forced. * Makes `--downstream` more correct, in relation to `--allow-missing` and `--pull`. Now we use an active graph for downstream/upstream logic instead of a subgraph. Note that this does not affect the downstream logic though, as dvc always goes downstream, so subgraph was no different than active graph. The subgraph only did not have the upstream nodes. * add tests * add spacing in the message
72 lines
2.1 KiB
Python
72 lines
2.1 KiB
Python
from itertools import chain
|
|
|
|
from networkx import DiGraph
|
|
from networkx.utils import graphs_equal
|
|
|
|
from dvc.repo.reproduce import get_active_graph, plan_repro
|
|
|
|
|
|
def test_active_graph(mocker):
|
|
n = mocker.sentinel
|
|
n1, n2, n3, n4, n5, n6, n7, n8, n9 = (getattr(n, f"n{i}") for i in range(1, 10))
|
|
edges = {n1: [n2, n3], n2: [n4, n5], n3: [n6, n7], n8: [n9]}
|
|
for node in chain.from_iterable([n, *v] for n, v in edges.items()):
|
|
node.frozen = False
|
|
|
|
g = DiGraph(edges)
|
|
|
|
active = get_active_graph(g)
|
|
assert graphs_equal(g, active)
|
|
|
|
n2.frozen = True
|
|
active = get_active_graph(g)
|
|
assert g.edges() - active.edges() == {(n2, n5), (n2, n4)}
|
|
assert n2 in active
|
|
assert not active.edges() - g.edges()
|
|
assert not graphs_equal(g, active)
|
|
|
|
|
|
def test_repro_plan(M):
|
|
r"""
|
|
1
|
|
/ \
|
|
2 3 8
|
|
/ \ / \ |
|
|
4 5 6 7 9
|
|
"""
|
|
g = DiGraph({1: [2, 3], 2: [4, 5], 3: [6, 7], 8: [9]})
|
|
|
|
assert plan_repro(g) == [4, 5, 2, 6, 7, 3, 1, 9, 8]
|
|
assert plan_repro(g, [1]) == [4, 5, 2, 6, 7, 3, 1]
|
|
assert plan_repro(g, [4], downstream=True) == [4, 2, 1]
|
|
assert plan_repro(g, [8], True) == plan_repro(g, [9], True) == [9, 8]
|
|
assert plan_repro(g, [2, 8], True) == [4, 5, 2, 6, 7, 3, 1, 9, 8]
|
|
assert plan_repro(g, [2, 3], downstream=True) == [
|
|
M.any_of(2, 3),
|
|
M.any_of(2, 3),
|
|
1,
|
|
]
|
|
|
|
|
|
def test_number_reproduces(tmp_dir, dvc, mocker):
|
|
mock = mocker.Mock(return_value=None)
|
|
tmp_dir.dvc_gen({"pre-foo": "pre-foo"})
|
|
|
|
dvc.stage.add(name="echo-foo", outs=["foo"], cmd="echo foo > foo", verify=False)
|
|
dvc.stage.add(
|
|
name="echo-bar", deps=["foo"], outs=["bar"], cmd="echo bar > bar", verify=False
|
|
)
|
|
dvc.stage.add(
|
|
name="echo-baz", deps=["foo"], outs=["baz"], cmd="echo baz > baz", verify=False
|
|
)
|
|
dvc.stage.add(
|
|
name="echo-boop",
|
|
deps=["bar"],
|
|
outs=["boop"],
|
|
cmd="echo boop > boop",
|
|
verify=False,
|
|
)
|
|
|
|
dvc.reproduce(all_pipelines=True, repro_fn=mock)
|
|
assert mock.call_count == 5
|