mm-std 0.1.11__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,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)
|
@@ -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
|