diff --git a/perxis/collections/helpers.py b/perxis/collections/helpers.py index 06ad1e1e3f106d9d8c0ae174e8200e8d3739b1ce..f0398f8b8ff1629b0539c95f5b077bc61199e935 100644 --- a/perxis/collections/helpers.py +++ b/perxis/collections/helpers.py @@ -1,7 +1,11 @@ from perxis.collections import collections_pb2 +from typing_extensions import deprecated -def make_collection_instances(schemes_dir: str, schemes_mapping: dict[str, str]) -> list[collections_pb2.Collection]: +@deprecated("This function is deprecated. Use `init_collections` instead.") +def make_collection_instances( + schemes_dir: str, schemes_mapping: dict[str, str] +) -> list[collections_pb2.Collection]: collections = [] for collection_id, collection_name in schemes_mapping.items(): @@ -13,7 +17,27 @@ def make_collection_instances(schemes_dir: str, schemes_mapping: dict[str, str]) name=collection_name, schema=collection_schema ) - collections.append(collection) + return collections + + +def init_collections( + schemes_dir: str, + schemes_mapping: dict[str, str], + collections_settings_mapping: dict[str, dict[str, ...]], +) -> list[collections_pb2.Collection]: - return collections \ No newline at end of file + collections = [] + for collection_id, collection_name in schemes_mapping.items(): + with open(f"{schemes_dir}/{collection_id}.json", "r") as file: + collection_schema = file.read() + + kwargs = { + **(collections_settings_mapping.get(collection_id) or {}), + "id": collection_id, + "name": collection_name, + "schema": collection_schema, + } + collection = collections_pb2.Collection(**kwargs) + collections.append(collection) + return collections