Skip to content

climate_ref.cli #

Entrypoint for the CLI

CLIContext #

Context object that can be passed to commands

Source code in packages/climate-ref/src/climate_ref/cli/__init__.py
@define
class CLIContext:
    """
    Context object that can be passed to commands
    """

    config: Config
    database: Database
    console: Console

LogLevel #

Bases: str, Enum

Log levels for the CLI

Source code in packages/climate-ref/src/climate_ref/cli/__init__.py
class LogLevel(str, Enum):
    """
    Log levels for the CLI
    """

    Error = "ERROR"
    Warning = "WARNING"
    Debug = "DEBUG"
    Info = "INFO"

build_app() #

Build the CLI app

This registers all the commands and subcommands of the CLI app. Some commands may not be available if certain dependencies are not installed, for example the Celery CLI is only available if the climate-ref-celery package is installed.

Returns:

Type Description
Typer

The CLI app

Source code in packages/climate-ref/src/climate_ref/cli/__init__.py
def build_app() -> typer.Typer:
    """
    Build the CLI app

    This registers all the commands and subcommands of the CLI app.
    Some commands may not be available if certain dependencies are not installed,
    for example the Celery CLI is only available if the `climate-ref-celery` package is installed.

    Returns
    -------
    :
        The CLI app
    """
    app = typer.Typer(name="ref", no_args_is_help=True)

    app.command(name="solve")(solve.solve)
    app.add_typer(config.app, name="config")
    app.add_typer(datasets.app, name="datasets")
    app.add_typer(executions.app, name="executions")
    app.add_typer(providers.app, name="providers")

    try:
        celery_app = importlib.import_module("climate_ref_celery.cli").app

        app.add_typer(celery_app, name="celery")
    except ImportError:
        logger.debug("Celery CLI not available")

    return app

main(ctx, configuration_directory=None, verbose=False, quiet=False, log_level=LogLevel.Info, version=None) #

A CLI for the Assessment Fast Track Rapid Evaluation Framework

This CLI provides a number of commands for managing and executing diagnostics.

Source code in packages/climate-ref/src/climate_ref/cli/__init__.py
@app.callback()
def main(  # noqa: PLR0913
    ctx: typer.Context,
    configuration_directory: Annotated[
        Path | None,
        typer.Option(help="Configuration directory"),
    ] = None,
    verbose: Annotated[
        bool,
        typer.Option("--verbose", "-v", help="Set the log level to DEBUG"),
    ] = False,
    quiet: Annotated[
        bool,
        typer.Option("--quiet", "-q", help="Set the log level to WARNING"),
    ] = False,
    log_level: Annotated[
        LogLevel,
        typer.Option(case_sensitive=False, help="Set the level of logging information to display"),
    ] = LogLevel.Info,
    version: Annotated[
        bool | None,
        typer.Option(
            "--version", callback=_version_callback, is_eager=True, help="Print the version and exit"
        ),
    ] = None,
) -> None:
    """
    A CLI for the Assessment Fast Track Rapid Evaluation Framework

    This CLI provides a number of commands for managing and executing diagnostics.
    """  # noqa: D401
    if quiet:
        log_level = LogLevel.Warning
    if verbose:
        log_level = LogLevel.Debug

    logger.remove()

    config = _load_config(configuration_directory)
    config.log_level = log_level.value

    log_format = config.log_format
    initialise_logging(level=config.log_level, format=log_format, log_directory=config.paths.log)

    logger.debug(f"Configuration loaded from: {config._config_file!s}")

    ctx.obj = CLIContext(config=config, database=Database.from_config(config), console=_create_console())

sub-packages#

Sub-package Description
_utils
config View and update the REF configuration
datasets View and ingest input datasets
executions View execution groups and their results
providers Manage the REF providers.
solve