CLI#

See this for command-line interface overview.

Exceptions reporter#

class gordo.cli.exceptions_reporter.ExceptionsReporter(exceptions: Iterable[Tuple[Type[Exception], int]], default_exit_code: int = 1, traceback_limit: int | None = None)[source]#

Bases: object

Helper which can save the exception information in JSON format into the file. This class might be used for storing exception information after termination of the Kubernetes pod. Information

Parameters:
  • exceptions – Exceptions list with preferred exit codes for each of them

  • default_exit_code – Default exit code. It might be used as sys.exit() code

  • traceback_limit – Limit for traceback.format_exception()

exception_exit_code(exc_type: Type[BaseException] | None) int[source]#

Possible sys.exit() code for given exception type

Parameters:

exc_type – The exception type

found_exception_item(exc_type: Type[BaseException])[source]#
report(level: ReportLevel, exc_type: Type[BaseException] | None, exc_value: BaseException | None, exc_traceback: TracebackType | None, report_file: IO[str], max_message_len: int | None = None)[source]#

Report exception to the file. exc_type, exc_value, exc_traceback might be values returned by sys.exc_info()

Parameters:
  • level – Level of the report verbosity

  • exc_type – The exception type

  • exc_value – The exception

  • exc_traceback – The exception traceback

  • report_file – File like object for reporting

  • max_message_len – The maximum length of message or traceback. Actual for the environments with limitation of storage capacity. For example, 2024 bytes is the maximum size of the k8s pod termination message content

safe_report(level: ReportLevel, exc_type: Type[BaseException] | None, exc_value: BaseException | None, exc_traceback: TracebackType | None, report_file_path: str, max_message_len: int | None = None)[source]#

Basically this is a wrapper for report() function with additional internal exceptions handling

Parameters:
  • level

  • exc_type

  • exc_value

  • exc_traceback

  • report_file_path

  • max_message_len

static sort_exceptions(exceptions: Iterable[Tuple[Type[Exception], int]]) List[Tuple[Type[Exception], int]][source]#
static trim_formatted_traceback(formatted_traceback: List[str], max_length: int) List[str][source]#
static trim_message(message: str, max_length: int) str[source]#
class gordo.cli.exceptions_reporter.ReportLevel(value)[source]#

Bases: Enum

An enumeration.

EXIT_CODE = 0#
MESSAGE = 2#
TRACEBACK = 3#
TYPE = 1#
classmethod get_by_name(name: str, default: ReportLevel | None = None) ReportLevel | None[source]#
classmethod get_names()[source]#

Click types#

class gordo.cli.custom_types.HostIP[source]#

Bases: ParamType

Validate input is a valid IP address

convert(value: Any, param: Parameter | None, ctx: Context | None)[source]#

Convert the value to the correct type. This is not called if the value is None (the missing value).

This must accept string values from the command line, as well as values that are already the correct type. It may also convert other compatible types.

The param and ctx arguments may be None in certain situations, such as when converting prompt input.

If the value cannot be converted, call fail() with a descriptive message.

Parameters:
  • value – The value to convert.

  • param – The parameter that is using this type to convert its value. May be None.

  • ctx – The current context that arrived at this value. May be None.

name: str = 'host'#

the descriptive name of this type

class gordo.cli.custom_types.JSONParam(schema: Type[T])[source]#

Bases: ParamType, Generic[T]

Loads JSON and validates value against pydantic schema

convert(value: Any, param: Parameter | None, ctx: Context | None) T | None[source]#

Convert the value to the correct type. This is not called if the value is None (the missing value).

This must accept string values from the command line, as well as values that are already the correct type. It may also convert other compatible types.

The param and ctx arguments may be None in certain situations, such as when converting prompt input.

If the value cannot be converted, call fail() with a descriptive message.

Parameters:
  • value – The value to convert.

  • param – The parameter that is using this type to convert its value. May be None.

  • ctx – The current context that arrived at this value. May be None.

name: str = 'JSON'#

the descriptive name of this type

class gordo.cli.custom_types.REParam(pattern: str)[source]#

Bases: ParamType

Validates argument over a regular expression

convert(value: Any, param: Parameter | None, ctx: Context | None)[source]#

Convert the value to the correct type. This is not called if the value is None (the missing value).

This must accept string values from the command line, as well as values that are already the correct type. It may also convert other compatible types.

The param and ctx arguments may be None in certain situations, such as when converting prompt input.

If the value cannot be converted, call fail() with a descriptive message.

Parameters:
  • value – The value to convert.

  • param – The parameter that is using this type to convert its value. May be None.

  • ctx – The current context that arrived at this value. May be None.

name: str = 'REGEXP'#

the descriptive name of this type

gordo.cli.custom_types.key_value_par(val) Tuple[str, str][source]#

Helper for CLI input of ‘key,val’

Utils#

gordo.cli.cli.expand_model(model_config: str, model_parameters: dict)[source]#

Expands the jinja template which is the model using the variables in model_parameters

Parameters:
  • model_config – Jinja template which when expanded becomes a valid model config json.

  • config. (model_parameters Parameters for the model) –

Raises:

ValueError – If an undefined variable is used in the model_config.

Return type:

The model config with variables expanded

gordo.cli.cli.get_all_score_strings(machine)[source]#

Given metadata from the model builder this function returns a list of strings of the following format: {metric_name}-{tag_name}_{fold-fold-number} = {score_val}. This computes the score for the given tag and cross validation split. {metric_name}-{tag_name}_{fold-aggregation} = {score_val}. This computes the score for the given tag and aggregates the score over all cross validation splits (aggregations currently used are mean, std, min and max) {metric_name}_{fold-fold-number} = {score_val}. This computes the score aggregate across all tags (uses sklearn’s default aggregation method) for a given cross validation split. {metric_name}_{fold-aggregation} = {score_val}. This computes the score aggregate across all tags (uses sklearn’s default aggregation method) and cross validation splits (aggregations currently used are mean, std, min and max).

for katib to pick up.

Current metric names supported are sklearn score functions: ‘r2_score’, ‘explained_variance_score’, ‘mean_squared_error’ and ‘mean_absolute_error’. The underscores in such score names are replaced by ‘-‘.

All spaces in the tag name are also replaced by ‘-‘.

Parameters:

machine – Machine to score

gordo.cli.workflow_generator.get_builder_exceptions_report_level(config: NormalizedConfig) ReportLevel[source]#
gordo.cli.workflow_generator.prepare_argo_version(argo_binary: str | None = None) str[source]#
gordo.cli.workflow_generator.prepare_keda_prometheus_query(context)[source]#
gordo.cli.workflow_generator.prepare_resources_labels(value: str, argument: str = '--resources-labels') List[Tuple[str, Any]][source]#
gordo.cli.workflow_generator.validate_generate_context(context)[source]#