pestifer.core.example module¶
Defines the Example class for managing examples.
- class pestifer.core.example.Example(*args, example_id: int, title: str, shortname: str, db_id: str | None = None, author_name: str | None = None, author_email: str | None = None, input: str | Path | None = None, auxiliary_inputs: list[str | Path] | None = None, outputs: list[str | Path] | None = None)[source]¶
Bases:
BaseObjRepresents an example.
- folder_name_format: ClassVar[str] = 'ex{example_id:02d}'¶
format for the name of the root folder of each example
- model_config = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': False}¶
Configuration for
pydantic.BaseModel.
- model_post_init(context: Any, /) None¶
This function is meant to behave like a BaseModel method to initialize private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- Parameters:
self – The BaseModel instance.
context – The context.
- report_line(formatter='{:>7s} {:>4s} {:<30s} {}') str[source]¶
Generate a formatted line for reporting the example.
- to_dict(ignore_none: bool = False) dict[source]¶
Convert the example to a dictionary representation.
- Returns:
A dictionary containing the example’s attributes.
- Return type:
- to_yaml() str[source]¶
Convert the example to a YAML string.
- Returns:
A YAML representation of the example.
- Return type:
- update_options(author_name: str = None, author_email: str = None, auxiliary_inputs: list[str] = None, outputs: list[str] = None) Example[source]¶
Update the optional attributes of the example in place. Return the Example instance itself.
- Parameters:
author_name (str, optional) – The new name of the author of the example.
author_email (str, optional) – The new email of the author of the example.
auxiliary_inputs (list[str], optional) – A new list of auxiliary inputs for the example.
outputs (list[str], optional) – A new list of outputs for the example.
- Returns:
The updated Example instance.
- Return type:
- class pestifer.core.example.ExampleList(initlist: Iterable[T] = ())[source]¶
Bases:
BaseObjList[Example]Represents a list of examples.
Inherits from UserList to provide list-like behavior for managing examples.
- append(example: Example)[source]¶
Append an Example instance to the list.
- Parameters:
example (Example) – The Example instance to append.
- describe() str[source]¶
Abstract method to describe the contents of the BaseObjList. Subclasses should implement this method to provide a meaningful description.
- classmethod from_list_of_dicts(examples_list) ExampleList[source]¶
Create an ExampleList from a list of dictionaries.
- classmethod read_yaml(yaml_str: str)[source]¶
Load examples from a YAML string.
- Parameters:
yaml_str (str) – A YAML string containing the examples.