palgen.interface#

Module Contents#

palgen.interface.max_jobs(amount)#
Parameters:

amount (int) –

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 folder

  • out_path (Path) – Output path

  • settings (Optional[dict[str, Any]], optional) – Extension settings. Defaults to None.

  • project (palgen.schemas.ProjectSettings) –

Raises:

SystemExit – If settings are provided but fail to validate

Settings: type[pydantic.BaseModel] | None#
Schema: type[pydantic.BaseModel] | None#
name: str#
description: str#
private: bool#
ingest: palgen.machinery.Pipeline | dict[str, palgen.machinery.Pipeline] | None#
pipeline: palgen.machinery.Pipeline | dict[str, palgen.machinery.Pipeline] | None#
__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 the ingest 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 schema Schema of this extension.

By default passes through whatever it received.

Parameters:

data (Iterable[tuple[Path, Any]]) – Iterable of inputs from the transform step

Yields:

tuple[Path, BaseModel | Any] – Input file path and validated Schema 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 the validate 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 the render 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 to_string()#
Return type:

str

__str__()#

Return str(self).

Return type:

str

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) – Defaults ingest to ingest toml files matching the extension name. Use ingest = 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