Runnerο
Classes
|
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:
objectHandles 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.