sdsstools 1.9.3__py3-none-any.whl → 1.9.5__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.
- sdsstools/configuration.py +15 -15
- sdsstools/daemonizer.py +14 -2
- {sdsstools-1.9.3.dist-info → sdsstools-1.9.5.dist-info}/METADATA +1 -1
- {sdsstools-1.9.3.dist-info → sdsstools-1.9.5.dist-info}/RECORD +7 -7
- {sdsstools-1.9.3.dist-info → sdsstools-1.9.5.dist-info}/WHEEL +0 -0
- {sdsstools-1.9.3.dist-info → sdsstools-1.9.5.dist-info}/entry_points.txt +0 -0
- {sdsstools-1.9.3.dist-info → sdsstools-1.9.5.dist-info}/licenses/LICENSE.md +0 -0
sdsstools/configuration.py
CHANGED
|
@@ -15,7 +15,7 @@ import pathlib
|
|
|
15
15
|
import re
|
|
16
16
|
from copy import deepcopy
|
|
17
17
|
|
|
18
|
-
from typing import Any, Dict, Optional, Type,
|
|
18
|
+
from typing import Any, Dict, Optional, Type, Union
|
|
19
19
|
|
|
20
20
|
import yaml
|
|
21
21
|
from typing_extensions import Self
|
|
@@ -385,16 +385,13 @@ class Configuration(RecursiveDict):
|
|
|
385
385
|
return self
|
|
386
386
|
|
|
387
387
|
|
|
388
|
-
ReturnClass = TypeVar("ReturnClass", bound=dict)
|
|
389
|
-
|
|
390
|
-
|
|
391
388
|
def read_yaml_file(
|
|
392
389
|
path: AnyPath,
|
|
393
390
|
use_extends: bool = True,
|
|
394
391
|
loader: Any = yaml.FullLoader,
|
|
395
|
-
return_class: Type
|
|
392
|
+
return_class: Type | None = None,
|
|
396
393
|
use_variables: bool = True,
|
|
397
|
-
)
|
|
394
|
+
):
|
|
398
395
|
"""Reads a YAML file and returns a dictionary.
|
|
399
396
|
|
|
400
397
|
Parameters
|
|
@@ -403,11 +400,12 @@ def read_yaml_file(
|
|
|
403
400
|
The path to the YAML file or a file-like object.
|
|
404
401
|
use_extends
|
|
405
402
|
If :obj:`True`, looks for lines starting with ``#!extends <basefile>`` and
|
|
406
|
-
merges the current file with the base file.
|
|
403
|
+
merges the current file with the base file. This requires both the current and
|
|
404
|
+
base files to be formatted as dictionaries.
|
|
407
405
|
loader
|
|
408
406
|
The YAML loader to use.
|
|
409
407
|
return_class
|
|
410
|
-
|
|
408
|
+
Casts the read YAML data to ``return_class`` if possible.
|
|
411
409
|
use_variables
|
|
412
410
|
If :obj:`True`, looks for a ``variables`` section in the YAML file and
|
|
413
411
|
replaces occurrences of ``$(VARNAME)`` with the value of that variable.
|
|
@@ -427,7 +425,12 @@ def read_yaml_file(
|
|
|
427
425
|
fp.seek(0)
|
|
428
426
|
yaml_data: Union[ConfigType, None] = yaml.load(fp, Loader=loader)
|
|
429
427
|
|
|
430
|
-
if yaml_data is
|
|
428
|
+
if yaml_data is None or yaml_data == {}:
|
|
429
|
+
return (
|
|
430
|
+
return_class({}) if return_class and issubclass(return_class, dict) else {}
|
|
431
|
+
)
|
|
432
|
+
|
|
433
|
+
if use_variables and isinstance(yaml_data, dict):
|
|
431
434
|
variables = yaml_data.get("variables", {})
|
|
432
435
|
|
|
433
436
|
fp.seek(0)
|
|
@@ -437,10 +440,7 @@ def read_yaml_file(
|
|
|
437
440
|
file_content = re.sub(rf"\$\(\s*{var}\s*\)", str(value), file_content)
|
|
438
441
|
yaml_data = yaml.load(file_content, Loader=loader)
|
|
439
442
|
|
|
440
|
-
if
|
|
441
|
-
return return_class({})
|
|
442
|
-
|
|
443
|
-
if use_extends:
|
|
443
|
+
if use_extends and isinstance(yaml_data, dict):
|
|
444
444
|
fp.seek(0)
|
|
445
445
|
for line in fp.readlines():
|
|
446
446
|
if line.strip().startswith("#!extends"):
|
|
@@ -452,9 +452,9 @@ def read_yaml_file(
|
|
|
452
452
|
|
|
453
453
|
base = read_yaml_file(base_file, use_extends=False, return_class=dict)
|
|
454
454
|
new_config = merge_config(base, yaml_data)
|
|
455
|
-
return return_class(new_config)
|
|
455
|
+
return return_class(new_config) if return_class else new_config
|
|
456
456
|
|
|
457
457
|
elif line.strip().startswith("#") or line.strip() == "":
|
|
458
458
|
continue
|
|
459
459
|
|
|
460
|
-
return return_class(yaml_data)
|
|
460
|
+
return return_class(yaml_data) if return_class else yaml_data
|
sdsstools/daemonizer.py
CHANGED
|
@@ -23,7 +23,19 @@ from click.decorators import pass_context
|
|
|
23
23
|
from daemonocle import Daemon
|
|
24
24
|
|
|
25
25
|
|
|
26
|
-
__all__ = ["cli_coro", "DaemonGroup"]
|
|
26
|
+
__all__ = ["cli_coro", "DaemonGroup", "get_event_loop", "daemonize"]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def get_event_loop() -> asyncio.AbstractEventLoop:
|
|
30
|
+
"""Gets the current event loop, or creates a new one if none exists."""
|
|
31
|
+
|
|
32
|
+
try:
|
|
33
|
+
return asyncio.get_event_loop()
|
|
34
|
+
except RuntimeError:
|
|
35
|
+
# "There is no current event loop in thread %r"
|
|
36
|
+
loop = asyncio.new_event_loop()
|
|
37
|
+
asyncio.set_event_loop(loop)
|
|
38
|
+
return loop
|
|
27
39
|
|
|
28
40
|
|
|
29
41
|
def cli_coro(
|
|
@@ -35,7 +47,7 @@ def cli_coro(
|
|
|
35
47
|
def decorator_cli_coro(f):
|
|
36
48
|
@wraps(f)
|
|
37
49
|
def wrapper(*args, **kwargs):
|
|
38
|
-
loop =
|
|
50
|
+
loop = get_event_loop()
|
|
39
51
|
if shutdown_func:
|
|
40
52
|
for ss in signals:
|
|
41
53
|
loop.add_signal_handler(ss, shutdown_func, ss, loop)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
sdsstools/__init__.py,sha256=G8u94gRu4THFJvptEITykK0Q_3jHqhQY9p01j9QCQH4,744
|
|
2
2
|
sdsstools/_tasks.py,sha256=U7fvxk9IExzE6voNjio2QqRTw-H9Upu1d0zKQlQFs5I,4263
|
|
3
3
|
sdsstools/cli.py,sha256=e4BS4b1cJThCj5tytajr_VMUvmVP1xYq_r90EtEscg8,1348
|
|
4
|
-
sdsstools/configuration.py,sha256=
|
|
5
|
-
sdsstools/daemonizer.py,sha256=
|
|
4
|
+
sdsstools/configuration.py,sha256=y_nmF_TN_o68ib2YIpdypHfwggvBpjz_dwKjNd0jzc8,14673
|
|
5
|
+
sdsstools/daemonizer.py,sha256=Yd06BTwcAjQ9hIC3O-pQhqE5daHK-ECPZ17FzZPe3xM,8176
|
|
6
6
|
sdsstools/logger.py,sha256=nGAC_hDK0dWVMAS-a-vBsw0oSCxAwx-ZsJUE5GMzILs,18382
|
|
7
7
|
sdsstools/metadata.py,sha256=LZWO0KI-gVvzdJNIaVlIn4bBBHxbglU8BLW-MdlxOFA,3268
|
|
8
8
|
sdsstools/time.py,sha256=cqLrch0ZUCt3ShagN1v-5GhgLyNjzPXgaQRem4j7vAk,4606
|
|
@@ -15,8 +15,8 @@ sdsstools/_vendor/toml/decoder.py,sha256=hWUJ3UQ43MGVER35rSUUj7Hdh85Vat8Od_B4HeF
|
|
|
15
15
|
sdsstools/_vendor/toml/encoder.py,sha256=OBRwH2tRUhRI8nJgKBwKbkyQnBAuhcUf60r3wykjPco,9989
|
|
16
16
|
sdsstools/_vendor/toml/ordered.py,sha256=aW5woa5xOqR4BjIz9t10_lghxyhF54KQ7FqUNVv7WJ0,334
|
|
17
17
|
sdsstools/_vendor/toml/tz.py,sha256=8TAiXrTqU08sE0ruz2TXH_pFY2rlwNKE47MSE4rDo8Y,618
|
|
18
|
-
sdsstools-1.9.
|
|
19
|
-
sdsstools-1.9.
|
|
20
|
-
sdsstools-1.9.
|
|
21
|
-
sdsstools-1.9.
|
|
22
|
-
sdsstools-1.9.
|
|
18
|
+
sdsstools-1.9.5.dist-info/METADATA,sha256=3_LXoDmSXoduy2mJteBp4bVbh-uN8bG-I2yu-HhYGi0,15701
|
|
19
|
+
sdsstools-1.9.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
20
|
+
sdsstools-1.9.5.dist-info/entry_points.txt,sha256=H1UefQFMHyzmGcdNib_qxiOfFSx3351wr4c2ax0PJbQ,87
|
|
21
|
+
sdsstools-1.9.5.dist-info/licenses/LICENSE.md,sha256=_7dAUQQ5Ph_x1hcFXhi9aHBcqq9H11zco12eO4B3Cyg,1504
|
|
22
|
+
sdsstools-1.9.5.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|