saysynth.cli.commands.demo

Play a built-in demo.

 1"""
 2Play a built-in demo.
 3"""
 4
 5import os
 6
 7import click
 8import pkg_resources
 9
10from saysynth.cli.commands.seq import run as run_sequence
11from saysynth.cli.options import (seq_command_arg, seq_opts,
12                                  set_config_overrides_opt)
13
14DEMO_DIR = pkg_resources.resource_filename("saysynth", "cli/commands/demos/")
15DEMO_NAMES = {
16    f.split("/")[-1]
17    .split(".yml")[0][2:]
18    .strip(): f.split("/")[-1]
19    .split(".yml")[0]
20    .split("-")[0]
21    .strip()
22    for f in os.listdir(DEMO_DIR)
23}
24
25
26def run(**kwargs):
27    name = kwargs.pop("name")
28    num = DEMO_NAMES.get(name)
29    kwargs["base_config"] = open(
30        os.path.join(DEMO_DIR, f"{num}-{name}.yml"), "r"
31    )
32    run_sequence(**kwargs)
33
34
35@click.command(
36    context_settings=dict(
37        ignore_unknown_options=True,
38        allow_extra_args=True,
39    )
40)
41@seq_command_arg
42@click.argument(
43    "name", type=click.Choice(list(DEMO_NAMES.keys())), default=None
44)
45@seq_opts
46@click.pass_context
47def cli(context, **kwargs):
48    """
49    Play a built-in demo.
50    """
51    return run(**set_config_overrides_opt(context, **kwargs))
def run(**kwargs):
27def run(**kwargs):
28    name = kwargs.pop("name")
29    num = DEMO_NAMES.get(name)
30    kwargs["base_config"] = open(
31        os.path.join(DEMO_DIR, f"{num}-{name}.yml"), "r"
32    )
33    run_sequence(**kwargs)
cli = <Command cli>

Play a built-in demo.