Utils

Functions

to_tuple(value)

Convert the given value to a tuple

merge_maps(source, new[, extend, overwrite])

Recursively update a given source map in place with a new map.

get_matching_catalog_table(item, catalog)

Check whether the given item exists in the database.

get_absolute_project_path(path)

Get the absolute path of the given relative path in the project directory.

dbt_contracts.contracts.utils.to_tuple(value: Any) → tuple

Convert the given value to a tuple

dbt_contracts.contracts.utils.merge_maps(source: T, new: Mapping, extend: bool = True, overwrite: bool = False) → T

Recursively update a given source map in place with a new map.

Parameters:
  • source – The source map.

  • new – The new map with values to update for the source map.

  • extend – When a value is a list and a list is already present in the source map, extend the list when True. When False, only replace the list if overwrite is True.

  • overwrite – When True, overwrite any value in the source destructively.

Returns:

The updated dict.

dbt_contracts.contracts.utils.get_matching_catalog_table(item: NodeT, catalog: CatalogArtifact) → CatalogTable | None

Check whether the given item exists in the database.

Parameters:
  • item – The resource to match.

  • catalog – The catalog of tables.

Returns:

The matching catalog table.

dbt_contracts.contracts.utils.get_absolute_project_path(path: str | Path) → Path | None

Get the absolute path of the given relative path in the project directory. Only returns the path if it exists.

Parameters:

path – The relative path.

Returns:

The absolute project path.