Skip to content

cc_overrides

This overrides the default cookie cutter environment.

CustomStrictEnvironment(**kwargs)

Bases: StrictEnvironment

Create strict Jinja2 environment.

Jinja2 environment will raise error on undefined variable in template-rendering context.

Does not expect all the context to be under the cookiecutter key.

_read_extensions(
    context: MutableMapping[str, Any],
) -> List[str]

Return list of extensions as str to be passed on to the Jinja2 env.

If context does not contain the relevant info, return an empty list instead.

Parameters:

context

A dict possibly containing the _extensions key

TYPE: MutableMapping[str, Any]

Returns:

List[str]

List of extensions as str to be passed on to the Jinja2 env

JsonifyContextExtension(environment: Environment)

Bases: Extension

Jinja2 extension to convert a Python object to JSON.

_render_dicts(
    context: MutableMapping,
    env: Environment,
    no_input: bool,
    prompts: dict,
) -> None

Render dictionaries.

This is the second pass of rendering. It must be done after the first pass because that renders the values that might be used as keys or values in the dictionaries.

I hate that this uses a side effect to modify the context, but I don’t see a better way.

Parameters:

context

The current context

TYPE: MutableMapping

env

The current environment for rendering

TYPE: Environment

no_input

Should we prompt the user for input?

TYPE: bool

prompts

The default prompts for the context

TYPE: dict

Raises:

UndefinedVariableInTemplate

If a variable in a prompt defaults is not in the context

_render_simple(
    context: MutableMapping,
    context_prompts: dict,
    env: Environment,
    no_input: bool,
    prompts: dict,
) -> None

Render simple variables, raw variables, and choices.

This is the first pass. It must be done first because the dictionary’s keys and values might refer to them.

I hate that this uses a side effect to modify the context, but I don’t see a better way.

Parameters:

context

The current context

TYPE: MutableMapping

context_prompts

The human prompts for the context

TYPE: dict

env

The current environment for rendering

TYPE: Environment

no_input

Should we prompt the user for input?

TYPE: bool

prompts

The default prompts for the context

TYPE: dict

Raises:

UndefinedVariableInTemplate

If a variable in a prompt defaults is not in the context

jsonify_context(value: Any) -> MutableMapping

Convert a Context to a dict.

prompt_for_config(
    prompts: dict,
    aggregated_context: Context,
    layer_context: Optional[
        MutableMapping[str, Any]
    ] = None,
    no_input: bool = False,
) -> MutableMapping[str, Any]

Prompt user to enter a new config using an existing config as a basis.

Will not prompt for configurations already in the existing configuration.

Prompts can refer to items in the existing config.

Parameters:

prompts

A dictionary of configuration prompts and default values

TYPE: dict

aggregated_context

An existing configuration to use as a basis

TYPE: Context

layer_context

A dictionary of defaults defined in the layer

TYPE: Optional[MutableMapping[str, Any]]

DEFAULT: None

no_input

If True Don’t prompt the user at command line for manual configuration

TYPE: bool

DEFAULT: False

Returns:

MutableMapping[str, Any]

A new configuration context

update_extensions(
    existing_config: MutableMapping[str, Any],
    prompts: MutableMapping[str, Any],
) -> List[str]

Merge extensions from prompts into existing config.