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

SwissDataScienceCenter / renku-python / 4182482698

pending completion
4182482698

Pull #3320

github-actions

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

20751 of 28900 relevant lines covered (71.8%)

2.47 hits per line

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

87.1
/renku/command/format/tabulate.py
1
# -*- coding: utf-8 -*-
2
#
3
# Copyright 2020 - 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
"""Tabular format helper functions."""
6✔
19

20
from collections import OrderedDict
6✔
21
from operator import attrgetter
6✔
22

23
from renku.core import errors
6✔
24

25

26
def tabulate(collection, columns, columns_mapping, columns_alignments=None, sort=True, reverse=False) -> str:
6✔
27
    """Format collection with a tabular output.
28

29
    Args:
30
        collection: Collection to format.
31
        columns: Columns to show.
32
        columns_mapping: Mapping of collection fields to columns.
33
        columns_alignments: Column alignment (Default value = None).
34
        sort: Whether to sort by first column or not (Default value = True).
35
        reverse: Whether to sort in reverse (Default value = False).
36
    """
37
    from renku.core.util.tabulate import tabulate as to_table
2✔
38

39
    if not columns:
2✔
40
        raise errors.ParameterError("Columns cannot be empty.")
×
41

42
    columns = [c.lower().strip() for c in columns.split(",") if c]
2✔
43

44
    headers, alignments = _make_headers(columns, columns_mapping, columns_alignments)
2✔
45

46
    # Sort based on the first requested field
47
    if sort:
2✔
48
        try:
2✔
49
            attr = list(headers.keys())[0]
2✔
50
            getter = attrgetter(attr)
2✔
51
            collection = sorted(collection, key=getter, reverse=reverse)
2✔
52
        except TypeError:
×
53
            pass
×
54

55
    alignments = alignments if collection else None  # To avoid a tabulate bug
2✔
56

57
    return to_table(collection, headers=headers, colalign=alignments, disable_numparse=True)
2✔
58

59

60
def _make_headers(columns, columns_mapping, columns_alignments):
6✔
61
    columns_alignments = columns_alignments or {}
2✔
62
    headers = OrderedDict()
2✔
63
    alignments = []
2✔
64
    for column in columns:
2✔
65
        if column not in columns_mapping:
2✔
66
            raise errors.ParameterError(
×
67
                'Invalid column name: "{}".\nPossible values: {}'.format(column, ", ".join(columns_mapping))
68
            )
69
        name, display_name = columns_mapping.get(column)
2✔
70
        headers[name] = display_name
2✔
71

72
        alignment = columns_alignments.get(column, "left")
2✔
73
        alignments.append(alignment)
2✔
74

75
    return headers, alignments
2✔
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