potato-util 0.2.0__py3-none-any.whl → 0.2.1__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.
- potato_util/__version__.py +1 -1
- potato_util/constants/_enum.py +8 -0
- potato_util/io/_async.py +62 -1
- potato_util/io/_sync.py +61 -2
- {potato_util-0.2.0.dist-info → potato_util-0.2.1.dist-info}/METADATA +3 -3
- {potato_util-0.2.0.dist-info → potato_util-0.2.1.dist-info}/RECORD +9 -9
- {potato_util-0.2.0.dist-info → potato_util-0.2.1.dist-info}/WHEEL +1 -1
- {potato_util-0.2.0.dist-info → potato_util-0.2.1.dist-info}/licenses/LICENSE.txt +0 -0
- {potato_util-0.2.0.dist-info → potato_util-0.2.1.dist-info}/top_level.txt +0 -0
potato_util/__version__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.2.
|
|
1
|
+
__version__ = "0.2.1"
|
potato_util/constants/_enum.py
CHANGED
|
@@ -24,8 +24,16 @@ class HashAlgoEnum(str, Enum):
|
|
|
24
24
|
sha512 = "sha512"
|
|
25
25
|
|
|
26
26
|
|
|
27
|
+
class ConfigFileFormatEnum(str, Enum):
|
|
28
|
+
YAML = "YAML"
|
|
29
|
+
JSON = "JSON"
|
|
30
|
+
TOML = "TOML"
|
|
31
|
+
INI = "INI"
|
|
32
|
+
|
|
33
|
+
|
|
27
34
|
__all__ = [
|
|
28
35
|
"WarnEnum",
|
|
29
36
|
"TSUnitEnum",
|
|
30
37
|
"HashAlgoEnum",
|
|
38
|
+
"ConfigFileFormatEnum",
|
|
31
39
|
]
|
potato_util/io/_async.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import os
|
|
1
2
|
import sys
|
|
2
3
|
import json
|
|
4
|
+
import glob
|
|
3
5
|
import errno
|
|
4
6
|
import hashlib
|
|
5
7
|
import logging
|
|
@@ -20,7 +22,8 @@ import aioshutil
|
|
|
20
22
|
import aiofiles.os
|
|
21
23
|
from pydantic import validate_call
|
|
22
24
|
|
|
23
|
-
from ..
|
|
25
|
+
from .._base import deep_merge
|
|
26
|
+
from ..constants import WarnEnum, HashAlgoEnum, ConfigFileFormatEnum, MAX_PATH_LENGTH
|
|
24
27
|
|
|
25
28
|
|
|
26
29
|
logger = logging.getLogger(__name__)
|
|
@@ -479,6 +482,63 @@ async def async_read_config_file(config_path: str | Path) -> dict[str, Any]:
|
|
|
479
482
|
return _config
|
|
480
483
|
|
|
481
484
|
|
|
485
|
+
@validate_call
|
|
486
|
+
async def async_read_all_configs(
|
|
487
|
+
configs_dir: str | Path | list[str | Path],
|
|
488
|
+
allowed_formats: list[ConfigFileFormatEnum] = [
|
|
489
|
+
ConfigFileFormatEnum.YAML,
|
|
490
|
+
ConfigFileFormatEnum.JSON,
|
|
491
|
+
ConfigFileFormatEnum.TOML,
|
|
492
|
+
],
|
|
493
|
+
) -> dict[str, Any]:
|
|
494
|
+
"""Asynchronous read all config files from directory or directories and merge them.
|
|
495
|
+
|
|
496
|
+
Args:
|
|
497
|
+
configs_dir (str | Path | list[str | Path], required): Configs directory or directories.
|
|
498
|
+
allowed_formats (list[ConfigFileFormatEnum] , optional): Allowed config file formats to read.
|
|
499
|
+
Defaults to [YAML, JSON, TOML].
|
|
500
|
+
|
|
501
|
+
Returns:
|
|
502
|
+
dict[str, Any]: Dictionary containing all merged config data from all files.
|
|
503
|
+
"""
|
|
504
|
+
|
|
505
|
+
_config_dict: dict[str, Any] = {}
|
|
506
|
+
|
|
507
|
+
if not isinstance(configs_dir, list):
|
|
508
|
+
configs_dir = [configs_dir]
|
|
509
|
+
|
|
510
|
+
_file_paths: list[str] = []
|
|
511
|
+
for _config_dir in configs_dir:
|
|
512
|
+
if isinstance(_config_dir, str):
|
|
513
|
+
_config_dir = Path(_config_dir)
|
|
514
|
+
|
|
515
|
+
if not os.path.isabs(_config_dir):
|
|
516
|
+
_current_dir = await aiofiles.os.getcwd()
|
|
517
|
+
_config_dir = os.path.join(_current_dir, _config_dir)
|
|
518
|
+
|
|
519
|
+
if await aiofiles.os.path.isdir(_config_dir):
|
|
520
|
+
if ConfigFileFormatEnum.YAML in allowed_formats:
|
|
521
|
+
_file_paths.extend(glob.glob(os.path.join(_config_dir, "*.yaml")))
|
|
522
|
+
_file_paths.extend(glob.glob(os.path.join(_config_dir, "*.yml")))
|
|
523
|
+
|
|
524
|
+
if ConfigFileFormatEnum.JSON in allowed_formats:
|
|
525
|
+
_file_paths.extend(glob.glob(os.path.join(_config_dir, "*.json")))
|
|
526
|
+
|
|
527
|
+
if ConfigFileFormatEnum.TOML in allowed_formats:
|
|
528
|
+
_file_paths.extend(glob.glob(os.path.join(_config_dir, "*.toml")))
|
|
529
|
+
|
|
530
|
+
if ConfigFileFormatEnum.INI in allowed_formats:
|
|
531
|
+
_file_paths.extend(glob.glob(os.path.join(_config_dir, "*.ini")))
|
|
532
|
+
_file_paths.extend(glob.glob(os.path.join(_config_dir, "*.cfg")))
|
|
533
|
+
|
|
534
|
+
_file_paths.sort()
|
|
535
|
+
for _file_path in _file_paths:
|
|
536
|
+
_config_data = await async_read_config_file(config_path=_file_path)
|
|
537
|
+
_config_dict = deep_merge(_config_dict, _config_data)
|
|
538
|
+
|
|
539
|
+
return _config_dict
|
|
540
|
+
|
|
541
|
+
|
|
482
542
|
__all__ = [
|
|
483
543
|
"async_create_dir",
|
|
484
544
|
"async_remove_dir",
|
|
@@ -491,4 +551,5 @@ __all__ = [
|
|
|
491
551
|
"async_read_toml_file",
|
|
492
552
|
"async_read_ini_file",
|
|
493
553
|
"async_read_config_file",
|
|
554
|
+
"async_read_all_configs",
|
|
494
555
|
]
|
potato_util/io/_sync.py
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import os
|
|
4
4
|
import sys
|
|
5
5
|
import json
|
|
6
|
+
import glob
|
|
6
7
|
import errno
|
|
7
8
|
import shutil
|
|
8
9
|
import hashlib
|
|
@@ -22,8 +23,8 @@ else:
|
|
|
22
23
|
import yaml
|
|
23
24
|
from pydantic import validate_call
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
from ..constants import WarnEnum, HashAlgoEnum, MAX_PATH_LENGTH
|
|
26
|
+
from .._base import deep_merge
|
|
27
|
+
from ..constants import WarnEnum, HashAlgoEnum, ConfigFileFormatEnum, MAX_PATH_LENGTH
|
|
27
28
|
|
|
28
29
|
|
|
29
30
|
logger = logging.getLogger(__name__)
|
|
@@ -466,6 +467,63 @@ def read_config_file(config_path: str | Path) -> dict[str, Any]:
|
|
|
466
467
|
return _config
|
|
467
468
|
|
|
468
469
|
|
|
470
|
+
@validate_call
|
|
471
|
+
def read_all_configs(
|
|
472
|
+
configs_dir: str | Path | list[str | Path],
|
|
473
|
+
allowed_formats: list[ConfigFileFormatEnum] = [
|
|
474
|
+
ConfigFileFormatEnum.YAML,
|
|
475
|
+
ConfigFileFormatEnum.JSON,
|
|
476
|
+
ConfigFileFormatEnum.TOML,
|
|
477
|
+
],
|
|
478
|
+
) -> dict[str, Any]:
|
|
479
|
+
"""Read all config files from directory or directories and merge them.
|
|
480
|
+
|
|
481
|
+
Args:
|
|
482
|
+
configs_dir (str | Path | list[str | Path], required): Configs directory or directories.
|
|
483
|
+
allowed_formats (list[ConfigFileFormatEnum] , optional): Allowed config file formats to read.
|
|
484
|
+
Defaults to [YAML, JSON, TOML].
|
|
485
|
+
|
|
486
|
+
Returns:
|
|
487
|
+
dict[str, Any]: Dictionary containing all merged config data from all files.
|
|
488
|
+
"""
|
|
489
|
+
|
|
490
|
+
_config_dict: dict[str, Any] = {}
|
|
491
|
+
|
|
492
|
+
if not isinstance(configs_dir, list):
|
|
493
|
+
configs_dir = [configs_dir]
|
|
494
|
+
|
|
495
|
+
_file_paths: list[str] = []
|
|
496
|
+
for _config_dir in configs_dir:
|
|
497
|
+
if isinstance(_config_dir, str):
|
|
498
|
+
_config_dir = Path(_config_dir)
|
|
499
|
+
|
|
500
|
+
if not os.path.isabs(_config_dir):
|
|
501
|
+
_current_dir = os.getcwd()
|
|
502
|
+
_config_dir = os.path.join(_current_dir, _config_dir)
|
|
503
|
+
|
|
504
|
+
if os.path.isdir(_config_dir):
|
|
505
|
+
if ConfigFileFormatEnum.YAML in allowed_formats:
|
|
506
|
+
_file_paths.extend(glob.glob(os.path.join(_config_dir, "*.yaml")))
|
|
507
|
+
_file_paths.extend(glob.glob(os.path.join(_config_dir, "*.yml")))
|
|
508
|
+
|
|
509
|
+
if ConfigFileFormatEnum.JSON in allowed_formats:
|
|
510
|
+
_file_paths.extend(glob.glob(os.path.join(_config_dir, "*.json")))
|
|
511
|
+
|
|
512
|
+
if ConfigFileFormatEnum.TOML in allowed_formats:
|
|
513
|
+
_file_paths.extend(glob.glob(os.path.join(_config_dir, "*.toml")))
|
|
514
|
+
|
|
515
|
+
if ConfigFileFormatEnum.INI in allowed_formats:
|
|
516
|
+
_file_paths.extend(glob.glob(os.path.join(_config_dir, "*.ini")))
|
|
517
|
+
_file_paths.extend(glob.glob(os.path.join(_config_dir, "*.cfg")))
|
|
518
|
+
|
|
519
|
+
_file_paths.sort()
|
|
520
|
+
for _file_path in _file_paths:
|
|
521
|
+
_config_data = read_config_file(config_path=_file_path)
|
|
522
|
+
_config_dict = deep_merge(_config_dict, _config_data)
|
|
523
|
+
|
|
524
|
+
return _config_dict
|
|
525
|
+
|
|
526
|
+
|
|
469
527
|
__all__ = [
|
|
470
528
|
"create_dir",
|
|
471
529
|
"remove_dir",
|
|
@@ -478,4 +536,5 @@ __all__ = [
|
|
|
478
536
|
"read_toml_file",
|
|
479
537
|
"read_ini_file",
|
|
480
538
|
"read_config_file",
|
|
539
|
+
"read_all_configs",
|
|
481
540
|
]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: potato_util
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: 'potato_util' is collection of simple useful utils package for python.
|
|
5
5
|
Author-email: Batkhuu Byambajav <batkhuu10@gmail.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/bybatkhuu/module-python-utils
|
|
@@ -55,7 +55,7 @@ Provides-Extra: docs
|
|
|
55
55
|
Requires-Dist: pylint<5.0.0,>=3.0.4; extra == "docs"
|
|
56
56
|
Requires-Dist: mkdocs-material<10.0.0,>=9.5.50; extra == "docs"
|
|
57
57
|
Requires-Dist: mkdocs-awesome-nav<4.0.0,>=3.0.0; extra == "docs"
|
|
58
|
-
Requires-Dist: mkdocstrings[python]<
|
|
58
|
+
Requires-Dist: mkdocstrings[python]<2.0.0,>=0.24.3; extra == "docs"
|
|
59
59
|
Requires-Dist: mike<3.0.0,>=2.1.3; extra == "docs"
|
|
60
60
|
Provides-Extra: dev
|
|
61
61
|
Requires-Dist: aiofiles<26.0.0,>=24.1.0; extra == "dev"
|
|
@@ -73,7 +73,7 @@ Requires-Dist: twine<7.0.0,>=6.0.1; extra == "dev"
|
|
|
73
73
|
Requires-Dist: pylint<5.0.0,>=3.0.4; extra == "dev"
|
|
74
74
|
Requires-Dist: mkdocs-material<10.0.0,>=9.5.50; extra == "dev"
|
|
75
75
|
Requires-Dist: mkdocs-awesome-nav<4.0.0,>=3.0.0; extra == "dev"
|
|
76
|
-
Requires-Dist: mkdocstrings[python]<
|
|
76
|
+
Requires-Dist: mkdocstrings[python]<2.0.0,>=0.24.3; extra == "dev"
|
|
77
77
|
Requires-Dist: mike<3.0.0,>=2.1.3; extra == "dev"
|
|
78
78
|
Requires-Dist: pyright<2.0.0,>=1.1.392; extra == "dev"
|
|
79
79
|
Requires-Dist: pre-commit<5.0.0,>=4.0.1; extra == "dev"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
potato_util/__init__.py,sha256=xl4th2Z_OmTk-3aO1w05Vh8ob0BnX4RcY1fT9tGX61c,74
|
|
2
|
-
potato_util/__version__.py,sha256=
|
|
2
|
+
potato_util/__version__.py,sha256=HfjVOrpTnmZ-xVFCYSVmX50EXaBQeJteUHG-PD6iQs8,22
|
|
3
3
|
potato_util/_base.py,sha256=oKLzp_NheI7kQAKC5xAm77OI_UmBXRuEEpulZTVBg5w,2549
|
|
4
4
|
potato_util/dt.py,sha256=DatLzuXOxdanplBv-Kf3qOaomrTCUUBSYv_QgTtQB6U,7635
|
|
5
5
|
potato_util/generator.py,sha256=vdvHj1UrCOQI2WXQHQ2H63PMLQ6yOXAZPNl0m-6BgtY,1572
|
|
@@ -8,7 +8,7 @@ potato_util/secure.py,sha256=HxlUGyJl15qiL5WFrTZOJLgBZzuEr3Eu--qvBPmj2So,848
|
|
|
8
8
|
potato_util/validator.py,sha256=TANw7uWHi0PANPkrNDOFFvRcYL9Ge75b4xGSf3PTW1A,4083
|
|
9
9
|
potato_util/constants/__init__.py,sha256=lhxZ2k-QotMR_w9w-Gv-9pCEFrQSKxe1YEIvV83pf8E,80
|
|
10
10
|
potato_util/constants/_base.py,sha256=J1i611erzcrPRZ6USkVgnNZ_IvvN9YLbcltvyIngpcg,61
|
|
11
|
-
potato_util/constants/_enum.py,sha256=
|
|
11
|
+
potato_util/constants/_enum.py,sha256=RYg5MBxeRe2-oZ9CsqvFhDRIvB3Wi4tm-Wa4MLLfVy4,654
|
|
12
12
|
potato_util/constants/_regex.py,sha256=T7SSsqD0y8jXJJPURwAK2uA59AjLt1uqGfqqUd1a22o,710
|
|
13
13
|
potato_util/http/__init__.py,sha256=qWOzScMVJEHjzClEqOYmGtfkZyU8f8Hz8nT054Dbblo,229
|
|
14
14
|
potato_util/http/_async.py,sha256=dfs-ynchPKdnMNQXqyoqhcz-jhtQ7g_4JnNfVr3bXk0,1178
|
|
@@ -16,10 +16,10 @@ potato_util/http/_base.py,sha256=qoW5U8gxihVMx3v1gSLLmptMjScVsDS9PowvJ6tTc9c,143
|
|
|
16
16
|
potato_util/http/_sync.py,sha256=i8oyRmh-WraOzotaUbssIjOPvBh1pvLPupdoCvyHTK0,1169
|
|
17
17
|
potato_util/http/fastapi.py,sha256=iqCxZcQDIVtcqCN9dZ4itcoUs6KzsfRGgK7sRd5EmOA,675
|
|
18
18
|
potato_util/io/__init__.py,sha256=FoGcN7t0uArQV4hbMR1X5aeC8Yq-h_ds4xooNpkmgG0,209
|
|
19
|
-
potato_util/io/_async.py,sha256=
|
|
20
|
-
potato_util/io/_sync.py,sha256=
|
|
21
|
-
potato_util-0.2.
|
|
22
|
-
potato_util-0.2.
|
|
23
|
-
potato_util-0.2.
|
|
24
|
-
potato_util-0.2.
|
|
25
|
-
potato_util-0.2.
|
|
19
|
+
potato_util/io/_async.py,sha256=mFkLrqXreCRJcvWEysS2Tvmb0XEDQeAqnnt1b1NbYh0,18209
|
|
20
|
+
potato_util/io/_sync.py,sha256=Zdvh-2_XeLriI4XKkgsRn9TvI8I3KjQItmIF6w4aNyk,17098
|
|
21
|
+
potato_util-0.2.1.dist-info/licenses/LICENSE.txt,sha256=CUTK-r0BWIg1r0bBiemAcMhakgV0N7HuRhw6rQ-A9A4,1074
|
|
22
|
+
potato_util-0.2.1.dist-info/METADATA,sha256=dPFt_2g3qw7T5cegDm8ZePnoaaM0OT6cHHLAS0Fzzrk,15725
|
|
23
|
+
potato_util-0.2.1.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
24
|
+
potato_util-0.2.1.dist-info/top_level.txt,sha256=pLMnSfT6rhlYBpo2Gnd8kKMDxcuvxdVizqsv1dd1frw,12
|
|
25
|
+
potato_util-0.2.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|