nemo_gym.cli.utils

View as Markdown

Module Contents

Functions

NameDescription
did_you_meanA Did you mean \X`?fragment for the closest candidate tovalue, or ""` if none is close enough.
exit_cleanly_on_config_errorDecorator: turn user-facing ConfigError into a clean message + non-zero exit.
exit_unknown_componentPrint an unknown <type> '<name>' error (with a did-you-mean hint) and exit nonzero.
fuzzy_matchesWhether query fuzzily matches any of fields: a substring or a close difflib match (token-aware).
print_no_matchesPrint the standard ‘nothing to show’ message for a gym list/gym search command.
print_rich_tablePrint a Rich table without the 80-col truncation Rich applies when stdout is piped.
render_component_inspectionRender the uniform gym list <type> <name> inspect view (or its --json payload).

API

nemo_gym.cli.utils.did_you_mean(
value: str,
candidates: typing.Iterable[str]
) -> str

A Did you mean \X`?fragment for the closest candidate tovalue, or ""` if none is close enough.

nemo_gym.cli.utils.exit_cleanly_on_config_error(
fn
)

Decorator: turn user-facing ConfigError into a clean message + non-zero exit.

Config mistakes (missing/typo’d config_paths, malformed config_paths, nothing configured to run) should fail fast with an actionable message, not a Python traceback. Unexpected errors still propagate normally.

nemo_gym.cli.utils.exit_unknown_component(
name: str,
candidates: typing.Iterable[str],
type_label: str
) -> None

Print an unknown <type> '<name>' error (with a did-you-mean hint) and exit nonzero.

nemo_gym.cli.utils.fuzzy_matches(
query: str,
fields: str = ()
) -> bool

Whether query fuzzily matches any of fields: a substring or a close difflib match (token-aware).

The shared matcher behind gym search <type> <query> across every component type.

nemo_gym.cli.utils.print_no_matches(
component_type: str,
query: typing.Optional[str]
) -> None

Print the standard ‘nothing to show’ message for a gym list/gym search command.

component_type is the plural noun (benchmarks, environments, …). Keeps the message and styling identical across every listing.

nemo_gym.cli.utils.print_rich_table(
table
) -> None

Print a Rich table without the 80-col truncation Rich applies when stdout is piped.

On a TTY, Rich sizes the console to the terminal. When stdout is redirected (e.g. gym list benchmarks | cat), Rich falls back to an 80-column console and truncates cells with an ellipsis, silently losing data. We measure the table’s natural width and render at that width so piped output is lossless, while leaving interactive terminal output unchanged.

nemo_gym.cli.utils.render_component_inspection(
json_output: bool,
name: str,
type_noun: str,
domain: typing.Optional[str] = None,
description: typing.Optional[str] = None,
details: typing.Dict[str, str],
usage: typing.Optional[str] = None
) -> None

Render the uniform gym list <type> <name> inspect view (or its --json payload).

details is an ordered label -> value mapping (e.g. {"config": ..., "agent": ...}). Text sections (domain suffix, description, Details, Usage example) are omitted when empty.