Generation Time Components#
This page documents the components that are (typically) used at the time of boilerplate generation to dicate the generation behavior.
Generation Context Object#
- class prept.GenerationContext(boilerplate: BoilerplateInfo, output_dir: pathlib.Path, variables: dict[str, Any] | None = None)#
The boilerplate generation context.
This class stores contextual and stateful information regarding generation of boilerplate files.
- output_dir#
The path to output directory where files are being generated.
- Type:
pathlib.Path
- state#
Attribute to store arbitrary data.
This attribute can take any value and is useful in storing and propagating state across Prept functions. By default, state is initialized with a
types.SimpleNamespaceinstance which allows setting arbitrary attributes on the state.
- property boilerplate: BoilerplateInfo#
The boilerplate that is being generated.
- property variables: Mapping[str, Any]#
Read-only mapping of template variables used for generating template files.
- property current_file: BoilerplateFile#
The file currently in process of being generated.
This property always returns a valid
BoilerplateFileand in a rare and niche case where no file is being generated (i.e. generation has not started yet), RuntimeError is raised.
- set_variable(name: str, value: Any) None#
Sets a template variable.
If an existing template variable is set by the same name, its value is overwritten.
- delete_variable(name: str) None#
Deletes a template variable.
If template variable does not exist, a KeyError is raised.
Boilerplate File#
- class prept.BoilerplateFile(boilerplate: BoilerplateInfo, filename: str, path: pathlib.Path, output_path: pathlib.Path)#
Represents a file from a boilerplate.
This class provides interface for interacting with the file at generation time, usually using file processors.
- boilerplate#
The boilerplate that the file is associated to.
- Type:
- property filename: str#
The name of this file.
This property can be updated at generation time to dynamically update the name of file in generated projects.
Updating this property is a shorthand equivalent of updating
output_pathfile name.
- property path: Path#
The path of boilerplate file.
This is the path where the file exists in the boilerplate, not the output directory. Use
output_pathfor path of output file.
- property output_path: Path#
The path of output file.
This is the path where the generated file will be created, not the path where file exists in the boilerplate, use
pathfor that.
- property process_path_template: bool#
Flag indicating whether this file’s path will be processed by template provider.
This is True by default and could be set to False to prevent this file’s path from being processed at generation time.
- property process_content_template: bool#
Flag indicating whether this file’s content will be processed by template provider.
This is True by default and could be set to False to prevent this file’s content from being processed at generation time.