Repository: kedro-org/kedro
File: kedro/framework/cli/starters.py (Python)

Code before:
    """Checks that the configuration file contains all needed variables.

    Args:
        config: The config as a dictionary.
        prompts: Prompts from prompts.yml.

    Raises:
        KedroCliError: If the config file is empty or does not contain all the keys
            required in prompts, or if the output_dir specified does not exist.
    """
    if config is None:
        raise KedroCliError("Config file is empty.")
    missing_keys = set(prompts) - set(config)
    missing_mandatory_keys = missing_keys - {"tools", "example_pipeline"}
    if missing_mandatory_keys:
        click.echo(yaml.dump(config, default_flow_style=False))
        raise KedroCliError(
            f"{', '.join(missing_mandatory_keys)} not found in config file."
        )
    if "example_pipeline" in missing_keys:
        click.secho(
            "The `example_pipeline` key not found in the config file, default value 'no' is being used.",
            fg="yellow",
        )
    if "tools" in missing_keys:
        click.secho(
            "The `tools` key not found in the config file, default value 'none' is being used.",
            fg="yellow",
        )

    if "output_dir" in config and not Path(config["output_dir"]).exists():
        raise KedroCliError(
            f"'{config['output_dir']}' is not a valid output directory. "
            "It must be a relative or absolute path to an existing directory."
        )


def _validate_config_file_inputs(config: dict[str, str]):
    """Checks that variables provided through the config file are of the expected format. This
    validate the config provided by `kedro new --config` in a similar way to `prompts.yml`
    for starters.

    Args:
        config: The config as a dictionary

    Raises:
        SystemExit: If the provided variables are not properly formatted.
    """
    project_name_validation_config = {
        "regex_validator": r"^[\w -]{2,}$",
        "error_message": "'{input_project_name}' is an invalid value for project name. It must contain only alphanumeric symbols, spaces, underscores and hyphens and be at least 2 characters long",

Review comment (suggestion):
Thanks, @ankatiyar , for updating the missing_mandatory_keys! 
Sorry to bother you, but I noticed some code repetition concerning 'example_pipeline' and 'tools'. Perhaps we could streamline this by storing these in a dictionary with their default values. This way, we can consolidate the echo command to a single instance.

Code after:


def _validate_config_file_against_prompts(
    config: dict[str, str], prompts: dict[str, Any]
):
    """Checks that the configuration file contains all needed variables.

    Args:
        config: The config as a dictionary.
        prompts: Prompts from prompts.yml.

    Raises:
        KedroCliError: If the config file is empty or does not contain all the keys
            required in prompts, or if the output_dir specified does not exist.
    """
    if config is None:
        raise KedroCliError("Config file is empty.")
    additional_keys = {"tools": "none", "example_pipeline": "no"}
    missing_keys = set(prompts) - set(config)
    missing_mandatory_keys = missing_keys - set(additional_keys)
    if missing_mandatory_keys:
        click.echo(yaml.dump(config, default_flow_style=False))
        raise KedroCliError(
            f"{', '.join(missing_mandatory_keys)} not found in config file."
        )
    for key, default_value in additional_keys.items():
        if key in missing_keys:
            click.secho(
                f"The `{key}` key not found in the config file, default value '{default_value}' is being used.",
                fg="yellow",
            )

    if "output_dir" in config and not Path(config["output_dir"]).exists():
        raise KedroCliError(
            f"'{config['output_dir']}' is not a valid output directory. "
            "It must be a relative or absolute path to an existing directory."
        )


def _validate_config_file_inputs(config: dict[str, str]):
    """Checks that variables provided through the config file are of the expected format. This
    validate the config provided by `kedro new --config` in a similar way to `prompts.yml`
    for starters.

    Args:
        config: The config as a dictionary

    Raises:
        SystemExit: If the provided variables are not properly formatted.
    """
    project_name_validation_config = {