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: BaseObj

Represents an example.

author_email: str | None
author_name: str | None
auxiliary_inputs: list[str | Path] | None
db_id: str | None
example_id: int
folder_name_format: ClassVar[str] = 'ex{example_id:02d}'

format for the name of the root folder of each example

input: str | Path | None
inputs_subdir: ClassVar[str] = 'inputs'
property inputspath: Path
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.

outputs: list[str | Path] | None
outputs_subdir: ClassVar[str] = 'outputs'
property outputspath: Path
report_line(formatter='{:>7s}    {:>4s}  {:<30s}    {}') str[source]

Generate a formatted line for reporting the example.

Parameters:

formatter (str, optional) – A format string for the report. Default is a string that formats the index, name, pdbID, and title of the example.

Returns:

A formatted string representing the example.

Return type:

str

property rootfolderpath: Path
property scriptname: str
property scriptpath: Path
shortname: str
title: str
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:

dict

to_yaml() str[source]

Convert the example to a YAML string.

Returns:

A YAML representation of the example.

Return type:

str

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:

Example

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.

Parameters:

examples_list (list of dict) – A list of dictionaries, each representing an example.

Returns:

An instance of ExampleList containing the examples.

Return type:

ExampleList

from_yaml(yaml_str: str, overwrite: bool = False)[source]

Load examples from a YAML string.

Parameters:
  • yaml_str (str) – A YAML string containing the examples.

  • overwrite (bool) – Whether to overwrite existing examples.

get_example_by_example_id(example_id: int) Example[source]
get_example_by_shortname(shortname: str) Example[source]

Get an example by its shortname.

Parameters:

name (str) – The name of the example to retrieve.

Returns:

The Example instance with the specified name or None if not found.

Return type:

Example

classmethod read_yaml(yaml_str: str)[source]

Load examples from a YAML string.

Parameters:

yaml_str (str) – A YAML string containing the examples.

to_list_of_dicts() list[source]

Convert the list of examples to a list of dictionaries.

Returns:

A list of dictionaries, each representing an example.

Return type:

list

to_yaml() str[source]

Convert the list of examples to a YAML string.

Returns:

A YAML representation of the examples.

Return type:

str