tugboat.utils module

tugboat.utils.bulk_translate_pydantic_errors(errors: Iterable[ErrorDetails]) list[Diagnosis]

Translate multiple Pydantic errors to diagnosis objects.

This function helps to translate multiple Pydantic errors to diagnosis objects, and merges some of the similar errors into a more concise message.

See translate_pydantic_error() for the details of the translation.

Parameters:

errors (Iterable[ErrorDetails]) – An iterable of Pydantic error objects. These objects could be obtained from ValidationError.errors method.

Yields:

list[Diagnosis] – A list of diagnosis objects that contain the error messages

tugboat.utils.check_model_fields_references(model: BaseModel, references: ReferenceCollection, *, exclude: Container[str] = ()) Iterator[Diagnosis]

Check the fields of the given model for errors that are specific to Argo workflows variables.

Parameters:
  • model (BaseModel) – The model to check. This function will check all fields of the model that are of type str.

  • references (ReferenceCollection) – The current active references.

  • exclude (Container[str]) – The fields to exclude from the check.

Yields:

Diagnosis – A diagnosis for each error found.

tugboat.utils.check_value_references(value: str, references: ReferenceCollection) Iterator[Diagnosis]

Check the given value for errors that are specific to Argo workflows variables.

Parameters:
  • value (str) – The value to check.

  • references (ReferenceCollection) – The current active references.

Yields:

Diagnosis – A diagnosis for each error found.

tugboat.utils.find_duplicate_names(items: Sequence[NamedModel]) Iterator[tuple[int, str]]

Find and yield the indices and names of duplicate items in a sequence.

tugboat.utils.get_alias(model: BaseModel, name: str) str

Get the alias of a field in a model.

tugboat.utils.get_context_name(loc: Sequence[str | int]) str

Get the parent context name for a location.

tugboat.utils.join_with_and(items: Iterable[Any], *, quote: bool = True, sort: bool = True, fallback_string: str = '(none)') str

Join items with “and” as the last joiner. On empty input, returns the fallback string.

Parameters:
  • items (Iterable[Any]) – The items to join.

  • quote (bool) – Whether to quote the items.

  • sort (bool) – Whether to sort the items.

  • fallback_string (str) – The string to return if there are no items.

tugboat.utils.join_with_or(items: Iterable[Any], *, quote: bool = True, sort: bool = True, fallback_string: str = '(none)') str

Join items with “or” as the last joiner. On empty input, returns the fallback string.

Parameters:
  • items (Iterable[Any]) – The items to join.

  • quote (bool) – Whether to quote the items.

  • sort (bool) – Whether to sort the items.

  • fallback_string (str) – The string to return if there are no items.

class tugboat.utils.prepend_loc(prefix: Sequence[str | int], items: Iterable[Diagnosis] = ())

Prepend path to the location of each diagnosis in an iterable.

tugboat.utils.translate_pydantic_error(error: ErrorDetails) Diagnosis

Translate a Pydantic error to a diagnosis object.

This function returns a diagnosis object based on the error type found in the input:

Below are some custom error types defined in Tugboat:

Custom Error Type

Tugboat Code

artifact_prohibited_value_field

M102 Found redundant field

parameter_value_type_error

M103 Type mismatch

Parameters:

error (ErrorDetails) – A Pydantic error object. This object could be obtained from ValidationError.errors method.

Returns:

A diagnosis object that contains the error message and other relevant information.

Return type:

Diagnosis