How to use the temci.utils.click_helper.CmdOptionList function in temci

To help you get started, we’ve selected a few temci examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github parttimenerd / temci / temci / scripts / cli.py View on Github external
CmdOption("without_description", short="wd",
                                    type_scheme=ListOrTuple(Str()) // Description("COMMAND: Benchmark the command and use "
                                                                           "itself as its description. "
                                                                           "Appends '$ARGUMENT' "
                                                                           "to the command if the string isn't present. "
                                                                           "Use the '--argument' option to set the value "
                                                                           "that this string is replaced with."),
                                    completion_hints={"zsh": "_command"}),
                          run_options["run_driver_specific"]["exec"],
                          run_options["common"]
                          ),
            "shell": CmdOptionList(run_options["run_driver_specific"]["exec"],
                          run_options["common"])
        }
    },
    "clean": CmdOptionList()
}
misc_commands_description = {
    "completion": {
        "zsh": "Creates a new tab completion file for zsh and returns its file name",
        #"fish": "Creates a file /tmp/temci_fish_completion for fish completion support.",
        "bash": "Creates a new tab completion file for zsh and returns its file name",
    },
    "init": {
        "settings": "Create a new settings file temci.yaml (or the file name passed) in the current directory",
        "build_config":
            "Creates a sample build config file build_config.yaml (or the file name passed) in the current directory",
        "run_config":
            "Creates a sample exec run config file run_config.yaml (or the file name passed) in the current directory"
    },
    "short": {
        "exec": "Execute commands directly with the exec run driver",
github parttimenerd / temci / temci / scripts / cli.py View on Github external
globals()["temci__" + driver](*args, **kwargs)

    def _func2(run_file, **kwargs):
        Settings()["run/driver"] = driver
        if run_file is not "":
            Settings()["run/in"] = run_file
        benchmark_and_exit()
    _func2.__name__ = "temci__" + driver
    document_func(command_docs[driver], options, argument="configuration YAML file")(_func2)
    globals()["temci__" + driver] = _func2


# Register a command for each run driver
for driver in run_driver.RunDriverRegistry.registry:
    create_run_driver_function(driver,
                               CmdOptionList(common_options, run_options["common"], run_options["run_driver_specific"][driver]))


def temci__short():
    pass


temci__short.__doc__ = command_docs["short"]


@cli.group(short_help=command_docs["short"])
@cmd_option(common_options)
def short(**kwargs):
    pass


@short.command(short_help=misc_commands_description["short"]["exec"])
github parttimenerd / temci / temci / scripts / cli.py View on Github external
command_docs = {
    "build": "Build program blocks",
    "report": "Generate a report from benchmarking result",
    "init": "Helper commands to initialize files (like settings)",
    "completion": "Creates completion files for several shells.",
    "short": "Utility commands to ease working directly on the command line",
    "clean": "Clean up the temporary files",
    "setup": "Compile all needed binaries in the temci scripts folder",
    "version": "Print the current version ({})".format(temci.scripts.version.version),
    "format": "Format a number"
}
for driver in run_driver.RunDriverRegistry.registry:
    command_docs[driver] = run_driver.RunDriverRegistry.registry[driver].__description__.strip().split("\n")[0]

common_options = CmdOptionList(
    CmdOption.from_non_plugin_settings("")
)

run_options = {
    "common": CmdOptionList(
        CmdOption.from_non_plugin_settings("run"),
        CmdOption.from_non_plugin_settings("stats", name_prefix="stats_"),
        CmdOption.from_non_plugin_settings("report/number", name_prefix="report_number_")
    ),
    "run_driver_specific": {  # besides DRIVER_misc and plugins
        "exec": CmdOptionList()
    }
}

# init the run_options dictionary
for driver in run_driver.RunDriverRegistry.registry:
github parttimenerd / temci / temci / scripts / cli.py View on Github external
"completion": "Creates completion files for several shells.",
    "short": "Utility commands to ease working directly on the command line",
    "clean": "Clean up the temporary files",
    "setup": "Compile all needed binaries in the temci scripts folder",
    "version": "Print the current version ({})".format(temci.scripts.version.version),
    "format": "Format a number"
}
for driver in run_driver.RunDriverRegistry.registry:
    command_docs[driver] = run_driver.RunDriverRegistry.registry[driver].__description__.strip().split("\n")[0]

common_options = CmdOptionList(
    CmdOption.from_non_plugin_settings("")
)

run_options = {
    "common": CmdOptionList(
        CmdOption.from_non_plugin_settings("run"),
        CmdOption.from_non_plugin_settings("stats", name_prefix="stats_"),
        CmdOption.from_non_plugin_settings("report/number", name_prefix="report_number_")
    ),
    "run_driver_specific": {  # besides DRIVER_misc and plugins
        "exec": CmdOptionList()
    }
}

# init the run_options dictionary
for driver in run_driver.RunDriverRegistry.registry:
    options = CmdOptionList(
        CmdOption.from_registry(run_driver.RunDriverRegistry.registry[driver]),
        CmdOption.from_non_plugin_settings("run/{}_misc".format(driver)),
        CmdOption.from_non_plugin_settings("run/cpuset", name_prefix="cpuset_"),
        run_options["common"]
github parttimenerd / temci / temci / utils / click_helper.py View on Github external
def document_func(description: str, *options: t.Tuple[t.Union[CmdOptionList, CmdOption]],
                  argument: str = None, only_if_sphinx_doc: bool = True) -> t.Callable[[t.Callable], t.Callable]:
    """
    Function decorator that appends an command documentation to the functions __doc__ attribute.


    :param description: description of the command
    :param options: options to generate a documentation for
    :param argument: optional argument description of the command
    :param only_if_sphinx_doc: only generate the documentation if the file is executed for documentation generation
    """
    options = CmdOptionList(*options)
    options_str = options.get_sphinx_doc()
    def func(f):
        if not sphinx_doc():
            return f
        full_cmd = f.__name__.replace("__", " ")
        if not f.__doc__:
            f.__doc__ = ""
        f.__doc__ += """
    .. role:: python(code)
    :language: python

    :Command: ``{full_cmd}``

    :Description: {description}

        """.format(full_cmd=full_cmd, description=description)
github parttimenerd / temci / temci / scripts / cli.py View on Github external
# init the run_options dictionary
for driver in run_driver.RunDriverRegistry.registry:
    options = CmdOptionList(
        CmdOption.from_registry(run_driver.RunDriverRegistry.registry[driver]),
        CmdOption.from_non_plugin_settings("run/{}_misc".format(driver)),
        CmdOption.from_non_plugin_settings("run/cpuset", name_prefix="cpuset_"),
        run_options["common"]
    )
    if driver not in run_options["run_driver_specific"]:
        run_options["run_driver_specific"][driver] = options
    else:
        run_options["run_driver_specific"][driver].append(options)


report_options = CmdOptionList(
    CmdOption.from_non_plugin_settings("report"),
    CmdOption.from_non_plugin_settings("stats")
)
# init the report_options dictionary
for reporter in ReporterRegistry.registry:
    options = CmdOption.from_non_plugin_settings("report/{}_misc".format(reporter), name_prefix=reporter + "_")
    report_options.append(options)

build_options = CmdOptionList(
    CmdOption.from_non_plugin_settings("build")
)

misc_commands = {
    "init": {
        "common": CmdOptionList(),
        "sub_commands": {
github parttimenerd / temci / temci / utils / click_helper.py View on Github external
def cmd_option(option: t.Union[CmdOption, CmdOptionList], name_prefix: str = None,
               validate: bool = None) \
        -> t.Callable[[t.Callable], t.Callable]:
    """
    Wrapper around click.option that works with CmdOption objects.
    If option is a list of CmdOptions then the type_scheme_option decorators are chained.
    Also supports nested lists in the same manner.

    :param option: CmdOption or (possibly nested) list of CmdOptions
    :param name_prefix: prefix of all options
    :param validate: validate setting or validate only for outer most if None
    :return: click.option(...) like decorator
    """
    typecheck(option, T(CmdOption) | T(CmdOptionList))
    name_prefix = name_prefix or ""
    typecheck(name_prefix, Str())
    if isinstance(option, CmdOption):
        return type_scheme_option(option_name=name_prefix + option.option_name,
                                  type_scheme=option.type_scheme,
                                  short=option.short,
                                  is_flag=option.is_flag,
                                  callback=option.callback,
                                  with_default=option.has_default,
                                  default=option.default,
                                  validate_settings=validate
                                  )
    def func(f: t.Callable):
        name = f.__name__
        #args = f.__arguments__
        annotations = f.__annotations__
github parttimenerd / temci / temci / scripts / cli.py View on Github external
if driver not in run_options["run_driver_specific"]:
        run_options["run_driver_specific"][driver] = options
    else:
        run_options["run_driver_specific"][driver].append(options)


report_options = CmdOptionList(
    CmdOption.from_non_plugin_settings("report"),
    CmdOption.from_non_plugin_settings("stats")
)
# init the report_options dictionary
for reporter in ReporterRegistry.registry:
    options = CmdOption.from_non_plugin_settings("report/{}_misc".format(reporter), name_prefix=reporter + "_")
    report_options.append(options)

build_options = CmdOptionList(
    CmdOption.from_non_plugin_settings("build")
)

misc_commands = {
    "init": {
        "common": CmdOptionList(),
        "sub_commands": {
            "settings": CmdOptionList(),
            "build_config": CmdOptionList(),
            "run_config": CmdOptionList()
        }
    },
    "completion": {
        "common": CmdOptionList(),
        "sub_commands": {
            "bash": CmdOptionList(),
github parttimenerd / temci / temci / utils / click_helper.py View on Github external
domain = Settings().type_scheme
        if settings_domain != "":
            domain = Settings().get_type_scheme(settings_domain)
        ret_list = []
        if isinstance(domain, Obsolete):
            return CmdOptionList()
        for sub_key in domain.data:
            if domain.is_obsolete(sub_key):
                continue
            if sub_key not in exclude and all(not sub_key.endswith(suf) for suf in ["_active", "_misc"]) \
               and not isinstance(domain[sub_key], Dict):
                ret_list.append(CmdOption(
                    option_name=name_prefix + sub_key,
                    settings_key=settings_domain + "/" + sub_key if settings_domain != "" else sub_key
                ))
        return CmdOptionList(*ret_list)