Runner

Inheritance diagram of dbt_contracts.runner.ContractsRunner

Classes

ContractsRunner(contracts,Β config,Β ...[,Β ...])

Handles loading config for contracts and their execution.

class dbt_contracts.runner.ContractsRunner(contracts: ~collections.abc.Collection[~dbt_contracts.contracts._contracts.Contract], config: ~dbt.config.runtime.RuntimeConfig, results_formatter: ~dbt_contracts.formatters._core.ResultsFormatter = GroupedTableFormatter(formatter=TableFormatter[TypeVar](builder=TableRowBuilder[TypeVar](cells=((TableCellBuilder[TypeVar](key='result_name', prefix=None, alignment='<', colour='\x1b[31m', min_width=None, max_width=50, wrap=False), TableCellBuilder[TypeVar](key='properties_start_line', prefix='L: ', alignment='>', colour='\x1b[94m', min_width=6, max_width=9, wrap=False), TableCellBuilder[TypeVar](key=<function <lambda>>, prefix=None, alignment='<', colour='\x1b[36m', min_width=None, max_width=40, wrap=False), TableCellBuilder[TypeVar](key='message', prefix=None, alignment='<', colour='\x1b[33m', min_width=None, max_width=60, wrap=True)), (None, TableCellBuilder[TypeVar](key='properties_start_col', prefix='P: ', alignment='>', colour='\x1b[94m', min_width=6, max_width=9, wrap=False), TableCellBuilder[TypeVar](key=<function <lambda>>, prefix='> ', alignment='<', colour='\x1b[36m', min_width=None, max_width=40, wrap=False), None)), separator='|', colour='\x1b[97m'), consistent_widths=True), group_key=<function <lambda>>, header_key=<function _get_default_table_header>, sort_key=('result_type', 'path', <function <lambda>>, <function <lambda>>, <function <lambda>>)))

Bases: object

Handles loading config for contracts and their execution.

default_config_file_name: str = 'contracts'
default_output_file_name: str = 'contracts_results'
output_writers_map = {'github-annotations': <function ContractsRunner._write_results_as_github_annotations>, 'json': <function ContractsRunner._write_results_as_json>, 'jsonl': <function ContractsRunner._write_results_as_jsonl>, 'text': <function ContractsRunner._write_results_as_text>, 'txt': <function ContractsRunner._write_results_as_text>}
property config: RuntimeConfig

The dbt runtime config

property dbt: dbtRunner

The dbt runner

property manifest: Manifest

The dbt manifest

property catalog: CatalogArtifact

The dbt catalog

property paths: PathCondition | None

An additional set of paths to filter on when filter contract items.

classmethod from_config(config: RuntimeConfig) → Self

Set up a new runner from the dbt runtime config with custom args parsed from CLI.

Parameters:

config – The dbt runtime config with args associated.

Returns:

The configured runner.

classmethod from_args(args: Namespace) → Self

Set up a new runner from the args parsed from CLI.

Parameters:

args – The parsed CLI args.

Returns:

The configured runner.

classmethod from_file(path: str | Path, config: RuntimeConfig)

Set up a new runner from the config in a file at the given path.

Parameters:
  • path – The path to the config file. Must be a path to a valid file.

  • config – The dbt runtime config.

Returns:

The configured runner.

classmethod from_yaml(path: str | Path, config: RuntimeConfig) → Self

Set up a new runner from the config in a yaml file at the given path.

Parameters:
  • path – The path to the yaml file. May either be a path to a yaml file or a path to the directory where the file is located. If a directory is given, the default file name will be appended.

  • config – The dbt runtime config.

Returns:

The configured runner.

classmethod from_json(path: str | Path, config: RuntimeConfig) → Self

Set up a new runner from the config in a json file at the given path.

Parameters:
  • path – The path to the json file. May either be a path to a json file or a path to the directory where the file is located. If a directory is given, the default file name will be appended.

  • config – The dbt runtime config.

Returns:

The configured runner.

classmethod from_dict(mapping: Mapping[str, Any], config: RuntimeConfig) → Self

Set up a new runner from the given config.

Parameters:
  • mapping – The config to configure the runner with.

  • config – The dbt runtime config.

Returns:

The configured runner.

validate(contract_key: str = None, terms: Collection[str] = ()) → list[Result]

Validate the project against the contracts and log the results.

Parameters:
  • contract_key – Only process the contract with this key.

  • terms – Only run the terms with these names.

Returns:

The results of the validation.

generate(contract_key: str = None) → dict[Path, int]

Generate properties for the contracts and log the results.

Parameters:

contract_key – Only process the contract with this key.

Returns:

The paths of the updated/created properties files.

log_results(results: Collection[Result]) → None

Log the results of the validation.

Parameters:

results – The results of the validation.

write_results(results: Collection[Result], path: str | Path, output_type: str) → Path | None

Write the given results to an output file with the given output_type.

Parameters:
  • results – The results to write.

  • path – The path to a directory or file to write to.

  • output_type – The format to write the file to e.g. β€˜txt’, β€˜json’ etc.

Returns:

The path the file was written to.