Skip to content

Manifest Checks: Metadata#

Note

The below checks require manifest.json to be present.

Functions:

Name Description
check_project_name

Enforce that the name of the dbt project matches a supplied regex. Generally used to enforce that project names conform to something like company_<DOMAIN>.

check_project_name #

Enforce that the name of the dbt project matches a supplied regex. Generally used to enforce that project names conform to something like company_<DOMAIN>.

Parameters:

Name Type Description Default
project_name_pattern str

Regex pattern to match the project name.

required

Receives at execution time:

Name Type Description
manifest_obj ManifestObject

The manifest object.

Other Parameters (passed via config file):

Name Type Description
description str | None

Description of what the check does and why it is implemented.

severity Literal[error, warn] | None

Severity level of the check. Default: error.

Example(s):

manifest_checks:
    - name: check_project_name
      project_name_pattern: ^awesome_company_

Source code in src/dbt_bouncer/checks/manifest/check_metadata.py
@check
def check_project_name(
    ctx, *, package_name: str | None = None, project_name_pattern: str
):
    """Enforce that the name of the dbt project matches a supplied regex. Generally used to enforce that project names conform to something like  `company_<DOMAIN>`.

    Parameters:
        project_name_pattern (str): Regex pattern to match the project name.

    Receives:
        manifest_obj (ManifestObject): The manifest object.

    Other Parameters:
        description (str | None): Description of what the check does and why it is implemented.
        severity (Literal["error", "warn"] | None): Severity level of the check. Default: `error`.

    Example(s):
        ```yaml
        manifest_checks:
            - name: check_project_name
              project_name_pattern: ^awesome_company_
        ```

    """
    compiled_project_name_pattern = compile_pattern(project_name_pattern.strip())
    manifest_obj = ctx.manifest_obj

    resolved_package_name = package_name or manifest_obj.manifest.metadata.project_name
    if compiled_project_name_pattern.match(str(resolved_package_name)) is None:
        fail(
            f"Project name (`{resolved_package_name}`) does not conform to the supplied regex `({project_name_pattern.strip()})`."
        )