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

nbiotcloud / ucdp / 18093583454

29 Sep 2025 10:16AM UTC coverage: 90.562% (-6.1%) from 96.647%
18093583454

push

github

web-flow
Merge pull request #132 from nbiotcloud/update-deps

update dependencies

4673 of 5160 relevant lines covered (90.56%)

10.86 hits per line

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

80.95
/src/ucdp/cliutil.py
1
#
2
# MIT License
3
#
4
# Copyright (c) 2024-2025 nbiotcloud
5
#
6
# Permission is hereby granted, free of charge, to any person obtaining a copy
7
# of this software and associated documentation files (the "Software"), to deal
8
# in the Software without restriction, including without limitation the rights
9
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
# copies of the Software, and to permit persons to whom the Software is
11
# furnished to do so, subject to the following conditions:
12
#
13
# The above copyright notice and this permission notice shall be included in all
14
# copies or substantial portions of the Software.
15
#
16
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
# SOFTWARE.
23
#
24

25
"""Command Line Interface - Utilities."""
26

27
from collections.abc import Iterator
12✔
28
from logging import FATAL, getLogger
12✔
29
from pathlib import Path
12✔
30

31
import click
12✔
32

33
from ucdp.finder import find
12✔
34
from ucdp.pathutil import improved_glob
12✔
35

36
PathType = click.Path(path_type=Path)
12✔
37

38

39
def auto_top(ctx, param, incomplete):
12✔
40
    """Autocompletion for TOP."""
41
    getLogger().setLevel(FATAL)
12✔
42
    infos = find(patterns=[f"{incomplete}*"], glob=True)
12✔
43
    return [str(info.topmodref) for info in infos]
12✔
44

45

46
def auto_path(ctr, param, incomplete):
12✔
47
    """Autocompletion for Paths."""
48
    return [str(path) for path in improved_glob(Path(f"{incomplete}*"))]
12✔
49

50

51
arg_top = click.argument("top", envvar="UCDP_TOP", shell_complete=auto_top)
12✔
52
arg_tops = click.argument("tops", nargs=-1, envvar="UCDP_TOP", shell_complete=auto_top)
12✔
53
opt_topsfile = click.option(
12✔
54
    "--tops-file",
55
    type=click.Path(path_type=Path),
56
    default=[],
57
    multiple=True,
58
    help="File with Top Module References",
59
)
60

61
opt_path = click.option(
12✔
62
    "--path",
63
    "-p",
64
    default=[],
65
    multiple=True,
66
    envvar="UCDP_PATH",
67
    type=click.Path(path_type=Path),
68
    shell_complete=auto_path,
69
    help="""
70
Search Path For Data Model And Template Files.
71
This option can be specified multiple times.
72
Environment Variable 'UCDP_PATH'.
73
""",
74
)
75
opt_filelist = click.option(
12✔
76
    "--filelist",
77
    "-f",
78
    multiple=True,
79
    help="Filelist Names. Environment Variable 'UCDP_FILELIST'.",
80
    envvar="UCDP_FILELIST",
81
)
82
opt_target = click.option(
12✔
83
    "--target",
84
    "-t",
85
    help="Filter File List for Target. Environment Variable 'UCDP_TARGET'.",
86
    envvar="UCDP_TARGET",
87
)
88
opt_show_diff = click.option(
12✔
89
    "--show-diff",
90
    "-s",
91
    default=False,
92
    is_flag=True,
93
    help="Show What Changed. Environment Variable 'UCDP_SHOW_DIFF'.",
94
    envvar="UCDP_SHOW_DIFF",
95
)
96
opt_maxlevel = click.option("--maxlevel", "-L", type=int, help="Limit to maximum number of hierarchy levels.")
12✔
97
opt_dry_run = click.option("--dry-run", default=False, is_flag=True, help="Do nothing.")
12✔
98
opt_maxworkers = click.option(
12✔
99
    "--maxworkers",
100
    "-J",
101
    type=int,
102
    help="Maximum Number of Processes.",
103
    envvar="UCDP_MAXWORKERS",
104
)
105
opt_defines = click.option(
12✔
106
    "--define",
107
    "-D",
108
    multiple=True,
109
    type=str,
110
    help="Defines set on the datamodel. Environment Variable 'UCDP_DEFINES'",
111
    envvar="UCDP_DEFINES",
112
)
113
opt_file = click.option(
12✔
114
    "--file",
115
    "-o",
116
    type=click.File("w"),
117
    shell_complete=auto_path,
118
    help="Output to file instead of STDOUT",
119
)
120
opt_filepath = click.option(
12✔
121
    "--file",
122
    "-o",
123
    type=click.Path(path_type=Path),
124
    shell_complete=auto_path,
125
    help="Output to file instead of STDOUT",
126
)
127
opt_tag = click.option(
12✔
128
    "--tag",
129
    "-G",
130
    default=[],
131
    multiple=True,
132
    help="Filter Modules by Tag Name or Wildcard.",
133
)
134
arg_template_filepaths = click.argument(
12✔
135
    "template_filepaths",
136
    type=PathType,
137
    shell_complete=auto_path,
138
    nargs=-1,
139
    envvar="UCDP_TEMPLATE_FILEPATHS",
140
)
141
opt_local = click.option(
12✔
142
    "--local/--no-local",
143
    "-l/-L",
144
    default=True,
145
    is_flag=True,
146
    help="List local/non-local modules only. Selected by default.",
147
)
148
opt_check = click.option(
12✔
149
    "--check",
150
    default=False,
151
    is_flag=True,
152
    help="Report an error if any file changes.",
153
)
154
opt_create = click.option(
12✔
155
    "--create",
156
    "-c",
157
    default=False,
158
    is_flag=True,
159
    help="Create missing inplace files.",
160
)
161
opt_clean = click.option(
12✔
162
    "--clean",
163
    "-n",
164
    default=False,
165
    is_flag=True,
166
    help="Remove obsolete fully-generated files.",
167
)
168

169

170
def defines2data(defines: list[str]) -> dict[str, str]:
12✔
171
    """Convert defines to data."""
172
    return dict(define.split("=", 1) if "=" in define else (define, None) for define in defines)
×
173

174

175
def read_file(filepath: Path) -> Iterator[str]:
12✔
176
    """Read File."""
177
    with filepath.open() as file:
×
178
        for line in file:
×
179
            line = line.strip()  # noqa: PLW2901
×
180
            if line.startswith("#"):
×
181
                continue
×
182
            if line:
×
183
                yield line
×
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