palgen.interface
#
Module Contents#
- class palgen.interface.Extension(project, root_path, out_path, settings=None)#
palgen.interface.Extension palgen.interface.Extension palgen.interface.Extension palgen.interface.Extension palgen.schemas.project.ProjectSettings palgen.schemas.project.ProjectSettings palgen.schemas.project.ProjectSettings palgen.schemas.project.ProjectSettings->palgen.interface.Extension project pydantic.main.BaseModel pydantic.main.BaseModel palgen.schemas.project.ProjectSettings->pydantic.main.BaseModel pathlib.Path pathlib.Path pathlib.Path->palgen.interface.Extension root_path pathlib.Path->palgen.interface.Extension out_path pathlib.PurePath pathlib.PurePath pathlib.Path->pathlib.PurePath Extension constructor. If settings are provided they are checked against the
Settings
schema.It’s not recommended to override this unless you want to disable settings validation.
- Parameters:
root_path (
Path
) – Path to the project’s root folderout_path (
Path
) – Output pathsettings (
Optional[dict[str, Any]], optional
) – Extension settings. Defaults to None.project (palgen.schemas.ProjectSettings) –
- Raises:
SystemExit – If settings are provided but fail to validate
- __slots__ = ('root_path', 'out_path', 'project', 'settings')#
- transform(data)#
This step is intended to transform input data to something pydantic can validate in the
validate
step.By default passes through whatever it received.
- Parameters:
data (
Iterable[tuple[Path, Any]]
) – Iterable of inputs from theingest
pipeline- Yields:
tuple[Path, Any]
– Transformed output- Return type:
Iterable[tuple[pathlib.Path, Any]]
- validate(data)#
Intended to validate elements in the
data
Iterable against the pydantic schemaSchema
of this extension.By default passes through whatever it received.
- Parameters:
data (
Iterable[tuple[Path, Any]]
) – Iterable of inputs from thetransform
step- Yields:
tuple[Path, BaseModel | Any]
– Input file path and validatedSchema
object- Return type:
Iterable[tuple[pathlib.Path, Any]]
- render(data)#
Intended to render the output content.
By default yields nothing.
- Parameters:
data (
Iterable[tuple[str, Meta, BaseModel]]
) – Iterable of inputs from thevalidate
step.- Yields:
tuple[Path, str]
– Output path and content for generated files- Return type:
Iterable[tuple[pathlib.Path, str | bytes]]
- write(output)#
Write the rendered files back to disk.
- Parameters:
output (
Iterable[tuple[Path, str]]
) – Iterable of inputs from therender
step- Yields:
Path
– Path to every generated file- Return type:
Iterable[pathlib.Path]
- run(files, jobs=None)#
Runs the extension’s pipeline. If the pipeline is a dictionary, it will loop through each item and run the associated pipeline. Otherwise, it will run the single pipeline.
This method may be overridden for extensions that do not wish to use the default pipelines at all or need to do custom pipeline preprocessing.
- Parameters:
files (
list[Path]
) – possibly pre-filtered list of paths to consider for ingest.jobs (
Optional[int]
) – Maximum number of jobs to spawn. Defaults to None.
- Returns:
Aggregated list of paths to generated files
- Return type:
list[Path]
- classmethod __init_subclass__(*, name=None, private=False)#
This class method is used to preprocess subclasses of the
Extension
interface.It sets the following attributes on the subclass:
- Variables:
path (
Path
) – Path object containing the filename of the subclass.name (
str
) – Name of the subclass. If no name is provided, the name of the class converted to lowercase is used.private (
bool
) – Indicates whether the subclass should be private or not.ingest (
Pipeline
) – Defaultsingest
to ingest toml files matching the extension name. Useingest = None
if you want to disable ingest.
- Parameters:
name (
Optional[str], optional
) – Overrides the extension name. Defaults to None.private (
bool, optional
) – Sets this extension as private. Defaults to False.
- Raises:
RuntimeError – Throws RuntimeError if an invalid ingest pipeline has been given.
- Return type:
None