simplebench.utils.flags_and_args moduleπŸ”—

Utility functions for command-line flags and argument names.

simplebench.utils.flags_and_args.arg_to_flag(arg: str) str[source]πŸ”—

Convert a Python argument name to a command-line flag.

This function takes a Python argument name (e.g., β€˜my_flag’) and converts it to a command-line flag (e.g., β€˜β€“my-flag’) by adding leading dashes and replacing underscores with hyphens.

Parameters:

arg (str) – The Python argument name to convert.

Raises:
Returns:

The corresponding command-line flag.

Return type:

str

simplebench.utils.flags_and_args.collect_arg_list(
*,
args: Namespace,
flag: str,
) list[str][source]πŸ”—

Collects a list of argument values from a Namespace for a given flag.

This function retrieves the values associated with the specified flag from the provided Namespace object. If the value is a sequence (excluding str and bytes), it returns the values as a list. If the value is a single item, it returns a list containing that single item. If the flag does not exist in the Namespace, it returns an empty list.

argparse lists consist of lists of lists of strings and so they have to be flattened to be processed.

Parameters:
  • args (Namespace) – The Namespace object containing argument values.

  • flag (str) – The command-line flag whose value is to be collected.

Raises:

SimpleBenchTypeError – If the args argument is not a Namespace or if the retrieved argument value is of an unexpected type.

Returns:

A list of unique argument values associated with the specified flag.

Return type:

list[str]

simplebench.utils.flags_and_args.flag_to_arg(flag: str) str[source]πŸ”—

Convert a command-line flag to a valid Python argument name.

This function takes a command-line flag (e.g., β€˜β€“my-flag’) and converts it to a valid Python argument name (e.g., β€˜my_flag’) as expected in a Namespace result by removing leading dashes and replacing hyphens with underscores.

Parameters:

flag (str) – The command-line flag to convert.

Raises:
Returns:

The corresponding Python argument name.

Return type:

str