zrb 0.15.0__py3-none-any.whl → 0.17.0__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.
- zrb/__init__.py +5 -0
- zrb/__main__.py +0 -3
- zrb/action/runner.py +12 -3
- zrb/advertisement.py +4 -0
- zrb/builtin/_helper/reccuring_action.py +0 -23
- zrb/builtin/devtool/install/_input.py +2 -4
- zrb/builtin/devtool/install/helix/resource/config.toml +2 -1
- zrb/builtin/process/pid/get_by_name.py +1 -1
- zrb/builtin/project/create/template/project.sh +1 -0
- zrb/builtin/schedule.py +14 -10
- zrb/builtin/watch_changes.py +15 -14
- zrb/config/config.py +21 -14
- zrb/helper/accessories/color.py +5 -2
- zrb/helper/accessories/icon.py +4 -0
- zrb/helper/accessories/name.py +4 -0
- zrb/helper/accessories/untyped_color.py +10 -0
- zrb/helper/advertisement.py +3 -0
- zrb/helper/callable.py +9 -1
- zrb/helper/cli.py +2 -0
- zrb/helper/codemod/add_argument_to_function.py +6 -0
- zrb/helper/codemod/add_argument_to_function_call.py +6 -0
- zrb/helper/codemod/add_assert_resource.py +4 -0
- zrb/helper/codemod/add_function_call.py +4 -0
- zrb/helper/codemod/add_import_module.py +4 -0
- zrb/helper/codemod/add_key_value_to_dict.py +6 -0
- zrb/helper/codemod/add_property_to_class.py +6 -0
- zrb/helper/codemod/add_upstream_to_task.py +4 -0
- zrb/helper/codemod/append_code_to_function.py +6 -0
- zrb/helper/codemod/format_code.py +4 -0
- zrb/helper/default_env.py +2 -0
- zrb/helper/docker_compose/fetch_external_env.py +6 -0
- zrb/helper/docker_compose/file.py +4 -0
- zrb/helper/docstring.py +5 -0
- zrb/helper/env_map/fetch.py +4 -0
- zrb/helper/file/copy_tree.py +3 -0
- zrb/helper/file/match.py +4 -0
- zrb/helper/file/text.py +4 -0
- zrb/helper/git/detect_changes.py +4 -0
- zrb/helper/loader/load_module.py +2 -0
- zrb/helper/log.py +1 -1
- zrb/helper/map/conversion.py +4 -0
- zrb/helper/python_task.py +3 -0
- zrb/helper/render_data.py +4 -0
- zrb/helper/string/conversion.py +13 -36
- zrb/helper/string/jinja.py +4 -0
- zrb/helper/string/modification.py +4 -0
- zrb/helper/string/parse_replacement.py +4 -0
- zrb/helper/string/untyped_conversion.py +49 -0
- zrb/helper/task.py +4 -0
- zrb/helper/typecheck.py +6 -7
- zrb/helper/typing.py +32 -12
- zrb/helper/util.py +4 -0
- zrb/runner.py +3 -0
- zrb/task/any_task.py +5 -0
- zrb/task/any_task_event_handler.py +4 -0
- zrb/task/base_remote_cmd_task.py +4 -0
- zrb/task/base_task/base_task.py +5 -1
- zrb/task/checker.py +7 -3
- zrb/task/cmd_task.py +14 -2
- zrb/task/decorator.py +4 -0
- zrb/task/docker_compose_task.py +4 -0
- zrb/task/flow_task.py +4 -0
- zrb/task/http_checker.py +14 -1
- zrb/task/looper.py +40 -0
- zrb/task/notifier.py +4 -0
- zrb/task/parallel.py +4 -0
- zrb/task/path_checker.py +14 -1
- zrb/task/path_watcher.py +65 -41
- zrb/task/port_checker.py +14 -1
- zrb/task/recurring_task.py +5 -0
- zrb/task/remote_cmd_task.py +4 -0
- zrb/task/resource_maker.py +14 -1
- zrb/task/rsync_task.py +4 -0
- zrb/task/server.py +190 -0
- zrb/task/task.py +4 -0
- zrb/task/time_watcher.py +50 -18
- zrb/task/watcher.py +100 -0
- zrb/task/wiki_task.py +4 -0
- zrb/task_env/constant.py +5 -0
- zrb/task_env/env.py +4 -0
- zrb/task_env/env_file.py +4 -0
- zrb/task_group/group.py +4 -0
- zrb/task_input/any_input.py +4 -0
- zrb/task_input/base_input.py +4 -0
- zrb/task_input/bool_input.py +4 -0
- zrb/task_input/choice_input.py +4 -0
- zrb/task_input/constant.py +5 -0
- zrb/task_input/float_input.py +4 -0
- zrb/task_input/int_input.py +4 -0
- zrb/task_input/password_input.py +4 -0
- zrb/task_input/str_input.py +4 -0
- zrb/task_input/task_input.py +4 -0
- {zrb-0.15.0.dist-info → zrb-0.17.0.dist-info}/METADATA +1 -1
- {zrb-0.15.0.dist-info → zrb-0.17.0.dist-info}/RECORD +97 -92
- {zrb-0.15.0.dist-info → zrb-0.17.0.dist-info}/LICENSE +0 -0
- {zrb-0.15.0.dist-info → zrb-0.17.0.dist-info}/WHEEL +0 -0
- {zrb-0.15.0.dist-info → zrb-0.17.0.dist-info}/entry_points.txt +0 -0
zrb/helper/file/match.py
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
import fnmatch
|
2
2
|
import glob
|
3
3
|
|
4
|
+
from zrb.helper.accessories.color import colored
|
5
|
+
from zrb.helper.log import logger
|
4
6
|
from zrb.helper.typecheck import typechecked
|
5
7
|
from zrb.helper.typing import Iterable, List
|
6
8
|
|
9
|
+
logger.debug(colored("Loading zrb.helper.file.match", attrs=["dark"]))
|
10
|
+
|
7
11
|
|
8
12
|
@typechecked
|
9
13
|
def get_file_names(glob_path: str, glob_ignored_paths: Iterable[str]) -> List[str]:
|
zrb/helper/file/text.py
CHANGED
@@ -2,8 +2,12 @@ import os
|
|
2
2
|
|
3
3
|
import aiofiles
|
4
4
|
|
5
|
+
from zrb.helper.accessories.color import colored
|
6
|
+
from zrb.helper.log import logger
|
5
7
|
from zrb.helper.typecheck import typechecked
|
6
8
|
|
9
|
+
logger.debug(colored("Loading zrb.helper.file.text", attrs=["dark"]))
|
10
|
+
|
7
11
|
|
8
12
|
@typechecked
|
9
13
|
async def read_text_file_async(file_name: str) -> str:
|
zrb/helper/git/detect_changes.py
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
import subprocess
|
2
2
|
|
3
|
+
from zrb.helper.accessories.color import colored
|
4
|
+
from zrb.helper.log import logger
|
3
5
|
from zrb.helper.typecheck import typechecked
|
4
6
|
from zrb.helper.typing import Mapping
|
5
7
|
|
8
|
+
logger.debug(colored("Loading zrb.helper.git.detect_changes", attrs=["dark"]))
|
9
|
+
|
6
10
|
|
7
11
|
@typechecked
|
8
12
|
class ModificationState:
|
zrb/helper/loader/load_module.py
CHANGED
@@ -8,6 +8,8 @@ from zrb.helper.accessories.color import colored
|
|
8
8
|
from zrb.helper.log import logger
|
9
9
|
from zrb.helper.typecheck import typechecked
|
10
10
|
|
11
|
+
logger.debug(colored("Loading zrb.helper.loader.load_module", attrs=["dark"]))
|
12
|
+
|
11
13
|
pattern = re.compile("[^a-zA-Z0-9]")
|
12
14
|
|
13
15
|
|
zrb/helper/log.py
CHANGED
zrb/helper/map/conversion.py
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
+
from zrb.helper.accessories.color import colored
|
2
|
+
from zrb.helper.log import logger
|
1
3
|
from zrb.helper.typecheck import typechecked
|
2
4
|
from zrb.helper.typing import Any, Mapping
|
3
5
|
|
6
|
+
logger.debug(colored("Loading zrb.helper.map.conversion", attrs=["dark"]))
|
7
|
+
|
4
8
|
|
5
9
|
@typechecked
|
6
10
|
def to_str(
|
zrb/helper/python_task.py
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
import sys
|
2
2
|
|
3
3
|
from zrb.helper.accessories.color import colored
|
4
|
+
from zrb.helper.log import logger
|
4
5
|
from zrb.helper.task import show_lines as task_show_lines
|
5
6
|
from zrb.helper.typecheck import typechecked
|
6
7
|
from zrb.task.task import Task
|
7
8
|
|
9
|
+
logger.debug(colored("Loading zrb.helper.python_task", attrs=["dark"]))
|
10
|
+
|
8
11
|
_DEPRECATION_WARNING = """
|
9
12
|
DEPRECATED: zrb.helper.python_task
|
10
13
|
Use zrb.helper.task instead
|
zrb/helper/render_data.py
CHANGED
@@ -3,6 +3,8 @@ import os
|
|
3
3
|
import platform
|
4
4
|
import time
|
5
5
|
|
6
|
+
from zrb.helper.accessories.color import colored
|
7
|
+
from zrb.helper.log import logger
|
6
8
|
from zrb.helper.util import (
|
7
9
|
coalesce,
|
8
10
|
coalesce_str,
|
@@ -14,6 +16,8 @@ from zrb.helper.util import (
|
|
14
16
|
to_snake_case,
|
15
17
|
)
|
16
18
|
|
19
|
+
logger.debug(colored("Loading zrb.helper.render_data", attrs=["dark"]))
|
20
|
+
|
17
21
|
DEFAULT_RENDER_DATA = {
|
18
22
|
"datetime": datetime,
|
19
23
|
"os": os,
|
zrb/helper/string/conversion.py
CHANGED
@@ -1,54 +1,31 @@
|
|
1
|
-
import
|
2
|
-
import
|
3
|
-
import
|
4
|
-
|
5
|
-
|
1
|
+
from zrb.helper.accessories.color import colored
|
2
|
+
from zrb.helper.log import logger
|
3
|
+
from zrb.helper.string.untyped_conversion import (
|
4
|
+
untyped_to_boolean,
|
5
|
+
untyped_to_cli_name,
|
6
|
+
untyped_to_logging_level,
|
7
|
+
untyped_to_variable_name,
|
8
|
+
)
|
6
9
|
from zrb.helper.typecheck import typechecked
|
7
10
|
|
8
|
-
|
9
|
-
LEADING_NUM = re.compile(r"^\d+")
|
10
|
-
LOGGING_LEVEL_MAP = {
|
11
|
-
"critical": logging.CRITICAL,
|
12
|
-
"fatal": logging.FATAL,
|
13
|
-
"error": logging.ERROR,
|
14
|
-
"warning": logging.WARNING,
|
15
|
-
"warn": logging.WARN,
|
16
|
-
"info": logging.INFO,
|
17
|
-
"debug": logging.DEBUG,
|
18
|
-
"notset": logging.NOTSET,
|
19
|
-
}
|
11
|
+
logger.debug(colored("Loading zrb.helper.string.conversion", attrs=["dark"]))
|
20
12
|
|
21
13
|
|
22
14
|
@typechecked
|
23
15
|
def to_cli_name(name: str) -> str:
|
24
|
-
return
|
16
|
+
return untyped_to_cli_name((name))
|
25
17
|
|
26
18
|
|
27
19
|
@typechecked
|
28
20
|
def to_variable_name(string: str) -> str:
|
29
|
-
|
30
|
-
string = NON_WORD.sub("_", string).strip()
|
31
|
-
# Remove leading digits
|
32
|
-
string = LEADING_NUM.sub("", string)
|
33
|
-
# Convert to lowercase
|
34
|
-
string = string.lower()
|
35
|
-
if keyword.iskeyword(string):
|
36
|
-
return string + "_"
|
37
|
-
return string
|
21
|
+
return untyped_to_variable_name(string)
|
38
22
|
|
39
23
|
|
40
24
|
@typechecked
|
41
25
|
def to_boolean(string: str) -> bool:
|
42
|
-
|
43
|
-
return True
|
44
|
-
if string.lower() in FALSE_STRS:
|
45
|
-
return False
|
46
|
-
raise Exception(f'Cannot infer boolean value from "{string}"')
|
26
|
+
return untyped_to_boolean(string)
|
47
27
|
|
48
28
|
|
49
29
|
@typechecked
|
50
30
|
def to_logging_level(logging_level_str: str) -> int:
|
51
|
-
|
52
|
-
if lower_logging_level_str in LOGGING_LEVEL_MAP:
|
53
|
-
return LOGGING_LEVEL_MAP[lower_logging_level_str]
|
54
|
-
return logging.WARNING
|
31
|
+
return untyped_to_logging_level(logging_level_str)
|
zrb/helper/string/jinja.py
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
+
from zrb.helper.accessories.color import colored
|
2
|
+
from zrb.helper.log import logger
|
1
3
|
from zrb.helper.typecheck import typechecked
|
2
4
|
from zrb.helper.typing import Any
|
3
5
|
|
6
|
+
logger.debug(colored("Loading zrb.helper.string.jinja", attrs=["dark"]))
|
7
|
+
|
4
8
|
|
5
9
|
@typechecked
|
6
10
|
def is_probably_jinja(value: Any) -> bool:
|
@@ -1,5 +1,9 @@
|
|
1
|
+
from zrb.helper.accessories.color import colored
|
2
|
+
from zrb.helper.log import logger
|
1
3
|
from zrb.helper.typecheck import typechecked
|
2
4
|
|
5
|
+
logger.debug(colored("Loading zrb.helper.string.modification", attrs=["dark"]))
|
6
|
+
|
3
7
|
|
4
8
|
@typechecked
|
5
9
|
def double_quote(text: str) -> str:
|
@@ -1,6 +1,10 @@
|
|
1
|
+
from zrb.helper.accessories.color import colored
|
2
|
+
from zrb.helper.log import logger
|
1
3
|
from zrb.helper.typecheck import typechecked
|
2
4
|
from zrb.helper.typing import Mapping
|
3
5
|
|
6
|
+
logger.debug(colored("Loading zrb.helper.string.parse_replacment", attrs=["dark"]))
|
7
|
+
|
4
8
|
|
5
9
|
@typechecked
|
6
10
|
def parse_replacement(text: str, replacement: Mapping[str, str]):
|
@@ -0,0 +1,49 @@
|
|
1
|
+
import keyword
|
2
|
+
import logging
|
3
|
+
import re
|
4
|
+
|
5
|
+
from zrb.helper.string.constant import FALSE_STRS, TRUE_STRS
|
6
|
+
|
7
|
+
NON_WORD = re.compile(r"[\W]+")
|
8
|
+
LEADING_NUM = re.compile(r"^\d+")
|
9
|
+
LOGGING_LEVEL_MAP = {
|
10
|
+
"critical": logging.CRITICAL,
|
11
|
+
"fatal": logging.FATAL,
|
12
|
+
"error": logging.ERROR,
|
13
|
+
"warning": logging.WARNING,
|
14
|
+
"warn": logging.WARN,
|
15
|
+
"info": logging.INFO,
|
16
|
+
"debug": logging.DEBUG,
|
17
|
+
"notset": logging.NOTSET,
|
18
|
+
}
|
19
|
+
|
20
|
+
|
21
|
+
def untyped_to_cli_name(name: str) -> str:
|
22
|
+
return NON_WORD.sub("-", name).strip("-").lower()
|
23
|
+
|
24
|
+
|
25
|
+
def untyped_to_variable_name(string: str) -> str:
|
26
|
+
# Replace any non-word characters with underscore
|
27
|
+
string = NON_WORD.sub("_", string).strip()
|
28
|
+
# Remove leading digits
|
29
|
+
string = LEADING_NUM.sub("", string)
|
30
|
+
# Convert to lowercase
|
31
|
+
string = string.lower()
|
32
|
+
if keyword.iskeyword(string):
|
33
|
+
return string + "_"
|
34
|
+
return string
|
35
|
+
|
36
|
+
|
37
|
+
def untyped_to_boolean(string: str) -> bool:
|
38
|
+
if string.lower() in TRUE_STRS:
|
39
|
+
return True
|
40
|
+
if string.lower() in FALSE_STRS:
|
41
|
+
return False
|
42
|
+
raise Exception(f'Cannot infer boolean value from "{string}"')
|
43
|
+
|
44
|
+
|
45
|
+
def untyped_to_logging_level(logging_level_str: str) -> int:
|
46
|
+
lower_logging_level_str = logging_level_str.lower()
|
47
|
+
if lower_logging_level_str in LOGGING_LEVEL_MAP:
|
48
|
+
return LOGGING_LEVEL_MAP[lower_logging_level_str]
|
49
|
+
return logging.WARNING
|
zrb/helper/task.py
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
+
from zrb.helper.accessories.color import colored
|
2
|
+
from zrb.helper.log import logger
|
1
3
|
from zrb.helper.typecheck import typechecked
|
2
4
|
from zrb.task.task import Task
|
3
5
|
|
6
|
+
logger.debug(colored("Loading zrb.helper.task", attrs=["dark"]))
|
7
|
+
|
4
8
|
|
5
9
|
@typechecked
|
6
10
|
def show_lines(task: Task, *lines: str):
|
zrb/helper/typecheck.py
CHANGED
@@ -1,17 +1,16 @@
|
|
1
|
-
import os
|
2
1
|
from typing import TypeVar
|
3
2
|
|
4
|
-
from
|
5
|
-
|
6
|
-
from zrb.helper.
|
7
|
-
|
8
|
-
enable_type_checking_str = os.getenv("ZRB_ENABLE_TYPE_CHECKING", "1").lower()
|
9
|
-
enable_type_checking = enable_type_checking_str not in FALSE_STRS
|
3
|
+
from zrb.config.config import enable_type_checking
|
4
|
+
from zrb.helper.accessories.untyped_color import untyped_colored as colored
|
5
|
+
from zrb.helper.log import logger
|
10
6
|
|
7
|
+
logger.debug(colored("Loading zrb.helper.typecheck", attrs=["dark"]))
|
11
8
|
T = TypeVar("T")
|
12
9
|
|
13
10
|
|
14
11
|
def typechecked(anything: T) -> T:
|
15
12
|
if enable_type_checking:
|
13
|
+
from beartype import beartype
|
14
|
+
|
16
15
|
return beartype(anything)
|
17
16
|
return anything
|
zrb/helper/typing.py
CHANGED
@@ -1,15 +1,35 @@
|
|
1
|
-
from
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
1
|
+
from zrb.config.config import enable_type_checking
|
2
|
+
from zrb.helper.accessories.untyped_color import untyped_colored as colored
|
3
|
+
from zrb.helper.log import logger
|
4
|
+
|
5
|
+
logger.debug(colored("Loading zrb.helper.typing", attrs=["dark"]))
|
6
|
+
|
7
|
+
if enable_type_checking:
|
8
|
+
from beartype.typing import (
|
9
|
+
Any,
|
10
|
+
Callable,
|
11
|
+
Iterable,
|
12
|
+
List,
|
13
|
+
Mapping,
|
14
|
+
Optional,
|
15
|
+
Tuple,
|
16
|
+
Type,
|
17
|
+
TypeVar,
|
18
|
+
Union,
|
19
|
+
)
|
20
|
+
else:
|
21
|
+
from typing import (
|
22
|
+
Any,
|
23
|
+
Callable,
|
24
|
+
Iterable,
|
25
|
+
List,
|
26
|
+
Mapping,
|
27
|
+
Optional,
|
28
|
+
Tuple,
|
29
|
+
Type,
|
30
|
+
TypeVar,
|
31
|
+
Union,
|
32
|
+
)
|
13
33
|
|
14
34
|
JinjaTemplate = str
|
15
35
|
|
zrb/helper/util.py
CHANGED
@@ -2,10 +2,14 @@ import re
|
|
2
2
|
|
3
3
|
import jinja2
|
4
4
|
|
5
|
+
from zrb.helper.accessories.color import colored
|
6
|
+
from zrb.helper.log import logger
|
5
7
|
from zrb.helper.string.conversion import to_boolean as conversion_to_boolean
|
6
8
|
from zrb.helper.typecheck import typechecked
|
7
9
|
from zrb.helper.typing import Any, Optional
|
8
10
|
|
11
|
+
logger.debug(colored("Loading zrb.helper.util", attrs=["dark"]))
|
12
|
+
|
9
13
|
NON_ALPHA_NUM = re.compile(r"[^a-zA-Z0-9]+")
|
10
14
|
|
11
15
|
|
zrb/runner.py
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
from zrb.action.runner import Runner
|
2
2
|
from zrb.config.config import env_prefix
|
3
|
+
from zrb.helper.accessories.color import colored
|
4
|
+
from zrb.helper.log import logger
|
3
5
|
|
6
|
+
logger.debug(colored("Loading zrb.runner", attrs=["dark"]))
|
4
7
|
runner = Runner(env_prefix=env_prefix)
|
zrb/task/any_task.py
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
from abc import ABC, abstractmethod
|
2
2
|
|
3
|
+
from zrb.helper.accessories.color import colored
|
4
|
+
from zrb.helper.log import logger
|
3
5
|
from zrb.helper.typing import (
|
4
6
|
Any,
|
5
7
|
Callable,
|
@@ -15,6 +17,8 @@ from zrb.task_env.env import Env
|
|
15
17
|
from zrb.task_env.env_file import EnvFile
|
16
18
|
from zrb.task_input.any_input import AnyInput
|
17
19
|
|
20
|
+
logger.debug(colored("Loading zrb.task.any_task", attrs=["dark"]))
|
21
|
+
|
18
22
|
# flake8: noqa E501
|
19
23
|
TAnyTask = TypeVar("TAnyTask", bound="AnyTask")
|
20
24
|
|
@@ -304,6 +308,7 @@ class AnyTask(ABC):
|
|
304
308
|
is_async: bool = False,
|
305
309
|
show_done_info: bool = True,
|
306
310
|
should_clear_xcom: bool = False,
|
311
|
+
should_stop_looper: bool = False,
|
307
312
|
) -> Callable[..., Any]:
|
308
313
|
"""
|
309
314
|
Converts the current task into a callable function.
|
@@ -1,6 +1,10 @@
|
|
1
|
+
from zrb.helper.accessories.color import colored
|
2
|
+
from zrb.helper.log import logger
|
1
3
|
from zrb.helper.typing import Any, Callable
|
2
4
|
from zrb.task.any_task import AnyTask
|
3
5
|
|
6
|
+
logger.debug(colored("Loading zrb.task.any_task_event_handler", attrs=["dark"]))
|
7
|
+
|
4
8
|
_TaskEventHandler = Callable[[AnyTask], Any]
|
5
9
|
OnTriggered = _TaskEventHandler
|
6
10
|
OnWaiting = _TaskEventHandler
|
zrb/task/base_remote_cmd_task.py
CHANGED
@@ -2,6 +2,8 @@ import copy
|
|
2
2
|
import os
|
3
3
|
import pathlib
|
4
4
|
|
5
|
+
from zrb.helper.accessories.color import colored
|
6
|
+
from zrb.helper.log import logger
|
5
7
|
from zrb.helper.typecheck import typechecked
|
6
8
|
from zrb.helper.typing import (
|
7
9
|
Any,
|
@@ -31,6 +33,8 @@ from zrb.task_env.env_file import EnvFile
|
|
31
33
|
from zrb.task_group.group import Group
|
32
34
|
from zrb.task_input.any_input import AnyInput
|
33
35
|
|
36
|
+
logger.debug(colored("Loading zrb.task.base_remote_cmd_task", attrs=["dark"]))
|
37
|
+
|
34
38
|
TSingleBaseRemoteCmdTask = TypeVar(
|
35
39
|
"TSingleBaseRemoteCmdTask", bound="SingleBaseRemoteCmdTask"
|
36
40
|
)
|
zrb/task/base_task/base_task.py
CHANGED
@@ -26,6 +26,7 @@ from zrb.task.any_task_event_handler import (
|
|
26
26
|
from zrb.task.base_task.component.base_task_model import BaseTaskModel
|
27
27
|
from zrb.task.base_task.component.renderer import Renderer
|
28
28
|
from zrb.task.base_task.component.trackers import AttemptTracker, FinishTracker
|
29
|
+
from zrb.task.looper import looper
|
29
30
|
from zrb.task.parallel import AnyParallel
|
30
31
|
from zrb.task_env.env import Env, PrivateEnv
|
31
32
|
from zrb.task_env.env_file import EnvFile
|
@@ -140,7 +141,7 @@ class BaseTask(FinishTracker, AttemptTracker, Renderer, BaseTaskModel, AnyTask):
|
|
140
141
|
xcom_dir = self.__get_xcom_dir()
|
141
142
|
xcom_file = os.path.join(xcom_dir, key)
|
142
143
|
with open(xcom_file, "w") as f:
|
143
|
-
f.write(value)
|
144
|
+
f.write(f"{value}")
|
144
145
|
|
145
146
|
def get_xcom(self, key: str) -> str:
|
146
147
|
self.__ensure_xcom_dir_exists()
|
@@ -164,6 +165,7 @@ class BaseTask(FinishTracker, AttemptTracker, Renderer, BaseTaskModel, AnyTask):
|
|
164
165
|
is_async: bool = False,
|
165
166
|
show_done_info: bool = True,
|
166
167
|
should_clear_xcom: bool = False,
|
168
|
+
should_stop_looper: bool = False,
|
167
169
|
) -> Callable[..., Any]:
|
168
170
|
async def function(*args: Any, **kwargs: Any) -> Any:
|
169
171
|
self.log_info("Copy task")
|
@@ -175,6 +177,8 @@ class BaseTask(FinishTracker, AttemptTracker, Renderer, BaseTaskModel, AnyTask):
|
|
175
177
|
kwargs=kwargs,
|
176
178
|
show_done_info=show_done_info,
|
177
179
|
)
|
180
|
+
if should_stop_looper:
|
181
|
+
looper.stop()
|
178
182
|
if should_clear_xcom:
|
179
183
|
self_cp.clear_xcom()
|
180
184
|
return result
|
zrb/task/checker.py
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
import asyncio
|
2
2
|
|
3
|
+
from zrb.helper.accessories.color import colored
|
4
|
+
from zrb.helper.log import logger
|
3
5
|
from zrb.helper.typecheck import typechecked
|
4
6
|
from zrb.helper.typing import Any, Callable, Iterable, Optional, Union
|
5
7
|
from zrb.task.any_task import AnyTask
|
@@ -18,6 +20,8 @@ from zrb.task_env.env_file import EnvFile
|
|
18
20
|
from zrb.task_group.group import Group
|
19
21
|
from zrb.task_input.any_input import AnyInput
|
20
22
|
|
23
|
+
logger.debug(colored("Loading zrb.task.checker", attrs=["dark"]))
|
24
|
+
|
21
25
|
|
22
26
|
@typechecked
|
23
27
|
class Checker(BaseTask):
|
@@ -79,15 +83,15 @@ class Checker(BaseTask):
|
|
79
83
|
while True:
|
80
84
|
self._should_show_progress = wait_time >= self._progress_interval
|
81
85
|
inspect_result = await self.inspect(*args, **kwargs)
|
82
|
-
if inspect_result == self._expected_result:
|
86
|
+
if inspect_result is not None and inspect_result == self._expected_result:
|
83
87
|
return True
|
84
88
|
if wait_time >= self._progress_interval:
|
85
89
|
wait_time = 0
|
86
90
|
await asyncio.sleep(self._checking_interval)
|
87
91
|
wait_time += self._checking_interval
|
88
92
|
|
89
|
-
async def inspect(self, *args: Any, **kwargs: Any) -> bool:
|
90
|
-
return
|
93
|
+
async def inspect(self, *args: Any, **kwargs: Any) -> Optional[bool]:
|
94
|
+
return None
|
91
95
|
|
92
96
|
def show_progress(self, message: str):
|
93
97
|
if self._should_show_progress:
|
zrb/task/cmd_task.py
CHANGED
@@ -8,7 +8,8 @@ import sys
|
|
8
8
|
import time
|
9
9
|
|
10
10
|
from zrb.config.config import default_shell
|
11
|
-
from zrb.helper.
|
11
|
+
from zrb.helper.accessories.color import colored
|
12
|
+
from zrb.helper.log import logger
|
12
13
|
from zrb.helper.typecheck import typechecked
|
13
14
|
from zrb.helper.typing import (
|
14
15
|
Any,
|
@@ -36,6 +37,8 @@ from zrb.task_env.env_file import EnvFile
|
|
36
37
|
from zrb.task_group.group import Group
|
37
38
|
from zrb.task_input.any_input import AnyInput
|
38
39
|
|
40
|
+
logger.debug(colored("Loading zrb.task.cmd_task", attrs=["dark"]))
|
41
|
+
|
39
42
|
_has_stty = True
|
40
43
|
try:
|
41
44
|
_original_stty = subprocess.getoutput("stty -g").rstrip()
|
@@ -196,8 +199,17 @@ class CmdTask(BaseTask):
|
|
196
199
|
raise_error: bool = True,
|
197
200
|
is_async: bool = False,
|
198
201
|
show_done_info: bool = True,
|
202
|
+
should_clear_xcom: bool = False,
|
203
|
+
should_stop_looper: bool = False,
|
199
204
|
) -> Callable[..., CmdResult]:
|
200
|
-
return super().to_function(
|
205
|
+
return super().to_function(
|
206
|
+
env_prefix=env_prefix,
|
207
|
+
raise_error=raise_error,
|
208
|
+
is_async=is_async,
|
209
|
+
show_done_info=show_done_info,
|
210
|
+
should_clear_xcom=should_clear_xcom,
|
211
|
+
should_stop_looper=should_stop_looper,
|
212
|
+
)
|
201
213
|
|
202
214
|
def print_result(self, result: CmdResult):
|
203
215
|
if not self._should_print_cmd_result or result.output == "":
|
zrb/task/decorator.py
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
from zrb.action.runner import Runner
|
2
|
+
from zrb.helper.accessories.color import colored
|
3
|
+
from zrb.helper.log import logger
|
2
4
|
from zrb.helper.typecheck import typechecked
|
3
5
|
from zrb.helper.typing import Any, Callable, Iterable, Optional, Union
|
4
6
|
from zrb.task.any_task import AnyTask
|
@@ -17,6 +19,8 @@ from zrb.task_env.env_file import EnvFile
|
|
17
19
|
from zrb.task_group.group import Group
|
18
20
|
from zrb.task_input.any_input import AnyInput
|
19
21
|
|
22
|
+
logger.debug(colored("Loading zrb.task.decorator", attrs=["dark"]))
|
23
|
+
|
20
24
|
# flake8: noqa E501
|
21
25
|
|
22
26
|
|
zrb/task/docker_compose_task.py
CHANGED
@@ -2,9 +2,11 @@ import os
|
|
2
2
|
import pathlib
|
3
3
|
|
4
4
|
from zrb.config.config import container_backend
|
5
|
+
from zrb.helper.accessories.color import colored
|
5
6
|
from zrb.helper.accessories.name import get_random_name
|
6
7
|
from zrb.helper.docker_compose.fetch_external_env import fetch_compose_file_env_map
|
7
8
|
from zrb.helper.docker_compose.file import read_compose_file, write_compose_file
|
9
|
+
from zrb.helper.log import logger
|
8
10
|
from zrb.helper.string.conversion import to_cli_name
|
9
11
|
from zrb.helper.string.modification import double_quote
|
10
12
|
from zrb.helper.typecheck import typechecked
|
@@ -37,6 +39,8 @@ from zrb.task_env.env_file import EnvFile
|
|
37
39
|
from zrb.task_group.group import Group
|
38
40
|
from zrb.task_input.any_input import AnyInput
|
39
41
|
|
42
|
+
logger.debug(colored("Loading zrb.task.docker_compose_task", attrs=["dark"]))
|
43
|
+
|
40
44
|
|
41
45
|
def _get_ensure_zrb_network_task(backend: str):
|
42
46
|
CURRENT_DIR = os.path.dirname(__file__)
|
zrb/task/flow_task.py
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
from zrb.helper.accessories.color import colored
|
2
|
+
from zrb.helper.log import logger
|
1
3
|
from zrb.helper.typecheck import typechecked
|
2
4
|
from zrb.helper.typing import Callable, Iterable, List, Optional, TypeVar, Union
|
3
5
|
from zrb.task.any_task import AnyTask
|
@@ -16,6 +18,8 @@ from zrb.task_env.env_file import EnvFile
|
|
16
18
|
from zrb.task_group.group import Group
|
17
19
|
from zrb.task_input.any_input import AnyInput
|
18
20
|
|
21
|
+
logger.debug(colored("Loading zrb.task.flow_task", attrs=["dark"]))
|
22
|
+
|
19
23
|
TFlowTask = TypeVar("TFlowTask", bound="FlowTask")
|
20
24
|
|
21
25
|
|
zrb/task/http_checker.py
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
from http.client import HTTPConnection, HTTPSConnection
|
2
2
|
|
3
|
+
from zrb.helper.accessories.color import colored
|
4
|
+
from zrb.helper.log import logger
|
3
5
|
from zrb.helper.typecheck import typechecked
|
4
6
|
from zrb.helper.typing import (
|
5
7
|
Any,
|
@@ -26,6 +28,8 @@ from zrb.task_env.env_file import EnvFile
|
|
26
28
|
from zrb.task_group.group import Group
|
27
29
|
from zrb.task_input.any_input import AnyInput
|
28
30
|
|
31
|
+
logger.debug(colored("Loading zrb.task.http_checker", attrs=["dark"]))
|
32
|
+
|
29
33
|
THTTPChecker = TypeVar("THTTPChecker", bound="HTTPChecker")
|
30
34
|
|
31
35
|
|
@@ -129,8 +133,17 @@ class HTTPChecker(Checker):
|
|
129
133
|
raise_error: bool = True,
|
130
134
|
is_async: bool = False,
|
131
135
|
show_done_info: bool = True,
|
136
|
+
should_clear_xcom: bool = False,
|
137
|
+
should_stop_looper: bool = False,
|
132
138
|
) -> Callable[..., bool]:
|
133
|
-
return super().to_function(
|
139
|
+
return super().to_function(
|
140
|
+
env_prefix=env_prefix,
|
141
|
+
raise_error=raise_error,
|
142
|
+
is_async=is_async,
|
143
|
+
show_done_info=show_done_info,
|
144
|
+
should_clear_xcom=should_clear_xcom,
|
145
|
+
should_stop_looper=should_stop_looper,
|
146
|
+
)
|
134
147
|
|
135
148
|
async def run(self, *args: Any, **kwargs: Any) -> bool:
|
136
149
|
self._config = HttpConnectionConfig(
|
zrb/task/looper.py
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
from zrb.helper.accessories.color import colored
|
2
|
+
from zrb.helper.callable import run_async
|
3
|
+
from zrb.helper.log import logger
|
4
|
+
from zrb.helper.typing import Callable, List, Mapping, Optional
|
5
|
+
|
6
|
+
logger.debug(colored("Loading zrb.task.looper", attrs=["dark"]))
|
7
|
+
|
8
|
+
|
9
|
+
class Looper:
|
10
|
+
def __init__(self):
|
11
|
+
self._queue: Mapping[str, List[Optional[bool]]] = {}
|
12
|
+
self._should_stop = False
|
13
|
+
|
14
|
+
async def pop(self, identifier: str) -> Optional[bool]:
|
15
|
+
if identifier not in self._queue or len(self._queue[identifier]) == 0:
|
16
|
+
return None
|
17
|
+
return self._queue[identifier].pop(0)
|
18
|
+
|
19
|
+
def stop(self):
|
20
|
+
self._should_stop = True
|
21
|
+
|
22
|
+
def is_registered(self, identifier: str) -> bool:
|
23
|
+
return identifier in self._queue
|
24
|
+
|
25
|
+
async def register(self, identifier: str, function: Callable[..., Optional[bool]]):
|
26
|
+
if identifier in self._queue:
|
27
|
+
return
|
28
|
+
self._queue[identifier] = []
|
29
|
+
while not self._should_stop:
|
30
|
+
try:
|
31
|
+
result = await run_async(function)
|
32
|
+
if result is not None:
|
33
|
+
if not result:
|
34
|
+
continue
|
35
|
+
self._queue[identifier].append(result)
|
36
|
+
except KeyboardInterrupt:
|
37
|
+
break
|
38
|
+
|
39
|
+
|
40
|
+
looper = Looper()
|