mm-std 0.1.10__py3-none-any.whl → 0.1.12__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,10 +1,11 @@
|
|
1
1
|
import io
|
2
|
+
import sys
|
2
3
|
from pathlib import Path
|
3
|
-
from typing import Self
|
4
4
|
|
5
5
|
import yaml
|
6
6
|
from pydantic import BaseModel, ConfigDict, ValidationError
|
7
7
|
|
8
|
+
from .print_ import print_plain
|
8
9
|
from .result import Err, Ok, Result
|
9
10
|
from .str import str_to_list
|
10
11
|
from .zip import read_text_from_zip_archive
|
@@ -30,7 +31,7 @@ class BaseConfig(BaseModel):
|
|
30
31
|
return v
|
31
32
|
|
32
33
|
@classmethod
|
33
|
-
def read_config(cls, config_path: io.TextIOWrapper | str | Path, zip_password: str = "") -> Result[
|
34
|
+
def read_config[T](cls: type[T], config_path: io.TextIOWrapper | str | Path, zip_password: str = "") -> Result[T]: # nosec
|
34
35
|
try:
|
35
36
|
# is it zip archive?
|
36
37
|
if isinstance(config_path, str) and config_path.endswith(".zip"):
|
@@ -51,6 +52,23 @@ class BaseConfig(BaseModel):
|
|
51
52
|
|
52
53
|
return Ok(cls(**yaml.full_load(config_path)))
|
53
54
|
except ValidationError as err:
|
54
|
-
return Err("
|
55
|
+
return Err("validator_error", data={"errors": err.errors()})
|
55
56
|
except Exception as err:
|
56
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)
|
@@ -1,7 +1,7 @@
|
|
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
|
@@ -18,6 +18,6 @@ mm_std/result.py,sha256=w2Y1dji0LozcJpPMnFkqN0UbxJUm1C8Kc5ZB1vLXx20,7443
|
|
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.12.dist-info/METADATA,sha256=XX3oZLg7Z156pVNb0E9_Rw9jthMj1-SEC3ZPM8fUKxU,307
|
22
|
+
mm_std-0.1.12.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
23
|
+
mm_std-0.1.12.dist-info/RECORD,,
|
File without changes
|