• 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

19.35
/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."""
3✔
19

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

23
from renku.core import errors
3✔
24

25

26
def tabulate(collection, columns, columns_mapping, columns_alignments=None, sort=True, reverse=False) -> str:
3✔
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
×
38

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

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

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

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

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

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

59

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

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

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