Skip to content

check_rhiza_config

rhiza_hooks.check_rhiza_config

Check that .rhiza/template.yml is valid and well-formed.

main(argv=None)

Main entry point for the hook.

Source code in src/rhiza_hooks/check_rhiza_config.py
def main(argv: list[str] | None = None) -> int:
    """Main entry point for the hook."""
    parser = argparse.ArgumentParser(description="Validate .rhiza/template.yml configuration")
    parser.add_argument(
        "filenames",
        nargs="*",
        help="Filenames to check",
    )
    args = parser.parse_args(argv)

    retval = 0
    for filename in args.filenames:
        filepath = Path(filename)
        errors = validate_rhiza_config(filepath)
        if errors:
            print(f"{filename}:")
            for error in errors:
                print(f"  - {error}")
            retval = 1

    return retval

validate_rhiza_config(filepath)

Validate a rhiza configuration file.

Parameters:

Name Type Description Default
filepath Path

Path to the .rhiza/template.yml file

required

Returns:

Type Description
list[str]

List of error messages (empty if valid)

Source code in src/rhiza_hooks/check_rhiza_config.py
def validate_rhiza_config(filepath: Path) -> list[str]:
    """Validate a rhiza configuration file.

    Args:
        filepath: Path to the .rhiza/template.yml file

    Returns:
        List of error messages (empty if valid)
    """
    # Load configuration
    raw_config = _load_config(filepath)
    if isinstance(raw_config, list):
        return raw_config

    # Validate unknown keys on raw config (before normalization)
    errors = []
    errors.extend(_validate_unknown_keys(raw_config))

    # Normalize aliases for subsequent validation
    config = _normalize_config(raw_config)

    # Validate all aspects
    errors.extend(_validate_required_keys(config))
    errors.extend(_validate_include_or_templates(config))
    errors.extend(_validate_template_repository(config))
    errors.extend(_validate_template_branch(config))
    errors.extend(_validate_include_field(config))
    errors.extend(_validate_templates_field(config))
    errors.extend(_validate_exclude_field(config))

    return errors