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

SwissDataScienceCenter / renku-python / 9058668052

13 May 2024 07:05AM UTC coverage: 77.713% (-8.4%) from 86.115%
9058668052

Pull #3727

github

web-flow
Merge 128d38387 into 050ed61bf
Pull Request #3727: fix: don't fail session launch when gitlab couldn't be reached

15 of 29 new or added lines in 3 files covered. (51.72%)

2594 existing lines in 125 files now uncovered.

23893 of 30745 relevant lines covered (77.71%)

3.2 hits per line

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

87.1
/renku/command/format/tabulate.py
1
# Copyright Swiss Data Science Center (SDSC). A partnership between
2
# École Polytechnique Fédérale de Lausanne (EPFL) and
3
# Eidgenössische Technische Hochschule Zürich (ETHZ).
4
#
5
# Licensed under the Apache License, Version 2.0 (the "License");
6
# you may not use this file except in compliance with the License.
7
# You may obtain a copy of the License at
8
#
9
#     http://www.apache.org/licenses/LICENSE-2.0
10
#
11
# Unless required by applicable law or agreed to in writing, software
12
# distributed under the License is distributed on an "AS IS" BASIS,
13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
# See the License for the specific language governing permissions and
15
# limitations under the License.
16
"""Tabular format helper functions."""
7✔
17

18
from collections import OrderedDict
7✔
19
from operator import attrgetter
7✔
20

21
from renku.core import errors
7✔
22

23

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

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

37
    if not columns:
3✔
38
        raise errors.ParameterError("Columns cannot be empty.")
×
39

40
    columns = [c.lower().strip() for c in columns.split(",") if c]
3✔
41

42
    headers, alignments = _make_headers(columns, columns_mapping, columns_alignments)
3✔
43

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

53
    alignments = alignments if collection else None  # To avoid a tabulate bug
3✔
54

55
    return to_table(collection, headers=headers, colalign=alignments, disable_numparse=True)
3✔
56

57

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

70
        alignment = columns_alignments.get(column, "left")
3✔
71
        alignments.append(alignment)
3✔
72

73
    return headers, alignments
3✔
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

© 2025 Coveralls, Inc