cldfbench Commands

The “bench” in cldfbench means that it can be used to apply tools to CLDF data. Now, being software, the ultimate tool that can be applied with cldfbench is custom code, provided by the user - rather than “off-the-shelve” tools like cldfbench makecldf.

The basics of custom cldfbench commands is described in <this README <https://github.com/cldf/cldfbench/blob/master/src/cldfbench/commands/README.md>`_

The following utilities to be used in commands are available:

Register arguments

These functions are typically called in a command’s register function.

cldfbench.cli_util.add_dataset_spec(parser, ep='cldfbench.dataset', multiple=False)[source]

Add arguments and options to specify cldfbench Datasets to the CLI.

Parameters:

multiple – Flag signaling whether selection of multiple datasets should be allowed.

Note

This funtion is supposed to be used in tandem with get_dataset(), called in a command’s run function.

Parameters:
  • parser (argparse.ArgumentParser) –

  • ep (str) –

cldfbench.cli_util.add_catalog_spec(parser, name, with_version=True, default=None)[source]

Add an option for a reference catalog (at a specific version tag) to the CLI.

Parameters:
  • parser (argparse.ArgumentParser) – Subparser for the subcommand.

  • name (str) – Option name to use for the catalog.

  • with_version (bool) – Flag signaling whether an option to select a version tag for the catalog should be added.

  • default – The default value for the argument. None will trigger config lookup, IGNORE_MISSING will set the argument to None if no user-supplied value is found.

Note

If one of the cldfbench.catalogs.BUILTIN_CATALOGS is added (using its name as name), cldfbench will add an initialized cldfcatalog.Catalog object (with entered context, if a particular version was requested) as name to the argparse.Namespace passed to the command’s run function.

Access objects

These functions are typically called in a command’s run function.

cldfbench.cli_util.get_dataset(args)[source]

Get the cldfbench.Dataset specified by args.

Raises:

ParserError – If no matching dataset was found.

Parameters:

args (argparse.Namespace) –

Return type:

cldfbench.dataset.Dataset

cldfbench.cli_util.get_datasets(args)[source]

Get the cldfbench.Dataset s specified by args.

Raises:

ParserError – If no matching datasets were found.

Parameters:

args (argparse.Namespace) –

Return type:

typing.List[cldfbench.dataset.Dataset]

cldfbench.cli_util.get_cldf_dataset(args, cldf_spec=None)[source]

Get the pycldf.Dataset specified by cldf_spec for the cldfbench.Dataset specified by args.

Parameters:

args (argparse.Namespace) –

Return type:

pycldf.dataset.Dataset

cldfbench.cli_util.with_dataset(args, func, dataset=None)[source]

Run a callable, passing a dataset and args as arguments, returning it’s result.

Parameters:
  • args (argparse.Namespace) – CLI arguments

  • func (typing.Union[callable, str]) – Callable with suitable signature or str, in which case a method _cmd_<name> will be looked up on the dataset and run.

  • datasetcldfbench.Dataset instance or None, in which case a dataset will be retrieved as specified by args.

Return type:

typing.Any

cldfbench.cli_util.with_datasets(args, func)[source]

Run func on all datasets specified by args.

See with_dataset() for details.