mm-std 0.1.11__py3-none-any.whl → 0.1.13__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.
mm_std/config.py
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
import io
|
2
|
+
import sys
|
2
3
|
from pathlib import Path
|
3
4
|
|
4
5
|
import yaml
|
5
6
|
from pydantic import BaseModel, ConfigDict, ValidationError
|
6
7
|
|
8
|
+
from .print_ import print_plain
|
7
9
|
from .result import Err, Ok, Result
|
8
10
|
from .str import str_to_list
|
9
11
|
from .zip import read_text_from_zip_archive
|
@@ -50,6 +52,23 @@ class BaseConfig(BaseModel):
|
|
50
52
|
|
51
53
|
return Ok(cls(**yaml.full_load(config_path)))
|
52
54
|
except ValidationError as err:
|
53
|
-
return Err("
|
55
|
+
return Err("validator_error", data={"errors": err.errors()})
|
54
56
|
except Exception as err:
|
55
57
|
return Err(err)
|
58
|
+
|
59
|
+
@classmethod
|
60
|
+
def read_config_or_exit[T](cls: type[T], config_path: io.TextIOWrapper | str | Path, zip_password: str = "") -> T: # noqa: PYI019 # nosec
|
61
|
+
res = cls.read_config(config_path, zip_password) # type: ignore[attr-defined]
|
62
|
+
if isinstance(res, Ok):
|
63
|
+
return res.unwrap() # type: ignore[no-any-return]
|
64
|
+
|
65
|
+
if res.err == "validator_error":
|
66
|
+
print_plain("config validation errors")
|
67
|
+
for e in res.data["errors"]:
|
68
|
+
loc = e["loc"]
|
69
|
+
field = ".".join(str(lo) for lo in loc) if len(loc) > 0 else ""
|
70
|
+
print_plain(f"{field} {e['msg']}")
|
71
|
+
else:
|
72
|
+
print_plain(f"can't parse config file: {res.err}")
|
73
|
+
|
74
|
+
sys.exit(1)
|
mm_std/json_.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import json
|
2
|
+
from collections.abc import Callable
|
2
3
|
from dataclasses import asdict, is_dataclass
|
3
4
|
from datetime import date, datetime
|
4
5
|
from decimal import Decimal
|
@@ -28,8 +29,9 @@ class CustomJSONEncoder(JSONEncoder):
|
|
28
29
|
return o.model_dump()
|
29
30
|
if isinstance(o, Exception):
|
30
31
|
return str(o)
|
32
|
+
|
31
33
|
return JSONEncoder.default(self, o)
|
32
34
|
|
33
35
|
|
34
|
-
def json_dumps(data: object) -> str:
|
35
|
-
return json.dumps(data, cls=CustomJSONEncoder)
|
36
|
+
def json_dumps(data: object, default: Callable[[object], str] | None = None) -> str:
|
37
|
+
return json.dumps(data, cls=CustomJSONEncoder, default=default)
|
mm_std/print_.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import sys
|
2
|
+
from collections.abc import Callable
|
2
3
|
from enum import Enum, unique
|
3
4
|
from typing import Any, NoReturn
|
4
5
|
|
@@ -21,13 +22,13 @@ def fatal(message: str, code: int = 1) -> NoReturn:
|
|
21
22
|
sys.exit(code)
|
22
23
|
|
23
24
|
|
24
|
-
def print_console(*messages: object, print_json: bool = False) -> None:
|
25
|
+
def print_console(*messages: object, print_json: bool = False, default: Callable[[object], str] | None = None) -> None:
|
25
26
|
if len(messages) == 1:
|
26
27
|
message = messages[0]
|
27
28
|
if isinstance(message, str):
|
28
29
|
print(message) # noqa: T201
|
29
30
|
elif print_json:
|
30
|
-
rich.print_json(json_dumps(message))
|
31
|
+
rich.print_json(json_dumps(message, default=default))
|
31
32
|
else:
|
32
33
|
rich.print(message)
|
33
34
|
else:
|
@@ -39,9 +40,9 @@ def print_plain(messages: object, print_format: PrintFormat | None = None) -> No
|
|
39
40
|
print(messages) # noqa: T201
|
40
41
|
|
41
42
|
|
42
|
-
def print_json(data: object, print_format: PrintFormat | None = None) -> None:
|
43
|
+
def print_json(data: object, default: Callable[[object], str] | None = None, print_format: PrintFormat | None = None) -> None:
|
43
44
|
if print_format is None or print_format == PrintFormat.JSON:
|
44
|
-
rich.print_json(json_dumps(data))
|
45
|
+
rich.print_json(json_dumps(data, default=default))
|
45
46
|
|
46
47
|
|
47
48
|
def print_table(title: str, columns: list[str], rows: list[list[Any]], print_format: PrintFormat | None = None) -> None:
|
mm_std/result.py
CHANGED
@@ -1,13 +1,11 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
|
3
3
|
import time
|
4
|
-
from
|
4
|
+
from collections.abc import Callable
|
5
|
+
from typing import Any, Literal, NoReturn
|
5
6
|
|
6
7
|
from pydantic_core import core_schema
|
7
8
|
|
8
|
-
if TYPE_CHECKING:
|
9
|
-
from collections.abc import Callable
|
10
|
-
|
11
9
|
|
12
10
|
class Ok[T]:
|
13
11
|
__match_args__ = ("ok",)
|
@@ -1,10 +1,10 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: mm-std
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.13
|
4
4
|
Requires-Python: >=3.12
|
5
5
|
Requires-Dist: cryptography~=44.0.0
|
6
6
|
Requires-Dist: httpx[http2,socks]~=0.28.1
|
7
|
-
Requires-Dist: pydantic~=2.10.
|
7
|
+
Requires-Dist: pydantic~=2.10.6
|
8
8
|
Requires-Dist: pydash~=8.0.5
|
9
9
|
Requires-Dist: python-dotenv~=1.0.1
|
10
10
|
Requires-Dist: pyyaml~=6.0.2
|
@@ -1,23 +1,23 @@
|
|
1
1
|
mm_std/__init__.py,sha256=dtYnmQP_HkWxIJvuCJGpex3RHvG2V0Ekh7oYstRQoco,2291
|
2
2
|
mm_std/command.py,sha256=ze286wjUjg0QSTgIu-2WZks53_Vclg69UaYYgPpQvCU,1283
|
3
3
|
mm_std/concurrency.py,sha256=4kKLhde6YQYsjJJjH6K5eMQj6FtegEz55Mo5TmhQMM0,5242
|
4
|
-
mm_std/config.py,sha256=
|
4
|
+
mm_std/config.py,sha256=VEVIg9FuFXDoqPNcFYtKI-toUrAOmr54QMMqpC6BY4Q,3065
|
5
5
|
mm_std/crypto.py,sha256=jdk0_TCmeU0pPXMyz9xH6kQHSjjZ9GcGClBwQps5vBo,340
|
6
6
|
mm_std/date.py,sha256=976eEkSONuNqHQBgSRu8hrtH23tJqztbmHFHLdbP2TY,1879
|
7
7
|
mm_std/dict.py,sha256=kJBPVG9vEqHiSgKKoji8gVGL1yEBbxAmFNn0zz17AUg,180
|
8
8
|
mm_std/env.py,sha256=5zaR9VeIfObN-4yfgxoFeU5IM1GDeZZj9SuYf7t9sOA,125
|
9
9
|
mm_std/fs.py,sha256=RwarNRJq3tIMG6LVX_g03hasfYpjYFh_O27oVDt5IPQ,291
|
10
10
|
mm_std/http_.py,sha256=QaPPXVb-rOS0BpoKdYQ0ABm_-mcR5dNa7Uqn-SeW_kE,4119
|
11
|
-
mm_std/json_.py,sha256=
|
11
|
+
mm_std/json_.py,sha256=tzrTqXDsaMX6D_J-4uesfhe9GdaxRXmEPzUzSBWSKX0,1102
|
12
12
|
mm_std/log.py,sha256=6ux6njNKc_ZCQlvWn1FZR6vcSY2Cem-mQzmNXvsg5IE,913
|
13
13
|
mm_std/net.py,sha256=qdRCBIDneip6FaPNe5mx31UtYVmzqam_AoUF7ydEyjA,590
|
14
|
-
mm_std/print_.py,sha256=
|
14
|
+
mm_std/print_.py,sha256=SKLZaxecy0ceP7olkzs5oH4XAydoquoifRuiIkhAvQY,1692
|
15
15
|
mm_std/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
16
16
|
mm_std/random_.py,sha256=OuUX4VJeSd13NZBya4qrGpR2TfN7_87tfebOY6DBUnI,1113
|
17
|
-
mm_std/result.py,sha256=
|
17
|
+
mm_std/result.py,sha256=KtYZbVJMkwwCPcV-Tnt0TkTNyDgiALvQB1DtIEp1prc,7405
|
18
18
|
mm_std/str.py,sha256=jS7VAI7i_a3iqnfaW4Iw2LZRTv0Tml4kmMbP2S2IUF4,3067
|
19
19
|
mm_std/types_.py,sha256=hvZlnvBWyB8CL_MeEWWD0Y0nN677plibYn3yD-5g7xs,99
|
20
20
|
mm_std/zip.py,sha256=2EXcae4HO5U4kObj2Lj8jl5F2OUpT-WRlJybTyFzt6I,370
|
21
|
-
mm_std-0.1.
|
22
|
-
mm_std-0.1.
|
23
|
-
mm_std-0.1.
|
21
|
+
mm_std-0.1.13.dist-info/METADATA,sha256=PZUazR5ItzzZqC-MqwXGur80VJ1Ly_ICNTxkilqN23U,307
|
22
|
+
mm_std-0.1.13.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
23
|
+
mm_std-0.1.13.dist-info/RECORD,,
|
File without changes
|