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

cokelaer / sequana / 6851111417

13 Nov 2023 02:09PM UTC coverage: 73.547%. Remained the same
6851111417

push

github

cokelaer
Refactorised the coverage tools (sequana_coverage)

160 of 296 new or added lines in 27 files covered. (54.05%)

496 existing lines in 25 files now uncovered.

13245 of 18009 relevant lines covered (73.55%)

2.2 hits per line

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

95.24
/sequana/scripts/main/utils.py
1
#  This file is part of Sequana software
2
#
3
#  Copyright (c) 2016-2020 - Sequana Development Team
4
#
5
#  Distributed under the terms of the 3-clause BSD license.
6
#  The full license is in the LICENSE file, distributed with this software.
7
#
8
#  website: https://github.com/sequana/sequana
9
#  documentation: http://sequana.readthedocs.io
10
#
11
##############################################################################
12
import functools
3✔
13

14
import click
3✔
15
import rich_click as click
3✔
16

17

18
CONTEXT_SETTINGS = {"help_option_names": ["-h", "--help"]}
3✔
19

20

21
# This is a recipe from https://stackoverflow.com/questions/48391777/nargs-equivalent-for-options-in-click
22
# to allow command line such as
23
# sequana enrichment-panther --ontologies MF BP CC
24
class OptionEatAll(click.Option):
3✔
25
    def __init__(self, *args, **kwargs):
3✔
26
        self.save_other_options = kwargs.pop("save_other_options", True)
3✔
27
        nargs = kwargs.pop("nargs", -1)
3✔
28
        assert nargs == -1, "nargs, if set, must be -1 not {}".format(nargs)
3✔
29
        super(OptionEatAll, self).__init__(*args, **kwargs)
3✔
30
        self._previous_parser_process = None
3✔
31
        self._eat_all_parser = None
3✔
32

33
    def add_to_parser(self, parser, ctx):
3✔
34
        def parser_process(value, state):
3✔
35
            # method to hook to the parser.process
36
            done = False
3✔
37
            value = [value]
3✔
38
            if self.save_other_options:
3✔
39
                # grab everything up to the next option
40
                while state.rargs and not done:
3✔
41
                    for prefix in self._eat_all_parser.prefixes:
3✔
42
                        if state.rargs[0].startswith(prefix):
3✔
43
                            done = True
3✔
44
                    if not done:
3✔
45
                        value.append(state.rargs.pop(0))
3✔
46
            else:
47
                # grab everything remaining
UNCOV
48
                value += state.rargs
×
49
                state.rargs[:] = []
×
50
            value = tuple(value)
3✔
51

52
            # call the actual process
53
            self._previous_parser_process(value, state)
3✔
54

55
        retval = super(OptionEatAll, self).add_to_parser(parser, ctx)
3✔
56
        for name in self.opts:
3✔
57
            our_parser = parser._long_opt.get(name) or parser._short_opt.get(name)
3✔
58
            if our_parser:
3✔
59
                self._eat_all_parser = our_parser
3✔
60
                self._previous_parser_process = our_parser.process
3✔
61
                our_parser.process = parser_process
3✔
62
                break
3✔
63
        return retval
3✔
64

65

66
# This can be used by all commands as a simple decorator
67
def common_logger(func):
3✔
68
    @click.option(
3✔
69
        "--logger",
70
        default="INFO",
71
        type=click.Choice(["INFO", "DEBUG", "WARNING", "CRITICAL", "ERROR"]),
72
    )
73
    @functools.wraps(func)
3✔
74
    def wrapper(*args, **kwargs):
3✔
75
        return func(*args, **kwargs)
3✔
76

77
    return wrapper
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

© 2026 Coveralls, Inc