zrb 0.23.0__py3-none-any.whl → 0.24.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 +2 -0
- zrb/builtin/devtool/install/_input.py +2 -2
- zrb/builtin/project/add/app/generator/template/src/kebab-zrb-package-name/src/snake_zrb_package_name/snake_zrb_generator_name/template/_automate/snake_zrb_app_name/container/start.py +5 -6
- zrb/builtin/project/add/app/python/template/_automate/snake_zrb_app_name/container/start.py +5 -6
- zrb/builtin/project/add/fastapp/app/template/_automate/snake_zrb_app_name/container/_helper.py +1 -52
- zrb/builtin/project/add/fastapp/app/template/_automate/snake_zrb_app_name/container/microservices/start.py +5 -6
- zrb/builtin/project/add/fastapp/app/template/_automate/snake_zrb_app_name/container/monolith/start.py +5 -6
- zrb/builtin/project/add/fastapp/app/template/_automate/snake_zrb_app_name/container/support/start.py +4 -6
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/README.md +84 -8
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/loadtest/locustfile.py +1 -3
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/loadtest/template.env +1 -1
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/config.py +59 -61
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/frontend/src/routes/+layout.svelte +1 -1
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/frontend/vite.config.ts +7 -1
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/integration/app/__init__.py +0 -0
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/integration/{app.py → app/app.py} +30 -29
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/integration/{app_lifespan.py → app/app_lifespan.py} +16 -16
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/integration/{app_state.py → app/app_state.py} +2 -2
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/integration/db_connection.py +14 -2
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/integration/frontend_index.py +2 -2
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/integration/log.py +6 -6
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/integration/messagebus.py +33 -33
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/integration/rpc.py +9 -9
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/main.py +1 -3
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/module/auth/integration/access_token_scheme.py +2 -2
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/module/auth/integration/access_token_util.py +7 -7
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/module/auth/integration/model/user_model.py +6 -6
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/module/auth/integration/refresh_token_util.py +7 -7
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/module/auth/integration/user.py +18 -18
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/module/auth/migrate.py +2 -2
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/module/auth/register_module.py +9 -9
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/module/log/migrate.py +2 -2
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/module/log/register_module.py +9 -9
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/template.env +5 -2
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/test/auth/test_group_crud.py +7 -7
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/test/auth/test_permission_crud.py +7 -7
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/test/auth/test_user_crud.py +7 -7
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/test/auth/test_user_login.py +14 -14
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/test/test_liveness_and_readiness.py +3 -3
- zrb/builtin/project/add/fastapp/crud/_helper/__init__.py +7 -0
- zrb/builtin/project/add/fastapp/crud/_helper/_common.py +8 -0
- zrb/builtin/project/add/fastapp/crud/_helper/register_api.py +45 -0
- zrb/builtin/project/add/fastapp/crud/_helper/register_permission.py +40 -0
- zrb/builtin/project/add/fastapp/crud/_helper/register_rpc.py +45 -0
- zrb/builtin/project/add/fastapp/crud/crud.py +3 -12
- zrb/builtin/project/add/fastapp/crud/template/src/kebab-zrb-app-name/src/module/snake_zrb_module_name/entity/snake_zrb_entity_name/repo.py +12 -1
- zrb/builtin/project/add/fastapp/crud/template/src/kebab-zrb-app-name/src/module/snake_zrb_module_name/schema/snake_zrb_entity_name.py +1 -0
- zrb/builtin/project/add/fastapp/crud/template/src/kebab-zrb-app-name/test/snake_zrb_module_name/test_snake_zrb_entity_name.py +8 -7
- zrb/builtin/project/add/fastapp/field/_helper/__init__.py +17 -0
- zrb/builtin/project/add/fastapp/field/_helper/_common.py +102 -0
- zrb/builtin/project/add/fastapp/field/_helper/inject_delete_page.py +49 -0
- zrb/builtin/project/add/fastapp/field/_helper/inject_detail_page.py +49 -0
- zrb/builtin/project/add/fastapp/field/_helper/inject_insert_page.py +62 -0
- zrb/builtin/project/add/fastapp/field/_helper/inject_list_page.py +47 -0
- zrb/builtin/project/add/fastapp/field/_helper/inject_repo.py +47 -0
- zrb/builtin/project/add/fastapp/field/_helper/inject_schema.py +45 -0
- zrb/builtin/project/add/fastapp/field/_helper/inject_test.py +49 -0
- zrb/builtin/project/add/fastapp/field/_helper/inject_update_page.py +50 -0
- zrb/builtin/project/add/fastapp/field/_input.py +14 -2
- zrb/builtin/project/add/fastapp/field/field.py +70 -90
- zrb/builtin/project/add/fastapp/module/_helper/__init__.py +17 -0
- zrb/builtin/project/add/fastapp/module/_helper/append_all_disabled_env.py +22 -0
- zrb/builtin/project/add/fastapp/module/_helper/append_all_enabled_env.py +22 -0
- zrb/builtin/project/add/fastapp/module/_helper/append_deployment_template_env.py +25 -0
- zrb/builtin/project/add/fastapp/module/_helper/append_src_template_env.py +25 -0
- zrb/builtin/project/add/fastapp/module/_helper/create_app_config.py +29 -0
- zrb/builtin/project/add/fastapp/module/_helper/create_microservice_config.py +158 -0
- zrb/builtin/project/add/fastapp/module/_helper/register_migration.py +35 -0
- zrb/builtin/project/add/fastapp/module/_helper/register_module.py +33 -0
- zrb/builtin/project/add/fastapp/module/module.py +8 -37
- zrb/builtin/project/add/fastapp/module/template/src/kebab-zrb-app-name/src/module/snake_zrb_module_name/migrate.py +2 -2
- zrb/builtin/project/add/fastapp/module/template/src/kebab-zrb-app-name/src/module/snake_zrb_module_name/register_module.py +9 -9
- zrb/builtin/project/add/plugin/plugin.py +2 -2
- zrb/builtin/project/create/create.py +2 -2
- zrb/builtin/version.py +3 -3
- zrb/config/config.py +14 -14
- zrb/helper/callable.py +3 -1
- zrb/helper/cli.py +4 -4
- zrb/helper/file/copy_tree.py +26 -10
- zrb/helper/log.py +3 -3
- zrb/helper/string/parse_replacement.py +1 -1
- zrb/helper/typecheck.py +2 -2
- zrb/helper/typing.py +2 -2
- zrb/helper/util.py +12 -0
- zrb/runner.py +2 -2
- zrb/task/base_remote_cmd_task.py +5 -1
- zrb/task/base_task/base_task.py +3 -3
- zrb/task/base_task/component/base_task_model.py +9 -9
- zrb/task/cmd_task.py +15 -7
- zrb/task/docker_compose_start_task.py +151 -0
- zrb/task/docker_compose_task.py +35 -16
- zrb/task_input/base_input.py +2 -2
- zrb/task_input/multiline_input.py +2 -2
- {zrb-0.23.0.dist-info → zrb-0.24.0.dist-info}/METADATA +3 -3
- {zrb-0.23.0.dist-info → zrb-0.24.0.dist-info}/RECORD +98 -80
- zrb/builtin/project/add/app/generator/template/src/kebab-zrb-package-name/src/snake_zrb_package_name/snake_zrb_generator_name/template/_automate/snake_zrb_app_name/container/init.py +0 -34
- zrb/builtin/project/add/app/python/template/_automate/snake_zrb_app_name/container/init.py +0 -34
- zrb/builtin/project/add/fastapp/app/template/_automate/snake_zrb_app_name/container/microservices/init.py +0 -36
- zrb/builtin/project/add/fastapp/app/template/_automate/snake_zrb_app_name/container/monolith/init.py +0 -36
- zrb/builtin/project/add/fastapp/app/template/_automate/snake_zrb_app_name/container/support/init.py +0 -26
- zrb/builtin/project/add/fastapp/crud/_helper.py +0 -118
- zrb/builtin/project/add/fastapp/field/_helper.py +0 -342
- zrb/builtin/project/add/fastapp/module/_helper.py +0 -313
- {zrb-0.23.0.dist-info → zrb-0.24.0.dist-info}/LICENSE +0 -0
- {zrb-0.23.0.dist-info → zrb-0.24.0.dist-info}/WHEEL +0 -0
- {zrb-0.23.0.dist-info → zrb-0.24.0.dist-info}/entry_points.txt +0 -0
@@ -1,10 +1,10 @@
|
|
1
1
|
from config import (
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
APP_ENABLE_API,
|
3
|
+
APP_ENABLE_EVENT_HANDLER,
|
4
|
+
APP_ENABLE_RPC_SERVER,
|
5
|
+
APP_ENABLE_SNAKE_ZRB_MODULE_NAME_MODULE,
|
6
6
|
)
|
7
|
-
from integration.app import app
|
7
|
+
from integration.app.app import app
|
8
8
|
from integration.log import logger
|
9
9
|
from integration.messagebus import consumer, publisher
|
10
10
|
from integration.rpc import rpc_caller, rpc_server
|
@@ -15,10 +15,10 @@ from module.snake_zrb_module_name.rpc import register_rpc
|
|
15
15
|
|
16
16
|
|
17
17
|
def register_snake_zrb_module_name():
|
18
|
-
if not
|
18
|
+
if not APP_ENABLE_SNAKE_ZRB_MODULE_NAME_MODULE:
|
19
19
|
logger.info('🥪 Skip registering "snake_zrb_module_name"')
|
20
20
|
return
|
21
|
-
if
|
21
|
+
if APP_ENABLE_API:
|
22
22
|
register_api(
|
23
23
|
logger=logger,
|
24
24
|
app=app,
|
@@ -26,11 +26,11 @@ def register_snake_zrb_module_name():
|
|
26
26
|
rpc_caller=rpc_caller,
|
27
27
|
publisher=publisher,
|
28
28
|
)
|
29
|
-
if
|
29
|
+
if APP_ENABLE_EVENT_HANDLER:
|
30
30
|
register_event(
|
31
31
|
logger=logger, consumer=consumer, rpc_caller=rpc_caller, publisher=publisher
|
32
32
|
)
|
33
|
-
if
|
33
|
+
if APP_ENABLE_RPC_SERVER:
|
34
34
|
register_rpc(
|
35
35
|
logger=logger,
|
36
36
|
rpc_server=rpc_server,
|
@@ -17,7 +17,7 @@ from zrb.builtin.project.add.plugin._input import (
|
|
17
17
|
package_repository_input,
|
18
18
|
)
|
19
19
|
from zrb.builtin.project.add.project_task import add_project_tasks
|
20
|
-
from zrb.config.config import
|
20
|
+
from zrb.config.config import VERSION
|
21
21
|
from zrb.helper.accessories.color import colored
|
22
22
|
from zrb.helper.typing import Any
|
23
23
|
from zrb.runner import runner
|
@@ -61,7 +61,7 @@ copy_resource = ResourceMaker(
|
|
61
61
|
"zrbPackageDocumentation": "{{input.package_documentation}}",
|
62
62
|
"zrbPackageAuthorName": "{{input.package_author_name}}",
|
63
63
|
"zrbPackageAuthorEmail": "{{input.package_author_email}}",
|
64
|
-
"zrbVersion":
|
64
|
+
"zrbVersion": VERSION,
|
65
65
|
},
|
66
66
|
template_path=os.path.join(_CURRENT_DIR, "template"),
|
67
67
|
destination_path="{{ input.project_dir }}",
|
@@ -10,7 +10,7 @@ from zrb.builtin.project.create._input import (
|
|
10
10
|
project_description_input,
|
11
11
|
project_name_input,
|
12
12
|
)
|
13
|
-
from zrb.config.config import
|
13
|
+
from zrb.config.config import VERSION
|
14
14
|
from zrb.helper.accessories.color import colored
|
15
15
|
from zrb.helper.typing import Any
|
16
16
|
from zrb.runner import runner
|
@@ -57,7 +57,7 @@ copy_resource = ResourceMaker(
|
|
57
57
|
"zrbProjectAuthorName": "{{input.project_author_name}}",
|
58
58
|
"zrbProjectAuthorEmail": "{{input.project_author_email}}",
|
59
59
|
"zrbImageDefaultNamespace": _IMAGE_DEFAULT_NAMESPACE,
|
60
|
-
"zrbVersion":
|
60
|
+
"zrbVersion": VERSION,
|
61
61
|
},
|
62
62
|
replacement_mutator=copy_resource_replacement_mutator,
|
63
63
|
template_path=os.path.join(_CURRENT_DIR, "template"),
|
zrb/builtin/version.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
from zrb.config.config import
|
1
|
+
from zrb.config.config import VERSION
|
2
2
|
from zrb.helper.typing import Any
|
3
3
|
from zrb.runner import runner
|
4
4
|
from zrb.task.decorator import python_task
|
@@ -8,5 +8,5 @@ from zrb.task.task import Task
|
|
8
8
|
@python_task(name="version", description="Get Zrb version", runner=runner)
|
9
9
|
async def get_version(*args: Any, **kwargs: Any) -> str:
|
10
10
|
task: Task = kwargs.get("_task")
|
11
|
-
task.print_out(
|
12
|
-
return
|
11
|
+
task.print_out(VERSION)
|
12
|
+
return VERSION
|
zrb/config/config.py
CHANGED
@@ -30,19 +30,19 @@ def _get_default_tmp_dir() -> str:
|
|
30
30
|
return os.path.expanduser(os.path.join("~", ".tmp"))
|
31
31
|
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
33
|
+
TMP_DIR = os.getenv("ZRB_TMP_DIR", _get_default_tmp_dir())
|
34
|
+
DEFAULT_SHELL = os.getenv("ZRB_SHELL", _get_current_shell())
|
35
|
+
DEFAULT_EDITOR = os.getenv("ZRB_EDITOR", "nano")
|
36
|
+
INIT_SCRIPT_STR = os.getenv("ZRB_INIT_SCRIPTS", "")
|
37
|
+
INIT_SCRIPTS = INIT_SCRIPT_STR.split(":") if INIT_SCRIPT_STR != "" else []
|
38
|
+
LOGGING_LEVEL = untyped_to_logging_level(os.getenv("ZRB_LOGGING_LEVEL", "WARNING"))
|
39
|
+
SHOULD_LOAD_BUILTIN = untyped_to_boolean(os.getenv("ZRB_SHOULD_LOAD_BUILTIN", "1"))
|
40
|
+
ENV_PREFIX = os.getenv("ZRB_ENV", "")
|
41
|
+
SHOW_ADVERTISEMENT = untyped_to_boolean(os.getenv("ZRB_SHOW_ADVERTISEMENT", "1"))
|
42
|
+
SHOW_PROMPT = untyped_to_boolean(os.getenv("ZRB_SHOW_PROMPT", "1"))
|
43
|
+
SHOW_TIME = untyped_to_boolean(os.getenv("ZRB_SHOW_TIME", "1"))
|
44
|
+
VERSION = _get_version()
|
45
|
+
CONTAINER_BACKEND = _get_valid_container_backend(
|
46
46
|
os.getenv("ZRB_CONTAINER_BACKEND", "docker")
|
47
47
|
)
|
48
|
-
|
48
|
+
ENABLE_TYPE_CHECKING = untyped_to_boolean(os.getenv("ZRB_ENABLE_TYPE_CHECKING", "1"))
|
zrb/helper/callable.py
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
import asyncio
|
2
2
|
import inspect
|
3
|
-
from typing import Any, Callable
|
3
|
+
from typing import Any, Callable, Coroutine
|
4
4
|
|
5
5
|
from zrb.helper.accessories.color import colored
|
6
6
|
from zrb.helper.log import logger
|
7
|
+
from zrb.helper.typecheck import typechecked
|
7
8
|
|
8
9
|
logger.debug(colored("Loading zrb.helper.callable", attrs=["dark"]))
|
9
10
|
|
10
11
|
|
12
|
+
@typechecked
|
11
13
|
async def run_async(fn: Callable, *args: Any, **kwargs: Any) -> Any:
|
12
14
|
if inspect.iscoroutinefunction(fn):
|
13
15
|
return await fn(*args, **kwargs)
|
zrb/helper/cli.py
CHANGED
@@ -4,7 +4,7 @@ from functools import lru_cache
|
|
4
4
|
|
5
5
|
import click
|
6
6
|
|
7
|
-
from zrb.config.config import
|
7
|
+
from zrb.config.config import INIT_SCRIPTS, SHOULD_LOAD_BUILTIN, VERSION
|
8
8
|
from zrb.helper.accessories.color import colored
|
9
9
|
from zrb.helper.loader.load_module import load_module
|
10
10
|
from zrb.helper.log import logger
|
@@ -18,7 +18,7 @@ HELP = f"""
|
|
18
18
|
zzzzz rr rr bb
|
19
19
|
zz rrr r bbbbbb
|
20
20
|
zz rr bb bb
|
21
|
-
zzzzz rr bbbbbb {
|
21
|
+
zzzzz rr bbbbbb {VERSION}
|
22
22
|
_ _ . . . _ . _ . . .
|
23
23
|
|
24
24
|
Super framework for your super app.
|
@@ -40,7 +40,7 @@ def create_cli() -> click.Group:
|
|
40
40
|
logger.info(colored("Prepare CLI", attrs=["dark"]))
|
41
41
|
zrb_cli_group = MultilineHelpClickGroup(name="zrb", help=HELP)
|
42
42
|
# Load default tasks
|
43
|
-
if
|
43
|
+
if SHOULD_LOAD_BUILTIN:
|
44
44
|
logger.info(colored("Load builtins", attrs=["dark"]))
|
45
45
|
from zrb import builtin
|
46
46
|
|
@@ -50,7 +50,7 @@ def create_cli() -> click.Group:
|
|
50
50
|
project_script = os.path.join(project_dir, "zrb_init.py")
|
51
51
|
load_module(script_path=project_script, sys_path_index=0)
|
52
52
|
# load from ZRB_INIT_SCRIPTS environment
|
53
|
-
for index, init_script in enumerate(
|
53
|
+
for index, init_script in enumerate(INIT_SCRIPTS):
|
54
54
|
logger.info(colored(f"Load module from {init_script}", attrs=["dark"]))
|
55
55
|
try:
|
56
56
|
load_module(script_path=init_script, sys_path_index=index + 1)
|
zrb/helper/file/copy_tree.py
CHANGED
@@ -26,6 +26,9 @@ async def copy_tree(
|
|
26
26
|
excludes = []
|
27
27
|
if skip_parsing is None:
|
28
28
|
skip_parsing = []
|
29
|
+
if os.path.isfile(src):
|
30
|
+
await _copy_file(src, dst, replacements, excludes, skip_parsing)
|
31
|
+
return
|
29
32
|
names = os.listdir(src)
|
30
33
|
new_dst = parse_replacement(dst, replacements)
|
31
34
|
if not os.path.exists(new_dst):
|
@@ -38,13 +41,26 @@ async def copy_tree(
|
|
38
41
|
if os.path.isdir(src_name):
|
39
42
|
await copy_tree(src_name, dst_name, replacements, excludes, skip_parsing)
|
40
43
|
continue
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
44
|
+
await _copy_file(src_name, dst_name, replacements, excludes, skip_parsing)
|
45
|
+
|
46
|
+
|
47
|
+
async def _copy_file(
|
48
|
+
src: str,
|
49
|
+
dst: str,
|
50
|
+
replacements: Optional[Mapping[str, str]] = None,
|
51
|
+
excludes: Optional[Iterable[str]] = None,
|
52
|
+
skip_parsing: Optional[Iterable[str]] = None,
|
53
|
+
):
|
54
|
+
if any(fnmatch.fnmatch(src, pattern) for pattern in excludes):
|
55
|
+
return
|
56
|
+
new_dst_name = parse_replacement(dst, replacements)
|
57
|
+
if new_dst_name != src:
|
58
|
+
shutil.copy2(src, new_dst_name)
|
59
|
+
if any(fnmatch.fnmatch(new_dst_name, pattern) for pattern in skip_parsing):
|
60
|
+
return
|
61
|
+
try:
|
62
|
+
file_content = await read_text_file_async(new_dst_name)
|
63
|
+
new_file_content = parse_replacement(file_content, replacements)
|
64
|
+
await write_text_file_async(new_dst_name, new_file_content)
|
65
|
+
except Exception:
|
66
|
+
logger.error(f"Cannot parse file: {new_dst_name}")
|
zrb/helper/log.py
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
import logging
|
2
2
|
|
3
|
-
from zrb.config.config import
|
3
|
+
from zrb.config.config import LOGGING_LEVEL
|
4
4
|
from zrb.helper.accessories.untyped_color import untyped_colored as colored
|
5
5
|
|
6
6
|
# create logger
|
7
7
|
logger = logging.getLogger("zrb")
|
8
|
-
logger.setLevel(
|
8
|
+
logger.setLevel(LOGGING_LEVEL)
|
9
9
|
|
10
10
|
# create console handler and set level to debug
|
11
11
|
ch = logging.StreamHandler()
|
12
|
-
ch.setLevel(
|
12
|
+
ch.setLevel(LOGGING_LEVEL)
|
13
13
|
|
14
14
|
# create formatter
|
15
15
|
formatter = logging.Formatter(
|
@@ -13,7 +13,7 @@ def parse_replacement(text: str, replacement: Mapping[str, str]):
|
|
13
13
|
new_text = text
|
14
14
|
for old, new in replacement.items():
|
15
15
|
if len(new.strip().split("\n")) > 1:
|
16
|
-
pattern = "".join(["^([ \\t]+)", old])
|
16
|
+
pattern = "".join(["^([ \\t]+)", re.escape(old)])
|
17
17
|
new_replacement = "".join(["\\1", new.replace("\n", "\n\\1")])
|
18
18
|
new_text = re.sub(pattern, new_replacement, new_text, flags=re.MULTILINE)
|
19
19
|
continue
|
zrb/helper/typecheck.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
from typing import TypeVar
|
2
2
|
|
3
|
-
from zrb.config.config import
|
3
|
+
from zrb.config.config import ENABLE_TYPE_CHECKING
|
4
4
|
from zrb.helper.accessories.untyped_color import untyped_colored as colored
|
5
5
|
from zrb.helper.log import logger
|
6
6
|
|
@@ -9,7 +9,7 @@ T = TypeVar("T")
|
|
9
9
|
|
10
10
|
|
11
11
|
def typechecked(anything: T) -> T:
|
12
|
-
if
|
12
|
+
if ENABLE_TYPE_CHECKING:
|
13
13
|
from beartype import beartype
|
14
14
|
|
15
15
|
return beartype(anything)
|
zrb/helper/typing.py
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
from zrb.config.config import
|
1
|
+
from zrb.config.config import ENABLE_TYPE_CHECKING
|
2
2
|
from zrb.helper.accessories.untyped_color import untyped_colored as colored
|
3
3
|
from zrb.helper.log import logger
|
4
4
|
|
5
5
|
logger.debug(colored("Loading zrb.helper.typing", attrs=["dark"]))
|
6
6
|
|
7
|
-
if
|
7
|
+
if ENABLE_TYPE_CHECKING:
|
8
8
|
from beartype.typing import (
|
9
9
|
Any,
|
10
10
|
Callable,
|
zrb/helper/util.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import re
|
2
|
+
from functools import lru_cache
|
2
3
|
|
3
4
|
import jinja2
|
4
5
|
|
@@ -18,6 +19,7 @@ def _is_undefined(value: Any) -> bool:
|
|
18
19
|
return value is None or isinstance(value, jinja2.Undefined)
|
19
20
|
|
20
21
|
|
22
|
+
@lru_cache
|
21
23
|
@typechecked
|
22
24
|
def coalesce(value: Any, *alternatives: Any) -> Any:
|
23
25
|
if not _is_undefined(value):
|
@@ -28,6 +30,7 @@ def coalesce(value: Any, *alternatives: Any) -> Any:
|
|
28
30
|
return None
|
29
31
|
|
30
32
|
|
33
|
+
@lru_cache
|
31
34
|
@typechecked
|
32
35
|
def coalesce_str(value: Any, *alternatives: Any) -> Any:
|
33
36
|
if not _is_undefined(value) and value != "":
|
@@ -38,6 +41,7 @@ def coalesce_str(value: Any, *alternatives: Any) -> Any:
|
|
38
41
|
return ""
|
39
42
|
|
40
43
|
|
44
|
+
@lru_cache
|
41
45
|
@typechecked
|
42
46
|
def to_camel_case(text: Optional[str]) -> str:
|
43
47
|
text = str(text) if not _is_undefined(text) else ""
|
@@ -47,6 +51,7 @@ def to_camel_case(text: Optional[str]) -> str:
|
|
47
51
|
return pascal[0].lower() + pascal[1:]
|
48
52
|
|
49
53
|
|
54
|
+
@lru_cache
|
50
55
|
@typechecked
|
51
56
|
def to_pascal_case(text: Optional[str]) -> str:
|
52
57
|
text = str(text) if not _is_undefined(text) else ""
|
@@ -56,6 +61,7 @@ def to_pascal_case(text: Optional[str]) -> str:
|
|
56
61
|
)
|
57
62
|
|
58
63
|
|
64
|
+
@lru_cache
|
59
65
|
@typechecked
|
60
66
|
def to_kebab_case(text: Optional[str]) -> str:
|
61
67
|
text = str(text) if not _is_undefined(text) else ""
|
@@ -63,6 +69,7 @@ def to_kebab_case(text: Optional[str]) -> str:
|
|
63
69
|
return "-".join([x.lower() for x in _to_space_separated(text).split(" ")])
|
64
70
|
|
65
71
|
|
72
|
+
@lru_cache
|
66
73
|
@typechecked
|
67
74
|
def to_snake_case(text: Optional[str]) -> str:
|
68
75
|
text = str(text) if not _is_undefined(text) else ""
|
@@ -70,12 +77,14 @@ def to_snake_case(text: Optional[str]) -> str:
|
|
70
77
|
return "_".join([x.lower() for x in _to_space_separated(text).split(" ")])
|
71
78
|
|
72
79
|
|
80
|
+
@lru_cache
|
73
81
|
@typechecked
|
74
82
|
def _to_alphanum(text: Optional[str]) -> str:
|
75
83
|
text = str(text) if not _is_undefined(text) else ""
|
76
84
|
return NON_ALPHA_NUM.sub(" ", text)
|
77
85
|
|
78
86
|
|
87
|
+
@lru_cache
|
79
88
|
@typechecked
|
80
89
|
def to_human_readable(text: Optional[str]) -> str:
|
81
90
|
text = str(text) if not _is_undefined(text) else ""
|
@@ -87,11 +96,13 @@ def to_human_readable(text: Optional[str]) -> str:
|
|
87
96
|
)
|
88
97
|
|
89
98
|
|
99
|
+
@lru_cache
|
90
100
|
@typechecked
|
91
101
|
def to_capitalized_human_readable(text: Optional[str]) -> str:
|
92
102
|
return to_human_readable(text).capitalize()
|
93
103
|
|
94
104
|
|
105
|
+
@lru_cache
|
95
106
|
@typechecked
|
96
107
|
def _to_space_separated(text: Optional[str]) -> str:
|
97
108
|
text = str(text) if not _is_undefined(text) else ""
|
@@ -122,6 +133,7 @@ def _to_space_separated(text: Optional[str]) -> str:
|
|
122
133
|
return " ".join(new_parts).strip(" ")
|
123
134
|
|
124
135
|
|
136
|
+
@lru_cache
|
125
137
|
@typechecked
|
126
138
|
def to_boolean(text: str) -> bool:
|
127
139
|
return conversion_to_boolean(text)
|
zrb/runner.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
from zrb.action.runner import Runner
|
2
|
-
from zrb.config.config import
|
2
|
+
from zrb.config.config import ENV_PREFIX
|
3
3
|
from zrb.helper.accessories.color import colored
|
4
4
|
from zrb.helper.log import logger
|
5
5
|
|
6
6
|
logger.debug(colored("Loading zrb.runner", attrs=["dark"]))
|
7
|
-
runner = Runner(env_prefix=
|
7
|
+
runner = Runner(env_prefix=ENV_PREFIX)
|
zrb/task/base_remote_cmd_task.py
CHANGED
@@ -82,6 +82,7 @@ class SingleBaseRemoteCmdTask(CmdTask):
|
|
82
82
|
post_cmd: CmdVal = "",
|
83
83
|
post_cmd_path: CmdVal = "",
|
84
84
|
cwd: Optional[Union[str, pathlib.Path]] = None,
|
85
|
+
should_render_cwd: bool = True,
|
85
86
|
upstreams: Iterable[AnyTask] = [],
|
86
87
|
fallbacks: Iterable[AnyTask] = [],
|
87
88
|
on_triggered: Optional[OnTriggered] = None,
|
@@ -118,6 +119,7 @@ class SingleBaseRemoteCmdTask(CmdTask):
|
|
118
119
|
cmd=cmd,
|
119
120
|
cmd_path=cmd_path,
|
120
121
|
cwd=cwd,
|
122
|
+
should_render_cwd=should_render_cwd,
|
121
123
|
upstreams=upstreams,
|
122
124
|
fallbacks=fallbacks,
|
123
125
|
on_triggered=on_triggered,
|
@@ -226,7 +228,8 @@ class BaseRemoteCmdTask(BaseTask):
|
|
226
228
|
cmd_path: CmdVal = "",
|
227
229
|
post_cmd: CmdVal = "",
|
228
230
|
post_cmd_path: CmdVal = "",
|
229
|
-
cwd: Optional[Union[
|
231
|
+
cwd: Optional[Union[JinjaTemplate, pathlib.Path]] = None,
|
232
|
+
should_render_cwd: bool = True,
|
230
233
|
upstreams: Iterable[AnyTask] = [],
|
231
234
|
fallbacks: Iterable[AnyTask] = [],
|
232
235
|
on_triggered: Optional[OnTriggered] = None,
|
@@ -266,6 +269,7 @@ class BaseRemoteCmdTask(BaseTask):
|
|
266
269
|
post_cmd=post_cmd,
|
267
270
|
post_cmd_path=post_cmd_path,
|
268
271
|
cwd=cwd,
|
272
|
+
should_render_cwd=should_render_cwd,
|
269
273
|
upstreams=upstreams,
|
270
274
|
fallbacks=fallbacks,
|
271
275
|
on_triggered=on_triggered,
|
zrb/task/base_task/base_task.py
CHANGED
@@ -4,7 +4,7 @@ import os
|
|
4
4
|
import shutil
|
5
5
|
|
6
6
|
from zrb.advertisement import advertisements
|
7
|
-
from zrb.config.config import
|
7
|
+
from zrb.config.config import SHOW_ADVERTISEMENT, TMP_DIR
|
8
8
|
from zrb.helper.accessories.name import get_random_name
|
9
9
|
from zrb.helper.advertisement import get_advertisement
|
10
10
|
from zrb.helper.callable import run_async
|
@@ -127,7 +127,7 @@ class BaseTask(FinishTracker, AttemptTracker, Renderer, BaseTaskModel, AnyTask):
|
|
127
127
|
def __get_xcom_dir(self, execution_id: Optional[str] = None) -> str:
|
128
128
|
if execution_id is None:
|
129
129
|
execution_id = self.get_execution_id()
|
130
|
-
return os.path.join(
|
130
|
+
return os.path.join(TMP_DIR, f"xcom.{execution_id}")
|
131
131
|
|
132
132
|
def __ensure_xcom_dir_exists(self, execution_id: Optional[str] = None):
|
133
133
|
xcom_dir = self.__get_xcom_dir(execution_id=execution_id)
|
@@ -303,7 +303,7 @@ class BaseTask(FinishTracker, AttemptTracker, Renderer, BaseTaskModel, AnyTask):
|
|
303
303
|
await asyncio.sleep(self._checking_interval)
|
304
304
|
self._end_timer()
|
305
305
|
if show_done_info:
|
306
|
-
if
|
306
|
+
if SHOW_ADVERTISEMENT:
|
307
307
|
selected_advertisement = get_advertisement(advertisements)
|
308
308
|
selected_advertisement.show()
|
309
309
|
self._show_done_info()
|
@@ -4,7 +4,7 @@ import os
|
|
4
4
|
import sys
|
5
5
|
from functools import lru_cache
|
6
6
|
|
7
|
-
from zrb.config.config import
|
7
|
+
from zrb.config.config import ENV_PREFIX, LOGGING_LEVEL, SHOW_TIME
|
8
8
|
from zrb.helper.accessories.color import colored
|
9
9
|
from zrb.helper.log import logger
|
10
10
|
from zrb.helper.string.conversion import to_variable_name
|
@@ -118,35 +118,35 @@ class BaseTaskModel(CommonTaskModel, PidModel, TimeTracker):
|
|
118
118
|
self.__kwargs = kwargs
|
119
119
|
|
120
120
|
def log_debug(self, message: Any):
|
121
|
-
if
|
121
|
+
if LOGGING_LEVEL > logging.DEBUG:
|
122
122
|
return
|
123
123
|
prefix = self.__get_log_prefix()
|
124
124
|
colored_message = colored(f"{prefix} • {message}", attrs=["dark"])
|
125
125
|
logger.debug(colored_message)
|
126
126
|
|
127
127
|
def log_warn(self, message: Any):
|
128
|
-
if
|
128
|
+
if LOGGING_LEVEL > logging.WARNING:
|
129
129
|
return
|
130
130
|
prefix = self.__get_log_prefix()
|
131
131
|
colored_message = colored(f"{prefix} • {message}", attrs=["dark"])
|
132
132
|
logger.warning(colored_message)
|
133
133
|
|
134
134
|
def log_info(self, message: Any):
|
135
|
-
if
|
135
|
+
if LOGGING_LEVEL > logging.INFO:
|
136
136
|
return
|
137
137
|
prefix = self.__get_log_prefix()
|
138
138
|
colored_message = colored(f"{prefix} • {message}", attrs=["dark"])
|
139
139
|
logger.info(colored_message)
|
140
140
|
|
141
141
|
def log_error(self, message: Any):
|
142
|
-
if
|
142
|
+
if LOGGING_LEVEL > logging.ERROR:
|
143
143
|
return
|
144
144
|
prefix = self.__get_log_prefix()
|
145
145
|
colored_message = colored(f"{prefix} • {message}", color="red", attrs=["bold"])
|
146
146
|
logger.error(colored_message, exc_info=True)
|
147
147
|
|
148
148
|
def log_critical(self, message: Any):
|
149
|
-
if
|
149
|
+
if LOGGING_LEVEL > logging.CRITICAL:
|
150
150
|
return
|
151
151
|
prefix = self.__get_log_prefix()
|
152
152
|
colored_message = colored(f"{prefix} • {message}", color="red", attrs=["bold"])
|
@@ -192,9 +192,9 @@ class BaseTaskModel(CommonTaskModel, PidModel, TimeTracker):
|
|
192
192
|
self._play_bell()
|
193
193
|
|
194
194
|
def _show_env_prefix(self):
|
195
|
-
if
|
195
|
+
if ENV_PREFIX == "":
|
196
196
|
return
|
197
|
-
colored_env_prefix = colored(
|
197
|
+
colored_env_prefix = colored(ENV_PREFIX, color="yellow")
|
198
198
|
colored_label = colored("Your current environment: ", attrs=["dark"])
|
199
199
|
print(colored(f"{colored_label}{colored_env_prefix}"), file=sys.stderr)
|
200
200
|
|
@@ -225,7 +225,7 @@ class BaseTaskModel(CommonTaskModel, PidModel, TimeTracker):
|
|
225
225
|
return colored(text, color=self.get_color())
|
226
226
|
|
227
227
|
def __get_print_prefix(self) -> str:
|
228
|
-
common_prefix = self.__get_common_prefix(show_time=
|
228
|
+
common_prefix = self.__get_common_prefix(show_time=SHOW_TIME)
|
229
229
|
icon = self.get_icon()
|
230
230
|
length = LOG_NAME_LENGTH - len(icon)
|
231
231
|
rjust_cli_name = self.__get_rjust_full_cli_name(length)
|
zrb/task/cmd_task.py
CHANGED
@@ -8,7 +8,7 @@ import subprocess
|
|
8
8
|
import sys
|
9
9
|
import time
|
10
10
|
|
11
|
-
from zrb.config.config import
|
11
|
+
from zrb.config.config import DEFAULT_SHELL, LOGGING_LEVEL
|
12
12
|
from zrb.helper.accessories.color import colored
|
13
13
|
from zrb.helper.log import logger
|
14
14
|
from zrb.helper.typecheck import typechecked
|
@@ -57,7 +57,7 @@ def _reset_stty():
|
|
57
57
|
|
58
58
|
|
59
59
|
def _log_error(message: Any):
|
60
|
-
if
|
60
|
+
if LOGGING_LEVEL > logging.ERROR:
|
61
61
|
return
|
62
62
|
colored_message = colored(f"{message}", color="red", attrs=["bold"])
|
63
63
|
logger.error(colored_message, exc_info=True)
|
@@ -127,7 +127,8 @@ class CmdTask(BaseTask):
|
|
127
127
|
executable: Optional[str] = None,
|
128
128
|
cmd: CmdVal = "",
|
129
129
|
cmd_path: CmdVal = "",
|
130
|
-
cwd: Optional[Union[
|
130
|
+
cwd: Optional[Union[JinjaTemplate, pathlib.Path]] = None,
|
131
|
+
should_render_cwd: bool = True,
|
131
132
|
upstreams: Iterable[AnyTask] = [],
|
132
133
|
fallbacks: Iterable[AnyTask] = [],
|
133
134
|
on_triggered: Optional[OnTriggered] = None,
|
@@ -181,12 +182,13 @@ class CmdTask(BaseTask):
|
|
181
182
|
self._cmd = cmd
|
182
183
|
self._cmd_path = cmd_path
|
183
184
|
self.__set_cwd(cwd)
|
185
|
+
self._should_render_cwd = should_render_cwd
|
184
186
|
self._max_output_size = max_output_line
|
185
187
|
self._max_error_size = max_error_line
|
186
188
|
self._output_buffer: Iterable[str] = []
|
187
189
|
self._error_buffer: Iterable[str] = []
|
188
|
-
if executable is None and
|
189
|
-
executable =
|
190
|
+
if executable is None and DEFAULT_SHELL != "":
|
191
|
+
executable = DEFAULT_SHELL
|
190
192
|
self._executable = executable
|
191
193
|
self._process: Optional[asyncio.subprocess.Process]
|
192
194
|
self._preexec_fn = preexec_fn
|
@@ -233,13 +235,14 @@ class CmdTask(BaseTask):
|
|
233
235
|
cmd = self.get_cmd_script(*args, **kwargs)
|
234
236
|
if self._should_show_cmd:
|
235
237
|
self.print_out_dark("Run script: " + self.__get_multiline_repr(cmd))
|
238
|
+
cwd = self._get_cwd()
|
236
239
|
if self._should_show_working_directory:
|
237
|
-
self.print_out_dark("Working directory: " +
|
240
|
+
self.print_out_dark("Working directory: " + cwd)
|
238
241
|
self._output_buffer = []
|
239
242
|
self._error_buffer = []
|
240
243
|
process = await asyncio.create_subprocess_shell(
|
241
244
|
cmd,
|
242
|
-
cwd=
|
245
|
+
cwd=cwd,
|
243
246
|
stdout=asyncio.subprocess.PIPE,
|
244
247
|
stderr=asyncio.subprocess.PIPE,
|
245
248
|
env=self.get_env_map(),
|
@@ -272,6 +275,11 @@ class CmdTask(BaseTask):
|
|
272
275
|
self.set_task_xcom(key="error", value=error)
|
273
276
|
return CmdResult(output, error)
|
274
277
|
|
278
|
+
def _get_cwd(self) -> Union[str, pathlib.Path]:
|
279
|
+
if self._should_render_cwd and isinstance(self._cwd, str):
|
280
|
+
return self.render_str(self._cwd)
|
281
|
+
return self._cwd
|
282
|
+
|
275
283
|
def _should_attempt(self) -> bool:
|
276
284
|
if self._global_state.no_more_attempt:
|
277
285
|
return False
|