-
Notifications
You must be signed in to change notification settings - Fork 29
/
rerun.py
85 lines (73 loc) · 3.21 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
# -*- coding: utf-8 -*-
#
# Copyright 2018-2022- 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.
"""Renku ``rerun`` command."""
from typing import List, Optional
from renku.command.command_builder.command import Command, inject
from renku.core import errors
from renku.core.interface.activity_gateway import IActivityGateway
from renku.core.interface.client_dispatcher import IClientDispatcher
from renku.core.util.os import get_relative_paths
from renku.core.workflow.activity import get_activities_until_paths, sort_activities
from renku.core.workflow.concrete_execution_graph import ExecutionGraph
from renku.core.workflow.execute import execute_workflow_graph
def rerun_command(skip_metadata_update: bool):
"""Recreate files generated by a sequence of ``run`` commands."""
command = Command().command(_rerun).require_migration().require_clean()
if skip_metadata_update:
command = command.with_database(write=False)
else:
command = command.with_database(write=True).with_commit()
return command
@inject.autoparams()
def _rerun(
dry_run: bool,
sources: List[str],
paths: List[str],
provider: str,
config: Optional[str],
client_dispatcher: IClientDispatcher,
activity_gateway: IActivityGateway,
):
"""Rerun a previously run workflow.
Args:
dry_run (bool): Whether or not to actually execute the workflow or just show
what would be executed.
sources (List[str]): Input files to start execution from.
paths (List[str]): Output paths to recreate.
provider (str): Name of the workflow provider to use for execution.
config (str): Path to configuration for the workflow provider.
client_dispatcher (IClientDispatcher): Injected client dispatcher.
activity_gateway (IActivityGateway): Injected activity gateway.
"""
client = client_dispatcher.current_client
sources = sources or []
sources = get_relative_paths(base=client.path, paths=sources)
paths = paths or []
paths = get_relative_paths(base=client.path, paths=paths)
activities = list(
get_activities_until_paths(
paths, sources, activity_gateway=activity_gateway, client_dispatcher=client_dispatcher
)
)
if len(activities) == 0:
raise errors.NothingToExecuteError()
activities = sort_activities(activities)
if dry_run:
return activities, set(sources)
graph = ExecutionGraph([a.plan_with_values for a in activities], virtual_links=True)
execute_workflow_graph(dag=graph.workflow_graph, provider=provider, config=config)