|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# |
| 3 | +# Copyright 2018-2022- Swiss Data Science Center (SDSC) |
| 4 | +# A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and |
| 5 | +# Eidgenössische Technische Hochschule Zürich (ETHZ). |
| 6 | +# |
| 7 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +# you may not use this file except in compliance with the License. |
| 9 | +# You may obtain a copy of the License at |
| 10 | +# |
| 11 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, software |
| 14 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +# See the License for the specific language governing permissions and |
| 17 | +# limitations under the License. |
| 18 | +"""Renku workflow update.""" |
| 19 | + |
| 20 | +from pathlib import Path |
| 21 | +from typing import List, Optional |
| 22 | + |
| 23 | +from pydantic import validate_arguments |
| 24 | + |
| 25 | +from renku.core import errors |
| 26 | +from renku.core.errors import ParameterError |
| 27 | +from renku.core.util.os import get_relative_paths |
| 28 | +from renku.core.workflow.activity import ( |
| 29 | + get_all_modified_and_deleted_activities_and_entities, |
| 30 | + get_downstream_generating_activities, |
| 31 | + is_activity_valid, |
| 32 | + sort_activities, |
| 33 | +) |
| 34 | +from renku.core.workflow.execute import execute_workflow_graph |
| 35 | +from renku.core.workflow.model.concrete_execution_graph import ExecutionGraph |
| 36 | +from renku.domain_model.project_context import project_context |
| 37 | + |
| 38 | + |
| 39 | +@validate_arguments(config=dict(arbitrary_types_allowed=True)) |
| 40 | +def update( |
| 41 | + update_all: bool, |
| 42 | + dry_run: bool, |
| 43 | + ignore_deleted: bool, |
| 44 | + provider: str, |
| 45 | + config: Optional[str], |
| 46 | + paths: Optional[List[str]] = None, |
| 47 | +): |
| 48 | + """Update stale generated outputs.""" |
| 49 | + if paths and update_all: |
| 50 | + raise ParameterError("Cannot use PATHS and --all/-a at the same time.") |
| 51 | + |
| 52 | + paths = paths or [] |
| 53 | + paths = get_relative_paths(base=project_context.path, paths=[Path.cwd() / p for p in paths]) |
| 54 | + |
| 55 | + modified, _, _ = get_all_modified_and_deleted_activities_and_entities(project_context.repository) |
| 56 | + modified_activities = {a for a, _ in modified if not a.deleted and is_activity_valid(a)} |
| 57 | + modified_paths = {e.path for _, e in modified} |
| 58 | + |
| 59 | + activities = get_downstream_generating_activities( |
| 60 | + starting_activities=modified_activities, |
| 61 | + paths=paths, |
| 62 | + ignore_deleted=ignore_deleted, |
| 63 | + project_path=project_context.path, |
| 64 | + ) |
| 65 | + |
| 66 | + if len(activities) == 0: |
| 67 | + raise errors.NothingToExecuteError() |
| 68 | + |
| 69 | + # NOTE: When updating we only want to eliminate activities that are overridden, not their parents |
| 70 | + activities = sort_activities(activities, remove_overridden_parents=False) |
| 71 | + if dry_run: |
| 72 | + return activities, modified_paths |
| 73 | + |
| 74 | + graph = ExecutionGraph([a.plan_with_values for a in activities], virtual_links=True) |
| 75 | + execute_workflow_graph(dag=graph.workflow_graph, provider=provider, config=config) |
0 commit comments