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

nbiotcloud / ucdp / 18093583429

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

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

65.49
/src/ucdp/cli.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."""
26

27
import logging
12✔
28
import sys
12✔
29
from collections import defaultdict
12✔
30
from collections.abc import Iterable
12✔
31
from logging import StreamHandler
12✔
32
from pathlib import Path
12✔
33
from typing import Literal
12✔
34

35
import click
12✔
36
from click_bash42_completion import patch
12✔
37
from pydantic import BaseModel, ConfigDict
12✔
38
from rich import box
12✔
39
from rich.console import Console
12✔
40
from rich.logging import RichHandler
12✔
41
from rich.pretty import pprint
12✔
42
from rich.table import Table
12✔
43

44
from ._cligroup import MainGroup
12✔
45
from ._logging import HasErrorHandler
12✔
46
from .cache import CACHE
12✔
47
from .cliutil import (
12✔
48
    PathType,
49
    arg_template_filepaths,
50
    arg_top,
51
    arg_tops,
52
    auto_path,
53
    defines2data,
54
    opt_check,
55
    opt_clean,
56
    opt_create,
57
    opt_defines,
58
    opt_dry_run,
59
    opt_file,
60
    opt_filelist,
61
    opt_filepath,
62
    opt_local,
63
    opt_maxlevel,
64
    opt_maxworkers,
65
    opt_path,
66
    opt_show_diff,
67
    opt_tag,
68
    opt_target,
69
    opt_topsfile,
70
    read_file,
71
)
72
from .consts import PATH
12✔
73
from .create import TB_MAP, TYPE_CHOICES, CreateInfo
12✔
74
from .create import create as create_
12✔
75
from .fileset import FileSet
12✔
76
from .finder import find
12✔
77
from .generate import Generator, clean, get_makolator, render_generate, render_inplace
12✔
78
from .iterutil import namefilter
12✔
79
from .loader import load
12✔
80
from .modfilelist import iter_modfilelists
12✔
81
from .modtopref import PAT_TOPMODREF, TopModRef
12✔
82
from .pathutil import absolute, relative
12✔
83
from .top import Top
12✔
84
from .util import LOGGER, guess_path
12✔
85

86
patch()
12✔
87

88

89
_LOGLEVELMAP = {
12✔
90
    0: logging.WARNING,
91
    1: logging.INFO,
92
    2: logging.DEBUG,
93
}
94

95

96
class Ctx(BaseModel):
12✔
97
    """Command Line Context."""
98

99
    model_config = ConfigDict(
12✔
100
        arbitrary_types_allowed=True,
101
    )
102

103
    console: Console
12✔
104
    has_error_handler: HasErrorHandler | None = None
12✔
105

106
    verbose: int = 0
12✔
107
    no_cache: bool = False
12✔
108
    no_color: bool | None = None
12✔
109

110
    @staticmethod
12✔
111
    def create(no_color: bool | None = None, **kwargs) -> "Ctx":
12✔
112
        """Create."""
113
        console = Console(log_time=False, log_path=False, no_color=no_color)
12✔
114
        has_error_handler = HasErrorHandler()
12✔
115
        return Ctx(console=console, has_error_handler=has_error_handler, no_color=no_color, **kwargs)
12✔
116

117
    def __enter__(self):
12✔
118
        # Logging
119
        level = _LOGLEVELMAP.get(self.verbose, logging.DEBUG)
12✔
120
        if not self.no_color:
12✔
121
            handler = RichHandler(
12✔
122
                show_time=False,
123
                show_path=False,
124
                rich_tracebacks=True,
125
                console=Console(stderr=True, no_color=self.no_color),
126
            )
127
            format_ = "%(message)s"
12✔
128
        else:
129
            handler = StreamHandler(stream=sys.stderr)
×
130
            format_ = "%(levelname)s %(message)s"
×
131
        handlers = [handler, self.has_error_handler]
12✔
132
        logging.basicConfig(level=level, format=format_, handlers=handlers)
12✔
133

134
        # Cache
135
        if self.no_cache:
12✔
136
            CACHE.disable()
×
137

138
        return self
12✔
139

140
    def __exit__(self, exc_type, exc_value, tb):
12✔
141
        if exc_type or self.has_error_handler.has_errors:
12✔
142
            if exc_type is KeyboardInterrupt:
×
143
                self.console.print("[red]Aborted.")
×
144
            else:
145
                self.console.print("[red][bold]Failed.")
×
146
            sys.exit(1)
×
147

148

149
@click.group(cls=MainGroup, context_settings={"help_option_names": ["-h", "--help"]})
12✔
150
@click.option("-v", "--verbose", count=True, help="Increase Verbosity.")
12✔
151
@click.option("-C", "--no-cache", is_flag=True, help="Disable Caching.")
12✔
152
@click.option("--no-color", is_flag=True, help="Disable Coloring.", envvar="UCDP_NO_COLOR")
12✔
153
@click.version_option()
12✔
154
@click.pass_context
12✔
155
def ucdp(ctx, verbose=0, no_cache=False, no_color=False):
12✔
156
    """Unified Chip Design Platform."""
157
    ctx.obj = ctx.with_resource(Ctx.create(verbose=verbose, no_cache=no_cache, no_color=no_color))
12✔
158

159

160
pass_ctx = click.make_pass_decorator(Ctx)
12✔
161

162

163
def get_group(help=None):  # pragma: no cover
164
    """Create Command Group."""
165

166
    @click.group(help=help)
167
    @click.pass_context
168
    def group(ctx):
169
        ctx.obj = Ctx(console=Console(log_time=False, log_path=False))
170

171
    return group
172

173

174
def load_top(ctx: Ctx, top: str | TopModRef, paths: Iterable[str | Path], quiet: bool = False) -> Top:
12✔
175
    """Load Top Module."""
176
    lpaths = [Path(path) for path in paths]
×
177
    # Check if top seems to be some kind of file path
178
    topmodref = TopModRef.cast(guess_path(top) or top) if isinstance(top, str) else top
×
179
    if quiet:
×
180
        return load(topmodref, paths=lpaths)
×
181
    with ctx.console.status(f"Loading '{topmodref!s}'"):
×
182
        result = load(topmodref, paths=lpaths)
×
183
    ctx.console.log(f"'{topmodref!s}' checked.")
×
184
    return result
×
185

186

187
@ucdp.command(
12✔
188
    help=f"""
189
Load Data Model and Check.
190

191
TOP: Top Module. {PAT_TOPMODREF}. Environment Variable 'UCDP_TOP'
192
"""
193
)
194
@arg_top
12✔
195
@opt_path
12✔
196
@click.option("--stat", default=False, is_flag=True, help="Show Statistics.")
12✔
197
@pass_ctx
12✔
198
def check(ctx, top, path, stat=False):
12✔
199
    """Check."""
200
    top = load_top(ctx, top, path)
×
201
    if stat:
×
202
        print("Statistics:")
×
203
        for name, value in top.get_stat().items():
×
204
            print(f"  {name}: {value}")
×
205

206

207
@ucdp.command(
12✔
208
    help=f"""
209
Load Data Model and Generate Files.
210

211
TOP: Top Module. {PAT_TOPMODREF}. Environment Variable 'UCDP_TOP'
212
"""
213
)
214
@arg_tops
12✔
215
@opt_path
12✔
216
@opt_filelist
12✔
217
@opt_target
12✔
218
@opt_show_diff
12✔
219
@opt_maxworkers
12✔
220
@opt_defines
12✔
221
@opt_local
12✔
222
@opt_topsfile
12✔
223
@opt_check
12✔
224
@opt_create
12✔
225
@opt_clean
12✔
226
@pass_ctx
12✔
227
def gen(
12✔
228
    ctx,
229
    tops,
230
    path,
231
    filelist,
232
    target=None,
233
    show_diff=False,
234
    maxworkers=None,
235
    define=None,
236
    local=None,
237
    check=False,
238
    create=False,
239
    clean=False,
240
    tops_file=None,
241
):
242
    """Generate."""
243
    tops = list(tops)
×
244
    for filepath in tops_file or []:
×
245
        tops.extend(read_file(filepath))
×
246
    makolator = get_makolator(show_diff=show_diff, paths=path, create=create)
×
247
    data = defines2data(define)
×
248
    filelist = filelist or ["*"]
×
249
    with Generator(makolator=makolator, maxworkers=maxworkers, check=check) as generator:
×
250
        for info in find(path, patterns=tuple(tops), local=local, is_top=True):
×
251
            try:
×
252
                top = load_top(ctx, info.topmodref, path)
×
253
            except Exception as exc:
×
254
                LOGGER.warning(f"Cannot load '{info.topmodref}'")
×
255
                LOGGER.warning(str(exc))
×
256
                LOGGER.warning(f"Debug with 'ucdp check {info.topmodref}'")
×
257
                continue
×
258
            for item in filelist:
×
259
                generator.generate(top, item, target=target, data=data, clean=clean)
×
260

261

262
@ucdp.command(
12✔
263
    help=f"""
264
Load Data Model and Render Template and Create File.
265

266
TOP: Top Module. {PAT_TOPMODREF}. Environment Variable 'UCDP_TOP'
267

268
TEMPLATE_FILEPATHS: Templates to render. Environment Variable 'UCDP_TEMPLATE_FILEPATHS'
269
                    Templates in `templates` folders are found automatically.
270

271
GENFILE: Generated File.
272
"""
273
)
274
@arg_top
12✔
275
@opt_path
12✔
276
@arg_template_filepaths
12✔
277
@click.argument("genfile", type=PathType, shell_complete=auto_path, nargs=1)
12✔
278
@opt_show_diff
12✔
279
@opt_defines
12✔
280
@opt_create
12✔
281
@pass_ctx
12✔
282
def rendergen(ctx, top, path, template_filepaths, genfile, show_diff=False, define=None, create=False):
12✔
283
    """Render Generate."""
284
    top = load_top(ctx, top, path)
×
285
    makolator = get_makolator(show_diff=show_diff, paths=path, create=create)
×
286
    data = defines2data(define)
×
287
    render_generate(top, template_filepaths, genfile=genfile, makolator=makolator, data=data)
×
288

289

290
@ucdp.command(
12✔
291
    help=f"""
292
Load Data Model and Render Template and Update File.
293

294
TOP: Top Module. {PAT_TOPMODREF}. Environment Variable 'UCDP_TOP'
295

296
TEMPLATE_FILEPATHS: Templates to render. Environment Variable 'UCDP_TEMPLATE_FILEPATHS'
297
                    Templates in `templates` folders are found automatically.
298

299
INPLACEFILE: Inplace File.
300
"""
301
)
302
@arg_top
12✔
303
@opt_path
12✔
304
@arg_template_filepaths
12✔
305
@click.argument("inplacefile", type=PathType, shell_complete=auto_path, nargs=1)
12✔
306
@opt_show_diff
12✔
307
@opt_defines
12✔
308
@opt_create
12✔
309
@click.option("--ignore_unknown", "-i", default=False, is_flag=True, help="Ignore Unknown Placeholder.")
12✔
310
@pass_ctx
12✔
311
def renderinplace(
12✔
312
    ctx, top, path, template_filepaths, inplacefile, show_diff=False, define=None, ignore_unknown=False, create=False
313
):
314
    """Render Inplace."""
315
    top = load_top(ctx, top, path)
×
316
    makolator = get_makolator(show_diff=show_diff, paths=path, create=create)
×
317
    data = defines2data(define)
×
318
    render_inplace(
×
319
        top,
320
        template_filepaths,
321
        inplacefile=inplacefile,
322
        makolator=makolator,
323
        data=data,
324
        ignore_unknown=ignore_unknown,
325
    )
326

327

328
@ucdp.command(
12✔
329
    help=f"""
330
Load Data Model and REMOVE Generated Files.
331

332
TOP: Top Module. {PAT_TOPMODREF}. Environment Variable 'UCDP_TOP'
333
"""
334
)
335
@arg_top
12✔
336
@opt_path
12✔
337
@opt_filelist
12✔
338
@opt_target
12✔
339
@opt_show_diff
12✔
340
@opt_dry_run
12✔
341
@opt_maxworkers
12✔
342
@pass_ctx
12✔
343
def cleangen(ctx, top, path, filelist, target=None, show_diff=False, maxworkers=None, dry_run=False):
12✔
344
    """Clean Generated Files."""
345
    top = load_top(ctx, top, path)
×
346
    makolator = get_makolator(show_diff=show_diff, paths=path)
×
347
    for item in filelist or ["*"]:
×
348
        clean(top, item, target=target, makolator=makolator, maxworkers=maxworkers, dry_run=dry_run)
×
349

350

351
@ucdp.command(
12✔
352
    help=f"""
353
Load Data Model and Generate File List.
354

355
TOP: Top Module. {PAT_TOPMODREF}. Environment Variable 'UCDP_TOP'
356
"""
357
)
358
@arg_top
12✔
359
@opt_path
12✔
360
@opt_filelist
12✔
361
@opt_target
12✔
362
@opt_file
12✔
363
@pass_ctx
12✔
364
def filelist(ctx, top, path, filelist, target=None, file=None):
12✔
365
    """File List."""
366
    # Load quiet, otherwise stdout is messed-up
367
    top = load_top(ctx, top, path, quiet=True)
×
368
    for item in filelist or ["*"]:
×
369
        fileset = FileSet.from_mod(top.mod, item, target=target)
×
370
        for line in fileset:
×
371
            print(line, file=file)
×
372

373

374
@ucdp.command(
12✔
375
    help=f"""
376
Load Data Model and Show File Information
377

378
TOP: Top Module. {PAT_TOPMODREF}. Environment Variable 'UCDP_TOP'
379
"""
380
)
381
@arg_top
12✔
382
@opt_path
12✔
383
@opt_filelist
12✔
384
@opt_target
12✔
385
@opt_maxlevel
12✔
386
@click.option("--minimal", "-m", default=False, is_flag=True, help="Skip defaults.")
12✔
387
@opt_file
12✔
388
@pass_ctx
12✔
389
def fileinfo(ctx, top, path, filelist, target=None, maxlevel=None, minimal=False, file=None):
12✔
390
    """File List."""
391
    # Load quiet, otherwise stdout is messed-up
392
    top = load_top(ctx, top, path, quiet=True)
×
393
    console = Console(file=file) if file else ctx.console
×
394
    for item in filelist or ["*"]:
×
395
        data = defaultdict(list)
×
396
        for mod, modfilelist in iter_modfilelists(top.mod, item, target=target, maxlevel=maxlevel):
×
397
            data[str(mod)].append(modfilelist.model_dump(exclude_defaults=minimal))
×
398
        pprint(dict(data), indent_guides=False, console=console)
×
399

400

401
@ucdp.command(
12✔
402
    help="""
403
              List Available Data Models.
404

405
              PATTERN: Limit list to these modules only.
406

407
              Examples:
408

409
                ucdp ls
410

411
                ucdp ls -n
412

413
                ucdp ls glbl_lib*
414
              """
415
)
416
@arg_tops
12✔
417
@opt_path
12✔
418
@click.option("--names", "-n", default=False, is_flag=True, help="Just print names")
12✔
419
@click.option("--top/--no-top", "-t/-T", default=None, is_flag=True, help="List loadable top modules only.")
12✔
420
@click.option("--tb/--no-tb", "-b/-B", default=None, is_flag=True, help="List testbench modules only.")
12✔
421
@click.option("--generic-tb", "-g", default=False, is_flag=True, help="List Generic Testbench modules only.")
12✔
422
@opt_local
12✔
423
@click.option("--base", "-A", default=False, is_flag=True, help="Show Base Classes.")
12✔
424
@click.option("--filepath", "-f", default=False, is_flag=True, help="Show File Path.")
12✔
425
@click.option("--abs-filepath", "-F", default=False, is_flag=True, help="Show Absolute File Path.")
12✔
426
@opt_tag
12✔
427
@pass_ctx
12✔
428
def ls(  # noqa: C901
12✔
429
    ctx,
430
    path=None,
431
    tops=None,
432
    names=False,
433
    top=None,
434
    tb=None,
435
    local=None,
436
    generic_tb=False,
437
    tag=None,
438
    base=False,
439
    filepath=False,
440
    abs_filepath=False,
441
):
442
    """List Modules."""
443
    with ctx.console.status("Searching"):
×
444
        infos = find(path, patterns=tops or ["*"], local=local)
×
445
    if top is not None:
×
446
        infos = [info for info in infos if info.is_top == top]
×
447
    if tb is not None:
×
448
        infos = [info for info in infos if bool(info.tb) == tb]
×
449
    if generic_tb:
×
450
        infos = [info for info in infos if info.tb == "Generic"]
×
451
    if tag:
×
452
        filter_ = namefilter(tag)
×
453
        infos = [info for info in infos if any(filter_(tag) for tag in info.tags)]
×
454

455
    def fill_row(row, info):
×
456
        if base:
×
457
            row.append(info.modbasecls.__name__)
×
458
        if filepath:
×
459
            row.append(str(relative(info.filepath)))
×
460
        if abs_filepath:
×
461
            row.append(str(info.filepath))
×
462

463
    if names:
×
464
        for info in infos:
×
465
            row = [info.topmodref]
×
466
            fill_row(row, info)
×
467
            print(*row)
×
468
    else:
469
        table = Table(expand=filepath or abs_filepath, box=box.MARKDOWN)
×
470
        table.add_column("Reference")
×
471
        table.add_column("Top", justify="center")
×
472
        table.add_column("Tb ", justify="center")
×
473
        table.add_column("Tags")
×
474
        if base:
×
475
            table.add_column("Bases on", justify="right")
×
476
        if filepath:
×
477
            table.add_column("Filepath")
×
478
        if abs_filepath:
×
479
            table.add_column("Absolute Filepath")
×
480
        for info in infos:
×
481
            row = [
×
482
                str(info.topmodref),
483
                "X" if info.is_top else "",
484
                "X" if info.tb else "",
485
                ",".join(sorted(info.tags)),
486
            ]
487
            fill_row(row, info)
×
488
            table.add_row(*row)
×
489
        ctx.console.print(table)
×
490

491

492
@ucdp.command(
12✔
493
    help=f"""
494
Load Data Model and Module Information.
495

496
TOP: Top Module. {PAT_TOPMODREF}. Environment Variable 'UCDP_TOP'
497
"""
498
)
499
@arg_tops
12✔
500
@opt_path
12✔
501
@opt_local
12✔
502
@click.option("--top", "-t", default=None, is_flag=True, help="List loadable top modules only.")
12✔
503
@click.option("--sub", "-S", default=False, is_flag=True, help="Show Submodules.")
12✔
504
@pass_ctx
12✔
505
def modinfo(ctx, tops, path, local, top, sub):
12✔
506
    """Module Information."""
507
    sep = ""
×
508
    for info in find(path, patterns=tops, local=local, is_top=top):
×
509
        try:
×
510
            top = load_top(ctx, info.topmodref, path, quiet=True)
×
511
        except Exception as exc:
×
512
            LOGGER.warning(str(exc))
×
513
            continue
×
514
        print(sep + top.mod.get_info(sub=sub))
×
515
        sep = "\n\n"
×
516

517

518
@ucdp.command(
12✔
519
    help=f"""
520
Load Data Model and Show Module Overview.
521

522
TOP: Top Module. {PAT_TOPMODREF}. Environment Variable 'UCDP_TOP'
523
"""
524
)
525
@arg_top
12✔
526
@opt_path
12✔
527
@click.option("--minimal", "-m", default=False, is_flag=True, help="Skip modules without specific details")
12✔
528
@opt_filepath
12✔
529
@opt_tag
12✔
530
@pass_ctx
12✔
531
def overview(ctx, top, path, minimal=False, file=None, tag=None):
12✔
532
    """Overview."""
533
    # Load quiet, otherwise stdout is messed-up
534
    top = load_top(ctx, top, path, quiet=True)
×
535
    data = {"minimal": minimal, "tags": tag}
×
536
    render_generate(top, [PATH / "ucdp-templates" / "overview.txt.mako"], genfile=file, data=data, no_stat=True)
×
537

538

539
@ucdp.group(context_settings={"help_option_names": ["-h", "--help"]})
12✔
540
def info():
12✔
541
    """Information."""
542

543

544
@info.command()
12✔
545
@pass_ctx
12✔
546
def examples(ctx):
12✔
547
    """Path to Examples."""
548
    examples_path = Path(__file__).parent / "examples"
×
549
    print(str(examples_path))
×
550

551

552
@info.command()
12✔
553
@opt_path
12✔
554
@pass_ctx
12✔
555
def template_paths(ctx, path):
12✔
556
    """Template Paths."""
557
    makolator = get_makolator(paths=path)
×
558
    for template_path in makolator.config.template_paths:
×
559
        print(str(template_path))
×
560

561

562
@ucdp.command(
12✔
563
    help="""
564
Create Datamodel Skeleton.
565
"""
566
)
567
@click.option("--module", "-m", prompt=True, help="Name of the Module")
12✔
568
@click.option("--library", "-l", default=absolute(Path()).name, prompt=True, help="Name of the Library")
12✔
569
@click.option("--regf/--no-regf", "-r/-R", default=True, help="Make use of a Register File")
12✔
570
@click.option("--descr", "-d", default="", help="Description")
12✔
571
@click.option("--flavour", "-F", type=click.Choice(TYPE_CHOICES, case_sensitive=False), help="Choose a Module Flavour")
12✔
572
@click.option("--tb/--no-tb", "-t/-T", default=None, help="Create testbench for design module")
12✔
573
@click.option("--force", "-f", is_flag=True, help="Overwrite existing files")
12✔
574
@pass_ctx
12✔
575
def create(
12✔
576
    ctx,
577
    module,
578
    library,
579
    regf,
580
    descr,
581
    flavour,
582
    tb,
583
    force,
584
):
585
    """Let The User Type In The Name And Library Of The File."""
586
    if flavour is None:
12✔
587
        flavour = prompt_flavour()
12✔
588
        ctx.console.print(f"\nYou choose the flavour [bold blue]{flavour}[/bold blue].\n")
12✔
589

590
    info = CreateInfo(module=module, library=library, regf=regf, descr=descr, flavour=flavour)
12✔
591

592
    if info.is_tb:
12✔
593
        if not module.endswith("_tb"):
12✔
594
            LOGGER.warning(f"Your testbench module name {module!r} does not end with '_tb'")
12✔
595

596
    else:
597
        if module.endswith("_tb"):
12✔
598
            LOGGER.warning(f"Your design module name {module!r} ends with '_tb'")
12✔
599
        if tb is None:
12✔
600
            answer = click.prompt(
12✔
601
                "Do you want to create a corresponding testbench? (y)es. (n)o.",
602
                type=click.Choice(["y", "n"]),
603
                default="y",
604
            )
605
            tb = answer == "y"
12✔
606
            ctx.console.print("")
12✔
607
        if tb:
12✔
608
            tbinfo = CreateInfo(module=f"{module}_tb", library=library, regf=regf, descr=descr, flavour=TB_MAP[flavour])
12✔
609
            create_(tbinfo, force)
12✔
610
    create_(info, force)
12✔
611

612

613
Type = Literal["AConfigurableMod", "AConfigurableTbMod", "AGenericTbMod", "AMod", "ATailoredMod", "ATbMod"]
12✔
614

615

616
def prompt_flavour() -> Type:
12✔
617
    """Let The User Choose The Type Of The File."""
618
    answer = click.prompt("Do you want to build a (d)esign or (t)estbench?", type=click.Choice(["d", "t"]), default="d")
12✔
619
    if answer == "d":
12✔
620
        answer = click.prompt(
12✔
621
            "Does your design vary more than what `parameter` can cover? (y)es. (n)o.", type=click.Choice(["y", "n"])
622
        )
623
        if answer == "y":
12✔
624
            answer = click.prompt(
12✔
625
                "Do you want to use a (c)onfig or (t) shall the parent module tailor the functionality?",
626
                type=click.Choice(["c", "t"]),
627
            )
628
            if answer == "c":
12✔
629
                flavour_ = "AConfigurableMod"
12✔
630

631
            else:
632
                flavour_ = "ATailoredMod"
12✔
633

634
        else:
635
            flavour_ = "AMod"
12✔
636

637
    else:
638
        answer = click.prompt(
12✔
639
            "Do you want to build a generic testbench which tests similar modules? (y)es. (n)o.",
640
            type=click.Choice(["y", "n"]),
641
        )
642
        if answer == "y":
12✔
643
            answer = click.prompt(
12✔
644
                "Do you want to automatically adapt your testbench to your (g) dut or use a (c)onfig?",
645
                type=click.Choice(["g", "c"]),
646
            )
647
            if answer == "c":
12✔
648
                flavour_ = "AConfigurableTbMod"
12✔
649

650
            else:
651
                flavour_ = "AGenericTbMod"
12✔
652

653
        else:
654
            flavour_ = "ATbMod"
12✔
655

656
    return flavour_
12✔
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