These modules are the Python API that template hooks use.
Cookieplone runs a template's hooks with the Python interpreter that runs Cookieplone itself, so a hook can import them.
Post-generation actions
Helpers for post-generation action hooks.
Provides run_post_gen_actions() — a single dispatcher that replaces
the boilerplate run_actions() loop duplicated across every template's
post_gen_project.py — together with a set of ready-made handlers for
common post-generation tasks (git init, file removal, file moves, namespace
packages, make format).
-
class cookieplone.utils.post_gen.PostGenAction[source]
A single post-generation action entry.
-
cookieplone.utils.post_gen.PostGenHandler
Signature for post-generation action handlers.
Receives (context, output_dir) and returns nothing.
alias of Callable[[OrderedDict, Path], None]
-
cookieplone.utils.post_gen.create_namespace_packages(context: OrderedDict, output_dir: Path) → None[source]
Create Python namespace package structure.
Reads python_package_name from context and delegates to
create_namespace_packages(). The
namespace_style key defaults to "native" (PEP 420).
-
cookieplone.utils.post_gen.initialize_git_repository(context: OrderedDict, output_dir: Path) → None[source]
Initialize a git repository in output_dir and stage all files.
Wraps initialize_repository(). After the
initial git add performed by that function, a second git add is
run to capture any files created by earlier post-gen actions.
-
cookieplone.utils.post_gen.move_files(pairs: list[tuple[str, str]]) → Callable[[OrderedDict, Path], None][source]
Return a handler that renames files within output_dir.
- Parameters:
pairs -- List of (source, destination) relative paths.
- Returns:
A PostGenHandler suitable for PostGenAction.
Example:
action = {
"handler": move_files([("docs/.readthedocs.yaml", ".readthedocs.yml")]),
"title": "Move docs config",
"enabled": True,
}
-
cookieplone.utils.post_gen.remove_files_by_key(to_remove: dict[str, list[str]], key: str) → Callable[[OrderedDict, Path], None][source]
Return a handler that removes files listed under key in to_remove.
- Parameters:
-
- Returns:
A PostGenHandler suitable for PostGenAction.
Example:
POST_GEN_TO_REMOVE = {
"devops-ansible": ["devops/ansible"],
"devops-gha": [".github/workflows/deploy.yml"],
}
action = {
"handler": remove_files_by_key(POST_GEN_TO_REMOVE, "devops-ansible"),
"title": "Remove Ansible files",
"enabled": True,
}
-
cookieplone.utils.post_gen.run_make_format(make_target: str = 'format', folder: str = '') → Callable[[OrderedDict, Path], None][source]
Return a handler that runs make <target> in a subfolder.
- Parameters:
make_target -- The make target to invoke (default "format").
folder -- Subfolder relative to output_dir. When empty, runs
in output_dir itself.
- Returns:
A PostGenHandler suitable for PostGenAction.
Example:
action = {
"handler": run_make_format("format", "backend"),
"title": "Format backend code",
"enabled": True,
}
-
cookieplone.utils.post_gen.run_post_gen_actions(context: OrderedDict, output_dir: Path, actions: list[PostGenAction]) → None[source]
Run a list of post-generation actions against a generated project.
Each action is a PostGenAction dict with handler, title,
and enabled keys. Disabled actions are logged and skipped; enabled
actions receive a deep copy of context and the output_dir.
- Parameters:
context -- The cookiecutter context OrderedDict from the
post-generation hook.
output_dir -- The generated project directory.
actions -- Ordered list of actions to execute.