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

cokelaer / sequana / 7117316673

06 Dec 2023 04:24PM UTC coverage: 75.413% (-0.07%) from 75.482%
7117316673

push

github

cokelaer
Update all codes to fulfill pre-commit hooks

392 of 456 new or added lines in 116 files covered. (85.96%)

1819 existing lines in 87 files now uncovered.

13680 of 18140 relevant lines covered (75.41%)

1.51 hits per line

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

95.65
/sequana/scripts/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 rich_click as click
3✔
15

16
CONTEXT_SETTINGS = {"help_option_names": ["-h", "--help"]}
3✔
17

18
click.rich_click.USE_MARKDOWN = True
3✔
19
click.rich_click.SHOW_METAVARS_COLUMN = False
3✔
20
click.rich_click.APPEND_METAVARS_HELP = True
3✔
21
click.rich_click.STYLE_ERRORS_SUGGESTION = "magenta italic"
3✔
22
click.rich_click.SHOW_ARGUMENTS = True
3✔
23

24

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

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

56
            # call the actual process
57
            self._previous_parser_process(value, state)
3✔
58

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

69

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

81
    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