svetlanna.specs package

Submodules

svetlanna.specs.specs module

class svetlanna.specs.specs.HTMLRepresentation

Bases: Representation[ParameterSaveContext_]

Representation that can be exported to the HTML

abstract to_html(out: TextIO, context: ParameterSaveContext_) None

Write the parameter related data to be shown in a HTML file. The text should be written to the out stream.

Parameters

outTextIO

output text stream

contextParameterSaveContext_

the parameter save context

class svetlanna.specs.specs.ImageRepr(value: Any, mode: Literal['1', 'L', 'LA', 'I', 'P', 'RGB', 'RGBA'] = 'L', format: str = 'png', show_image: bool = True)

Bases: StrRepresentation, MarkdownRepresentation, HTMLRepresentation

Representation of the parameter as an image. Image generation is based on the pillow package.

draw_image(context: ParameterSaveContext, filepath: Path) Image

Draw image into the file, using pillow package.

Parameters

contextParameterSaveContext

the parameter save context

filepathPath

path to the image file to be created

to_html(out: TextIO, context: ParameterSaveContext)

Write the parameter related data to be shown in a HTML file. The text should be written to the out stream.

Parameters

outTextIO

output text stream

contextParameterSaveContext_

the parameter save context

to_markdown(out: TextIO, context: ParameterSaveContext)

Write the parameter related data to be shown in a markdown file. The text should be written to the out stream.

Parameters

outTextIO

output text stream

contextParameterSaveContext_

the parameter save context

to_str(out: TextIO, context: ParameterSaveContext)

Write the parameter related data to be shown as a plain text. The text should be written to the out stream.

Parameters

outTextIO

output text stream

contextParameterSaveContext_

the parameter save context

class svetlanna.specs.specs.MarkdownRepresentation

Bases: Representation[ParameterSaveContext_]

Representation that can be exported to markdown file

abstract to_markdown(out: TextIO, context: ParameterSaveContext_) None

Write the parameter related data to be shown in a markdown file. The text should be written to the out stream.

Parameters

outTextIO

output text stream

contextParameterSaveContext_

the parameter save context

class svetlanna.specs.specs.NpyFileRepr(value: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes])

Bases: StrRepresentation, MarkdownRepresentation

Representation of the parameter as a .npy file.

save_to_file(context: ParameterSaveContext, filepath: Path)

Save the parameter related data to npy file.

Parameters

contextParameterSaveContext

the parameter save context

filepathPath

path to the file to be created

to_markdown(out: TextIO, context: ParameterSaveContext)

Write the parameter related data to be shown in a markdown file. The text should be written to the out stream.

Parameters

outTextIO

output text stream

contextParameterSaveContext_

the parameter save context

to_str(out: TextIO, context: ParameterSaveContext)

Write the parameter related data to be shown as a plain text. The text should be written to the out stream.

Parameters

outTextIO

output text stream

contextParameterSaveContext_

the parameter save context

class svetlanna.specs.specs.ParameterSaveContext(parameter_name: str, directory: Path)

Bases: object

Generates different context managers that can be used to write a parameter data to output stream or file.

file(filepath: Path) Generator[BufferedWriter, Any, None]

Context manager for the output file

Parameters

filepathPath

filepath

Yields

Generator[BufferedWriter, Any, None]

Buffer

get_new_filepath(extension: str) Path

Create a new filepath for a specific extension. The generated filename of a specific extension will have a unique name ending with _<n>.<extension>, where <n> is auto-incrementing index.

Parameters

extensionstr

filename extension

Returns

Path

relative path to the file

rel_filepath(filepath: Path) Path

Get relative to specs file filepath

Parameters

filepathPath

absolute path

Returns

Path

relative path

class svetlanna.specs.specs.ParameterSpecs(parameter_name: str, representations: Iterable[Representation])

Bases: object

Container with all representations for the parameter.

class svetlanna.specs.specs.PrettyReprRepr(value: Any, units: str | None = None)

Bases: ReprRepr, HTMLRepresentation

Same as ReprRepr but with better handling of Parameters and BoundedParameter

to_html(out: TextIO, context: ParameterSaveContext)

Write the parameter related data to be shown in a HTML file. The text should be written to the out stream.

Parameters

outTextIO

output text stream

contextParameterSaveContext_

the parameter save context

to_markdown(out: TextIO, context: ParameterSaveContext)

Write the parameter related data to be shown in a markdown file. The text should be written to the out stream.

Parameters

outTextIO

output text stream

contextParameterSaveContext_

the parameter save context

to_str(out: TextIO, context: ParameterSaveContext)

Write the parameter related data to be shown as a plain text. The text should be written to the out stream.

Parameters

outTextIO

output text stream

contextParameterSaveContext_

the parameter save context

class svetlanna.specs.specs.ReprRepr(value: Any)

Bases: StrRepresentation, MarkdownRepresentation, HTMLRepresentation

Representation of the parameter as a plain text. The __repr__ method is used to generate the text.

to_html(out: TextIO, context: Any)

Write the parameter related data to be shown in a HTML file. The text should be written to the out stream.

Parameters

outTextIO

output text stream

contextParameterSaveContext_

the parameter save context

to_markdown(out: TextIO, context: ParameterSaveContext)

Write the parameter related data to be shown in a markdown file. The text should be written to the out stream.

Parameters

outTextIO

output text stream

contextParameterSaveContext_

the parameter save context

to_str(out: TextIO, context: ParameterSaveContext)

Write the parameter related data to be shown as a plain text. The text should be written to the out stream.

Parameters

outTextIO

output text stream

contextParameterSaveContext_

the parameter save context

class svetlanna.specs.specs.Representation

Bases: Generic[ParameterSaveContext_]

Base class for a parameter representation

class svetlanna.specs.specs.Specsable(*args, **kwargs)

Bases: Protocol

Represents any specsable object

to_specs() Iterable[ParameterSpecs | SubelementSpecs]
class svetlanna.specs.specs.StrRepresentation

Bases: Representation[ParameterSaveContext_]

Representation that can be exported in the text format

abstract to_str(out: TextIO, context: ParameterSaveContext_) None

Write the parameter related data to be shown as a plain text. The text should be written to the out stream.

Parameters

outTextIO

output text stream

contextParameterSaveContext_

the parameter save context

class svetlanna.specs.specs.SubelementSpecs(subelement_type: str, subelement: Specsable)

Bases: object

Container for named subelement

svetlanna.specs.specs_writer module

svetlanna.specs.specs_writer.context_generator(element: Specsable, element_index: int, directory: str | Path, subelements: list[SubelementSpecs]) Generator[_WriterContext, None, None]

Generate _WriterContext for the element

Parameters

elementSpecsable

Element

element_indexint

Index of the element. It is used to create unique directory for element specs.

directorystr | Path

Directory where element directory is created

Yields

_WriterContext

context

svetlanna.specs.specs_writer.write_elements_tree_to_markdown(tree: list[_ElementInTree], stream: TextIO)
svetlanna.specs.specs_writer.write_elements_tree_to_str(tree: list[_ElementInTree], stream: TextIO)
svetlanna.specs.specs_writer.write_specs(*iterables: Specsable, filename: str = 'specs.txt', directory: str | Path = 'specs')
svetlanna.specs.specs_writer.write_specs_to_html(element: Specsable, element_index: int, writer_context_generator: Generator[_WriterContext, None, None], stream: TextIO)
svetlanna.specs.specs_writer.write_specs_to_markdown(element: Specsable, element_index: int, writer_context_generator: Generator[_WriterContext, None, None], stream: TextIO)
svetlanna.specs.specs_writer.write_specs_to_str(element: Specsable, element_index: int, writer_context_generator: Generator[_WriterContext, None, None], stream: TextIO)

Module contents

class svetlanna.specs.HTMLRepresentation

Bases: Representation[ParameterSaveContext_]

Representation that can be exported to the HTML

abstract to_html(out: TextIO, context: ParameterSaveContext_) None

Write the parameter related data to be shown in a HTML file. The text should be written to the out stream.

Parameters

outTextIO

output text stream

contextParameterSaveContext_

the parameter save context

class svetlanna.specs.ImageRepr(value: Any, mode: Literal['1', 'L', 'LA', 'I', 'P', 'RGB', 'RGBA'] = 'L', format: str = 'png', show_image: bool = True)

Bases: StrRepresentation, MarkdownRepresentation, HTMLRepresentation

Representation of the parameter as an image. Image generation is based on the pillow package.

draw_image(context: ParameterSaveContext, filepath: Path) Image

Draw image into the file, using pillow package.

Parameters

contextParameterSaveContext

the parameter save context

filepathPath

path to the image file to be created

to_html(out: TextIO, context: ParameterSaveContext)

Write the parameter related data to be shown in a HTML file. The text should be written to the out stream.

Parameters

outTextIO

output text stream

contextParameterSaveContext_

the parameter save context

to_markdown(out: TextIO, context: ParameterSaveContext)

Write the parameter related data to be shown in a markdown file. The text should be written to the out stream.

Parameters

outTextIO

output text stream

contextParameterSaveContext_

the parameter save context

to_str(out: TextIO, context: ParameterSaveContext)

Write the parameter related data to be shown as a plain text. The text should be written to the out stream.

Parameters

outTextIO

output text stream

contextParameterSaveContext_

the parameter save context

class svetlanna.specs.MarkdownRepresentation

Bases: Representation[ParameterSaveContext_]

Representation that can be exported to markdown file

abstract to_markdown(out: TextIO, context: ParameterSaveContext_) None

Write the parameter related data to be shown in a markdown file. The text should be written to the out stream.

Parameters

outTextIO

output text stream

contextParameterSaveContext_

the parameter save context

class svetlanna.specs.NpyFileRepr(value: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes])

Bases: StrRepresentation, MarkdownRepresentation

Representation of the parameter as a .npy file.

save_to_file(context: ParameterSaveContext, filepath: Path)

Save the parameter related data to npy file.

Parameters

contextParameterSaveContext

the parameter save context

filepathPath

path to the file to be created

to_markdown(out: TextIO, context: ParameterSaveContext)

Write the parameter related data to be shown in a markdown file. The text should be written to the out stream.

Parameters

outTextIO

output text stream

contextParameterSaveContext_

the parameter save context

to_str(out: TextIO, context: ParameterSaveContext)

Write the parameter related data to be shown as a plain text. The text should be written to the out stream.

Parameters

outTextIO

output text stream

contextParameterSaveContext_

the parameter save context

class svetlanna.specs.ParameterSaveContext(parameter_name: str, directory: Path)

Bases: object

Generates different context managers that can be used to write a parameter data to output stream or file.

file(filepath: Path) Generator[BufferedWriter, Any, None]

Context manager for the output file

Parameters

filepathPath

filepath

Yields

Generator[BufferedWriter, Any, None]

Buffer

get_new_filepath(extension: str) Path

Create a new filepath for a specific extension. The generated filename of a specific extension will have a unique name ending with _<n>.<extension>, where <n> is auto-incrementing index.

Parameters

extensionstr

filename extension

Returns

Path

relative path to the file

rel_filepath(filepath: Path) Path

Get relative to specs file filepath

Parameters

filepathPath

absolute path

Returns

Path

relative path

class svetlanna.specs.ParameterSpecs(parameter_name: str, representations: Iterable[Representation])

Bases: object

Container with all representations for the parameter.

class svetlanna.specs.PrettyReprRepr(value: Any, units: str | None = None)

Bases: ReprRepr, HTMLRepresentation

Same as ReprRepr but with better handling of Parameters and BoundedParameter

to_html(out: TextIO, context: ParameterSaveContext)

Write the parameter related data to be shown in a HTML file. The text should be written to the out stream.

Parameters

outTextIO

output text stream

contextParameterSaveContext_

the parameter save context

to_markdown(out: TextIO, context: ParameterSaveContext)

Write the parameter related data to be shown in a markdown file. The text should be written to the out stream.

Parameters

outTextIO

output text stream

contextParameterSaveContext_

the parameter save context

to_str(out: TextIO, context: ParameterSaveContext)

Write the parameter related data to be shown as a plain text. The text should be written to the out stream.

Parameters

outTextIO

output text stream

contextParameterSaveContext_

the parameter save context

class svetlanna.specs.ReprRepr(value: Any)

Bases: StrRepresentation, MarkdownRepresentation, HTMLRepresentation

Representation of the parameter as a plain text. The __repr__ method is used to generate the text.

to_html(out: TextIO, context: Any)

Write the parameter related data to be shown in a HTML file. The text should be written to the out stream.

Parameters

outTextIO

output text stream

contextParameterSaveContext_

the parameter save context

to_markdown(out: TextIO, context: ParameterSaveContext)

Write the parameter related data to be shown in a markdown file. The text should be written to the out stream.

Parameters

outTextIO

output text stream

contextParameterSaveContext_

the parameter save context

to_str(out: TextIO, context: ParameterSaveContext)

Write the parameter related data to be shown as a plain text. The text should be written to the out stream.

Parameters

outTextIO

output text stream

contextParameterSaveContext_

the parameter save context

class svetlanna.specs.Representation

Bases: Generic[ParameterSaveContext_]

Base class for a parameter representation

class svetlanna.specs.Specsable(*args, **kwargs)

Bases: Protocol

Represents any specsable object

to_specs() Iterable[ParameterSpecs | SubelementSpecs]
class svetlanna.specs.StrRepresentation

Bases: Representation[ParameterSaveContext_]

Representation that can be exported in the text format

abstract to_str(out: TextIO, context: ParameterSaveContext_) None

Write the parameter related data to be shown as a plain text. The text should be written to the out stream.

Parameters

outTextIO

output text stream

contextParameterSaveContext_

the parameter save context

class svetlanna.specs.SubelementSpecs(subelement_type: str, subelement: Specsable)

Bases: object

Container for named subelement