rechu.inventory package

Submodules

rechu.inventory.base module

Bag of files containing multiple grouped models that share common properties.

class rechu.inventory.base.Inventory[source]

Bases: Mapping[Path, Sequence[T]]

An inventory of a type of model grouped by one or more characteristics, which are concretized in file names.

find(key: Hashable, update_map: bool = False) T[source]

Find metadata for a model identified by a unique key, or if it is not found, create an empty model with only properties deduced from the key. If update_map is True, ensures that the most recent changes to the inventory are reflected, otherwise direct mutations of path elements may not be considered or a cached map may be used.

get_writers() Iterator[Writer[T]][source]

Obtain writers for each inventory file.

merge_update(other: Inventory[T], update: bool = True, only_new: bool = False) Inventory[T][source]

Find groups with models that are added or updated in the other inventory compared to the current inventory. The returned inventory contains the new, existing and merged models grouped by path; only paths with changes are included. The products in the current inventory are updated as well. If update is enabled, then new models are added to and changed models updated in the current inventory; this is the default. If update is disabled, then only the updated models are provided in the return value and the current object also remains immutable. If only_new is enabled, then models that existed but had changes are not considered, just like unchanged models; only_new inherently disables update.

classmethod read() Inventory[T][source]

Create an inventory based on models stored in files.

classmethod select(session: Session, selectors: list[dict[str, str | None]] | None = None) Inventory[T][source]

Create an inventory based on models stored in the database.

classmethod spread(models: Iterable[T]) Inventory[T][source]

Create an inventory based on provided models by assigning them to groups that each belongs to.

write() None[source]

Write an inventory to files.

rechu.inventory.products module

Products inventory.

class rechu.inventory.products.Products(mapping=None, /, parts: Iterable[Literal['shop', 'brand', 'category', 'type']] | None = None)[source]

Bases: dict, Inventory[Product]

Inventory of products grouped by their identifying fields.

find(key: Hashable, update_map: bool = False) Product[source]

Find metadata for a model identified by a unique key, or if it is not found, create an empty model with only properties deduced from the key. If update_map is True, ensures that the most recent changes to the inventory are reflected, otherwise direct mutations of path elements may not be considered or a cached map may be used.

static get_parts(settings: Settings) tuple[str, str, Iterable[Literal['shop', 'brand', 'category', 'type']], Pattern[str]][source]

Retrieve various formatting, selecting and matching parts for inventory filenames of products.

get_writers() Iterator[ProductsWriter][source]

Obtain writers for each inventory file.

merge_update(other: Inventory[Product], update: bool = True, only_new: bool = False) Inventory[Product][source]

Find groups with models that are added or updated in the other inventory compared to the current inventory. The returned inventory contains the new, existing and merged models grouped by path; only paths with changes are included. The products in the current inventory are updated as well. If update is enabled, then new models are added to and changed models updated in the current inventory; this is the default. If update is disabled, then only the updated models are provided in the return value and the current object also remains immutable. If only_new is enabled, then models that existed but had changes are not considered, just like unchanged models; only_new inherently disables update.

classmethod read() Inventory[Product][source]

Create an inventory based on models stored in files.

classmethod select(session: Session, selectors: list[dict[str, str | None]] | None = None) Inventory[Product][source]

Create an inventory based on models stored in the database.

classmethod spread(models: Iterable[Product]) Inventory[Product][source]

Create an inventory based on provided models by assigning them to groups that each belongs to.

rechu.inventory.shops module

Shops inventory.

class rechu.inventory.shops.Shops(mapping=None, /)[source]

Bases: dict, Inventory[Shop]

Inventory of shops.

find(key: Hashable, update_map: bool = False) Shop[source]

Find metadata for a model identified by a unique key, or if it is not found, create an empty model with only properties deduced from the key. If update_map is True, ensures that the most recent changes to the inventory are reflected, otherwise direct mutations of path elements may not be considered or a cached map may be used.

get_writers() Iterator[ShopsWriter][source]

Obtain writers for each inventory file.

merge_update(other: Inventory[Shop], update: bool = True, only_new: bool = False) Inventory[Shop][source]

Find groups with models that are added or updated in the other inventory compared to the current inventory. The returned inventory contains the new, existing and merged models grouped by path; only paths with changes are included. The products in the current inventory are updated as well. If update is enabled, then new models are added to and changed models updated in the current inventory; this is the default. If update is disabled, then only the updated models are provided in the return value and the current object also remains immutable. If only_new is enabled, then models that existed but had changes are not considered, just like unchanged models; only_new inherently disables update.

classmethod read() Inventory[Shop][source]

Create an inventory based on models stored in files.

classmethod select(session: Session, selectors: list[dict[str, str | None]] | None = None) Inventory[Shop][source]

Create an inventory based on models stored in the database.

classmethod spread(models: Iterable[Shop]) Inventory[Shop][source]

Create an inventory based on provided models by assigning them to groups that each belongs to.

Module contents

Submodule for inventory of grouped models.

class rechu.inventory.Inventory[source]

Bases: Mapping[Path, Sequence[T]]

An inventory of a type of model grouped by one or more characteristics, which are concretized in file names.

find(key: Hashable, update_map: bool = False) T[source]

Find metadata for a model identified by a unique key, or if it is not found, create an empty model with only properties deduced from the key. If update_map is True, ensures that the most recent changes to the inventory are reflected, otherwise direct mutations of path elements may not be considered or a cached map may be used.

get_writers() Iterator[Writer[T]][source]

Obtain writers for each inventory file.

merge_update(other: Inventory[T], update: bool = True, only_new: bool = False) Inventory[T][source]

Find groups with models that are added or updated in the other inventory compared to the current inventory. The returned inventory contains the new, existing and merged models grouped by path; only paths with changes are included. The products in the current inventory are updated as well. If update is enabled, then new models are added to and changed models updated in the current inventory; this is the default. If update is disabled, then only the updated models are provided in the return value and the current object also remains immutable. If only_new is enabled, then models that existed but had changes are not considered, just like unchanged models; only_new inherently disables update.

classmethod read() Inventory[T][source]

Create an inventory based on models stored in files.

classmethod select(session: Session, selectors: list[dict[str, str | None]] | None = None) Inventory[T][source]

Create an inventory based on models stored in the database.

classmethod spread(models: Iterable[T]) Inventory[T][source]

Create an inventory based on provided models by assigning them to groups that each belongs to.

write() None[source]

Write an inventory to files.