mmar-mapi 1.0.9__tar.gz → 1.0.11__tar.gz

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.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mmar-mapi
3
- Version: 1.0.9
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,7 +1,7 @@
1
1
  [project]
2
2
  name = "mmar-mapi"
3
3
  # dynamic version is not supported yet on uv_build
4
- version = "1.0.9"
4
+ version = "1.0.11"
5
5
  description = "Common pure/IO utilities for multi-modal architectures team"
6
6
  authors = [{name = "Eugene Tagin", email = "tagin@airi.net"}]
7
7
  license = "MIT"
@@ -25,6 +25,7 @@ classifiers = [
25
25
  ]
26
26
  dependencies = [
27
27
  "pydantic~=2.11.7",
28
+ "loguru~=0.7.3",
28
29
  ]
29
30
 
30
31
  [build-system]
@@ -51,7 +52,6 @@ ci = [
51
52
  "mypy>=1.10",
52
53
  "types-markdown>=3.6",
53
54
  "types-pyyaml>=6.0",
54
- "more-itertools>=10.8.0",
55
55
  ]
56
56
 
57
57
  [tool.uv]
@@ -15,8 +15,9 @@ from .models.chat_item import ChatItem, OuterContextItem, InnerContextItem, Repl
15
15
  from .models.enums import MTRSLabelEnum, DiagnosticsXMLTagEnum, MTRSXMLTagEnum, DoctorChoiceXMLTagEnum
16
16
  from .models.tracks import TrackInfo, DomainInfo
17
17
  from .models.widget import Widget
18
- from .utils import make_session_id
18
+ from .utils import make_session_id, chunked
19
19
  from .xml_parser import XMLParser
20
+ from .utils_import import load_main_objects
20
21
 
21
22
  __all__ = [
22
23
  "AIMessage",
@@ -42,6 +43,8 @@ __all__ = [
42
43
  "TrackInfo",
43
44
  "Widget",
44
45
  "XMLParser",
46
+ "chunked",
47
+ "load_main_objects",
45
48
  "make_content",
46
49
  "make_session_id",
47
50
  ]
@@ -1,6 +1,6 @@
1
1
  from typing import Self, Literal
2
2
 
3
- from more_itertools import chunked
3
+ from mmar_mapi.utils import chunked
4
4
  from pydantic import BaseModel, model_validator
5
5
 
6
6
 
@@ -0,0 +1,16 @@
1
+ from itertools import islice
2
+ from collections.abc import Iterable
3
+ from datetime import datetime
4
+
5
+
6
+ def make_session_id() -> str:
7
+ return f"{datetime.now():%Y-%m-%d--%H-%M-%S}"
8
+
9
+
10
+ def chunked(items: Iterable, n) -> list:
11
+ "behavior like in more_itertools.chunked"
12
+ iterator = iter(items)
13
+ res = []
14
+ while chunk := list(islice(iterator, n)):
15
+ res.append(chunk)
16
+ return res
@@ -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,5 +0,0 @@
1
- from datetime import datetime
2
-
3
-
4
- def make_session_id() -> str:
5
- return f"{datetime.now():%Y-%m-%d--%H-%M-%S}"
File without changes
File without changes