From e559a25d72fb6710842fa3f0f7bfcb90ee3df30c Mon Sep 17 00:00:00 2001
From: teplyakov <teolyakov@perx.ru>
Date: Tue, 18 Feb 2025 17:41:44 +0300
Subject: [PATCH] feat: AUTO-3805 Add init_collections function

---
 perxis/collections/helpers.py | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/perxis/collections/helpers.py b/perxis/collections/helpers.py
index 06ad1e1..f0398f8 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
-- 
GitLab