mmar-mapi 1.0.10__py3-none-any.whl → 1.0.11__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of mmar-mapi might be problematic. Click here for more details.

mmar_mapi/__init__.py CHANGED
@@ -17,7 +17,7 @@ from .models.tracks import TrackInfo, DomainInfo
17
17
  from .models.widget import Widget
18
18
  from .utils import make_session_id, chunked
19
19
  from .xml_parser import XMLParser
20
-
20
+ from .utils_import import load_main_objects
21
21
 
22
22
  __all__ = [
23
23
  "AIMessage",
@@ -44,6 +44,7 @@ __all__ = [
44
44
  "Widget",
45
45
  "XMLParser",
46
46
  "chunked",
47
+ "load_main_objects",
47
48
  "make_content",
48
49
  "make_session_id",
49
50
  ]
@@ -0,0 +1,42 @@
1
+ from pkgutil import iter_modules
2
+ from importlib import import_module
3
+ from types import ModuleType
4
+
5
+ from loguru import logger
6
+
7
+ def convert_snake_to_pascal(name: str) -> str:
8
+ """ snake_to_pascal -> SnakeToPascal """
9
+ return "".join(map(str.capitalize, name.split("_")))
10
+
11
+
12
+ def get_main_object_name(module: type[ModuleType]) -> str:
13
+ module_name = module.__name__.rsplit(".", 1)[-1]
14
+ main_object_name = convert_snake_to_pascal(module_name)
15
+ return main_object_name
16
+
17
+
18
+ def get_main_object(module: type[ModuleType], obj_type):
19
+ """tries to find SomeObject in object src.some_object"""
20
+ main_object_name = get_main_object_name(module)
21
+ try:
22
+ res = getattr(module, main_object_name)
23
+ if not isinstance(res, obj_type) and not issubclass(res, obj_type):
24
+ logger.error(f"Failed to load {module}.{main_object_name}: expected {obj_type} but found {type(res)}")
25
+ return None
26
+ return res
27
+ except AttributeError as ex:
28
+ logger.error(f"Failed to load {module}.{main_object_name}: {ex}")
29
+ return None
30
+
31
+
32
+ def load_modules(package_name: str) -> list[type[ModuleType]]:
33
+ package = import_module(package_name)
34
+ res = [import_module(module_name) for _, module_name, _ in iter_modules(package.__path__, package_name + ".")]
35
+ return res
36
+
37
+
38
+ def load_main_objects(package_name: str, obj_type: type) -> dict[str, object]:
39
+ modules = load_modules(package_name)
40
+ main_objects = [get_main_object(m, obj_type) for m in modules]
41
+ res = {obj.__name__: obj for obj in main_objects}
42
+ return res
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mmar-mapi
3
- Version: 1.0.10
3
+ Version: 1.0.11
4
4
  Summary: Common pure/IO utilities for multi-modal architectures team
5
5
  Keywords:
6
6
  Author: Eugene Tagin
@@ -20,6 +20,7 @@ Classifier: Topic :: Software Development
20
20
  Classifier: Topic :: Utilities
21
21
  Classifier: Typing :: Typed
22
22
  Requires-Dist: pydantic~=2.11.7
23
+ Requires-Dist: loguru~=0.7.3
23
24
  Requires-Python: >=3.12
24
25
  Description-Content-Type: text/markdown
25
26
 
@@ -1,4 +1,4 @@
1
- mmar_mapi/__init__.py,sha256=NxCsA3aMKjxIZ2f4pQTJ1LPpg7t2yz7PsiDeb_HrAJE,1109
1
+ mmar_mapi/__init__.py,sha256=Q2WFyNje0mDzP3eK7k-900W4Uty82BlulKv9-FmkcZs,1177
2
2
  mmar_mapi/api.py,sha256=C9Sr8dISvf51xfEznPjccI_odaG4coQE3HI_0jVpjMQ,1677
3
3
  mmar_mapi/file_storage.py,sha256=GbahBabBdAKjlAnv1MszERUxxZyA9HGMiR9tz2a9dgY,4409
4
4
  mmar_mapi/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -10,8 +10,9 @@ mmar_mapi/models/tracks.py,sha256=HKDp-BX1p7AlDfSEKfOKCu0TRSK9cD4Dmq1vJt8oRjw,30
10
10
  mmar_mapi/models/widget.py,sha256=ue5o4AkN8SG09aA8eQLOOxbwah-mkZir0ZGL6OA8S9Q,1355
11
11
  mmar_mapi/type_union.py,sha256=diwmzcnbqkpGFckPHNw9o8zyQ955mOGNvhTlcBJ0RMI,1905
12
12
  mmar_mapi/utils.py,sha256=oVrEAHGcfFBprwdTEzSbFCpdLtkDRVzWtOnYpS439os,394
13
+ mmar_mapi/utils_import.py,sha256=47qNpd41ZvzJQsPtielqTlikO-N3xUXlj5LnoGrbM5g,1562
13
14
  mmar_mapi/xml_parser.py,sha256=VvLIX_XCZao9i0qqpTVx8nx0vbFXSe8pEbdJdXnj97g,568
14
- mmar_mapi-1.0.10.dist-info/licenses/LICENSE,sha256=2A90w8WjhOgQXnFuUijKJYazaqZ4_NTokYb9Po4y-9k,1061
15
- mmar_mapi-1.0.10.dist-info/WHEEL,sha256=Pi5uDq5Fdo_Rr-HD5h9BiPn9Et29Y9Sh8NhcJNnFU1c,79
16
- mmar_mapi-1.0.10.dist-info/METADATA,sha256=cL99l0W1GOtgnJOUNDyflzdkbMNHNfGwNpdiLnhFIz0,915
17
- mmar_mapi-1.0.10.dist-info/RECORD,,
15
+ mmar_mapi-1.0.11.dist-info/licenses/LICENSE,sha256=2A90w8WjhOgQXnFuUijKJYazaqZ4_NTokYb9Po4y-9k,1061
16
+ mmar_mapi-1.0.11.dist-info/WHEEL,sha256=Pi5uDq5Fdo_Rr-HD5h9BiPn9Et29Y9Sh8NhcJNnFU1c,79
17
+ mmar_mapi-1.0.11.dist-info/METADATA,sha256=JGGIso4M27c1Rf48uIx5OtdTGQ5-PQwzZ2Kr89kZm74,944
18
+ mmar_mapi-1.0.11.dist-info/RECORD,,