• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SwissDataScienceCenter / renku-python / 4182445342

pending completion
4182445342

Pull #3320

github-actions

GitHub
Merge f135d5076 into 0e5906373
Pull Request #3320: chore: fix coveralls comments

12864 of 23835 relevant lines covered (53.97%)

1.18 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

48.0
/renku/command/format/workflow.py
1
# -*- coding: utf-8 -*-
2
#
3
# Copyright 2021 - 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
"""Serializers for workflows."""
3✔
19
import textwrap
3✔
20
from typing import Callable, Dict
3✔
21

22
from renku.command.format.json import dumps
3✔
23
from renku.command.format.tabulate import tabulate
3✔
24

25

26
def tabular(workflows, *, columns=None):
3✔
27
    """Format workflows with a tabular output.
28

29
    Args:
30
        workflows: Workflows to format.
31
        columns: Columns to show (Default value = None).
32

33
    Returns:
34
        Workflows in tabular format.
35
    """
36
    if not columns:
×
37
        columns = "id,name,keywords"
×
38

39
    _create_workflow_short_description(workflows)
×
40

41
    return tabulate(collection=workflows, columns=columns, columns_mapping=WORKFLOW_COLUMNS)
×
42

43

44
def _create_workflow_short_description(workflows):
3✔
45
    for workflow in workflows:
×
46
        lines = textwrap.wrap(workflow.description, width=64, max_lines=5) if workflow.description else []
×
47
        workflow.short_description = "\n".join(lines)
×
48

49

50
def jsonld(workflows, **kwargs):
3✔
51
    """Format workflow as JSON-LD.
52

53
    Args:
54
        workflows: Workflows to convert.
55

56
    Returns:
57
        JSON-LD string of workflows.
58
    """
59
    from renku.command.schema.plan import PlanSchema
×
60

61
    data = [PlanSchema().dump(workflow) for workflow in workflows]
×
62
    return dumps(data, indent=2)
×
63

64

65
def json(workflows, **kwargs):
3✔
66
    """Format workflow as JSON.
67

68
    Args:
69
        workflows: Workflows to convert.
70

71
    Returns:
72
        String of JSON data.
73
    """
74
    from renku.domain_model.workflow.plan import PlanDetailsJson
×
75

76
    data = [PlanDetailsJson().dump(workflow) for workflow in workflows]
×
77
    return dumps(data, indent=2)
×
78

79

80
WORKFLOW_FORMATS: Dict[str, Callable] = {
3✔
81
    "tabular": tabular,
82
    "json-ld": jsonld,
83
    "json": json,
84
}
85
"""Valid formatting options."""
86

87
WORKFLOW_COLUMNS = {
3✔
88
    "id": ("id", "id"),
89
    "name": ("name", None),
90
    "keywords": ("keywords_csv", "keywords"),
91
    "description": ("short_description", "description"),
92
    "command": ("full_command", "command"),
93
}
94

95
WORKFLOW_VISUALIZE_FORMATS = {
3✔
96
    "console": "console",
97
    "dot": "dot",
98
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc