Skip to content

load_config

get_interpreters_from_yaml(config_file)

Parse the 'interpreters' variable out of the user's config yaml file.

Parameters:

Name Type Description Default
config_file str

path to the user's config yaml file

required

Raises:

Type Description
InvalidYamlFormatError

if yaml parser fails to load the user's config

UserYamlDesignError

if yaml does not contain the 'default_context' key

Returns:

Type Description
Optional[SupportedInterpreters]

t.Mapping[str, t.Sequence[str]]: dictionary with intepreters as a sequence of strings, mapped to the 'supported-interpreters' key

Source code in src/cookiecutter_python/backend/load_config.py
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
def get_interpreters_from_yaml(
    config_file: str,
) -> t.Optional[SupportedInterpreters]:
    """Parse the 'interpreters' variable out of the user's config yaml file.

    Args:
        config_file (str): path to the user's config yaml file

    Raises:
        InvalidYamlFormatError: if yaml parser fails to load the user's config
        UserYamlDesignError: if yaml does not contain the 'default_context' key

    Returns:
        t.Mapping[str, t.Sequence[str]]: dictionary with intepreters as a sequence of strings,
            mapped to the 'supported-interpreters' key
    """
    # Step 1: Load YAML data
    data = load_yaml(config_file)

    # Step 2: Validate YAML structure
    context = _validate_and_get_context(data)

    # Step 3: Extract interpreters
    return _extract_interpreters(context)