/
rerun.py
90 lines (72 loc) · 2.89 KB
/
rerun.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# -*- coding: utf-8 -*-
#
# Copyright 2018-2021- Swiss Data Science Center (SDSC)
# A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and
# Eidgenössische Technische Hochschule Zürich (ETHZ).
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
r"""Recreate files created by the "run" command.
Recreating files
~~~~~~~~~~~~~~~~
.. image:: _static/asciicasts/rerun.delay.gif
:width: 600
:alt: Rerun workflow
Assume you have run a step 2 that uses a stochastic algorithm, so each run
will be slightly different. The goal is to regenerate output ``C`` several
times to compare the output. In this situation it is not possible to simply
call :ref:`cli-update` since the input file ``A`` has not been modified
after the execution of step 2.
.. code-block:: text
A-[step 1]-B-[step 2*]-C
Recreate a specific output file by running:
.. code-block:: console
$ renku rerun C
If you do not want step 1 to also be rerun, you can specify a starting point
using the ``--from`` parameter:
.. code-block:: console
$ renku rerun --from B C
Note that all other outputs of the executed workflow will be recreated as well.
If the output didn't change, it will be removed from git and re-added to ensure
that the reexecution is properly tracked.
"""
import click
from renku.cli.utils.callback import ClickCallback
from renku.core import errors
@click.command()
@click.option("--dry-run", "-n", is_flag=True, default=False, help="Show a preview of plans that will be executed.")
@click.option(
"--from",
"sources",
type=click.Path(exists=True, dir_okay=False),
multiple=True,
help="Start an execution from this file.",
)
@click.argument("paths", type=click.Path(exists=True, dir_okay=True), nargs=-1, required=True)
def rerun(dry_run, sources, paths):
"""Recreate files generated by a sequence of ``run`` commands."""
from renku.core.commands.format.activity import tabulate_activities
from renku.core.commands.rerun import rerun_command
communicator = ClickCallback()
try:
result = (
rerun_command()
.with_communicator(communicator)
.build()
.execute(dry_run=dry_run, sources=sources, paths=paths)
)
except errors.NothingToExecuteError:
exit(1)
else:
if dry_run:
activities, modified_inputs = result.output
click.echo(tabulate_activities(activities, modified_inputs))