zrb 0.23.4__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/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/integration/app/app.py +28 -28
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/integration/app/app_lifespan.py +15 -15
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/integration/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/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 +8 -8
- 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 +8 -8
- 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 -24
- 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 +51 -69
- 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 +8 -8
- 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/log.py +3 -3
- 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_task/base_task.py +3 -3
- zrb/task/base_task/component/base_task_model.py +9 -9
- zrb/task/cmd_task.py +4 -4
- zrb/task/docker_compose_start_task.py +151 -0
- zrb/task/docker_compose_task.py +32 -15
- zrb/task_input/base_input.py +2 -2
- zrb/task_input/multiline_input.py +2 -2
- {zrb-0.23.4.dist-info → zrb-0.24.0.dist-info}/METADATA +2 -2
- {zrb-0.23.4.dist-info → zrb-0.24.0.dist-info}/RECORD +90 -73
- 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 -328
- zrb/builtin/project/add/fastapp/module/_helper.py +0 -313
- {zrb-0.23.4.dist-info → zrb-0.24.0.dist-info}/LICENSE +0 -0
- {zrb-0.23.4.dist-info → zrb-0.24.0.dist-info}/WHEEL +0 -0
- {zrb-0.23.4.dist-info → zrb-0.24.0.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,158 @@
|
|
1
|
+
import asyncio
|
2
|
+
import os
|
3
|
+
|
4
|
+
import jsons
|
5
|
+
from dotenv import dotenv_values
|
6
|
+
|
7
|
+
from zrb.helper.docker_compose.file import add_services
|
8
|
+
from zrb.helper.file.text import (
|
9
|
+
append_text_file_async,
|
10
|
+
read_text_file_async,
|
11
|
+
write_text_file_async,
|
12
|
+
)
|
13
|
+
from zrb.helper.typecheck import typechecked
|
14
|
+
from zrb.helper.typing import Any, List, Mapping
|
15
|
+
from zrb.helper.util import to_kebab_case, to_snake_case
|
16
|
+
from zrb.task.task import Task
|
17
|
+
|
18
|
+
|
19
|
+
@typechecked
|
20
|
+
async def create_microservice_config(
|
21
|
+
task: Task, project_dir: str, app_name: str, module_name: str
|
22
|
+
):
|
23
|
+
modules = await _create_automation_json_config(
|
24
|
+
task, project_dir, app_name, module_name
|
25
|
+
)
|
26
|
+
return await asyncio.gather(
|
27
|
+
asyncio.create_task(
|
28
|
+
_add_docker_compose_service(
|
29
|
+
task, modules, project_dir, app_name, module_name
|
30
|
+
)
|
31
|
+
),
|
32
|
+
asyncio.create_task(
|
33
|
+
_append_compose_env(task, modules, project_dir, app_name, module_name)
|
34
|
+
),
|
35
|
+
)
|
36
|
+
|
37
|
+
|
38
|
+
@typechecked
|
39
|
+
async def _add_docker_compose_service(
|
40
|
+
task: Task, modules: List[str], project_dir: str, app_name: str, module_name: str
|
41
|
+
):
|
42
|
+
kebab_app_name = to_kebab_case(app_name)
|
43
|
+
snake_module_name = to_snake_case(module_name)
|
44
|
+
upper_snake_module_name = snake_module_name.upper()
|
45
|
+
module_app_port = 8080 + len(modules)
|
46
|
+
module_app_port_str = str(module_app_port)
|
47
|
+
docker_compose_file_path = os.path.join(
|
48
|
+
project_dir, "src", kebab_app_name, "docker-compose.yml"
|
49
|
+
)
|
50
|
+
app_container_port_env_name = f"APP_{upper_snake_module_name}_MODULE_PORT"
|
51
|
+
app_container_port_env = (
|
52
|
+
"${" + app_container_port_env_name + ":-" + module_app_port_str + "}"
|
53
|
+
) # noqa
|
54
|
+
app_host_port_env_name = f"APP_{upper_snake_module_name}_HOST_MODULE_PORT"
|
55
|
+
app_host_port_env = (
|
56
|
+
"${" + app_host_port_env_name + ":-" + module_app_port_str + "}"
|
57
|
+
) # noqa
|
58
|
+
service_definition = _get_new_docker_compose_service_definition(
|
59
|
+
app_name=app_name,
|
60
|
+
module_name=module_name,
|
61
|
+
app_host_port_env=app_host_port_env,
|
62
|
+
app_container_port_env=app_container_port_env,
|
63
|
+
)
|
64
|
+
task.print_out(f"Add service at: {docker_compose_file_path}")
|
65
|
+
add_services(
|
66
|
+
file_name=docker_compose_file_path,
|
67
|
+
new_services=service_definition,
|
68
|
+
)
|
69
|
+
|
70
|
+
|
71
|
+
@typechecked
|
72
|
+
def _get_new_docker_compose_service_definition(
|
73
|
+
app_name: str, module_name: str, app_host_port_env: str, app_container_port_env: str
|
74
|
+
) -> Mapping[str, Any]:
|
75
|
+
kebab_app_name = to_kebab_case(app_name)
|
76
|
+
kebab_module_name = to_kebab_case(module_name)
|
77
|
+
snake_module_name = to_snake_case(module_name)
|
78
|
+
upper_snake_module_name = snake_module_name.upper()
|
79
|
+
return {
|
80
|
+
f"{kebab_app_name}-{kebab_module_name}-service": {
|
81
|
+
"build": {"dockerfile": "Dockerfile", "context": "./src"},
|
82
|
+
"image": "${IMAGE:-" + kebab_app_name + "}",
|
83
|
+
"container_name": "${CONTAINER_PREFIX:-my}-"
|
84
|
+
+ f"{kebab_app_name}-{kebab_module_name}-service", # noqa
|
85
|
+
"hostname": f"{kebab_app_name}-{kebab_module_name}-service",
|
86
|
+
"env_file": ["src/template.env", "all-module-disabled.env"],
|
87
|
+
"environment": {
|
88
|
+
"APP_NAME": "${APP_NAME:-"
|
89
|
+
+ kebab_app_name
|
90
|
+
+ "}-"
|
91
|
+
+ f"{kebab_module_name}-service", # noqa
|
92
|
+
"APP_ENABLE_OTEL": "${APP_ENABLE_OTEL:-0}",
|
93
|
+
"APP_PORT": app_container_port_env,
|
94
|
+
"APP_ENABLE_EVENT_HANDLER": "true",
|
95
|
+
"APP_ENABLE_RPC_SERVER": "true",
|
96
|
+
"APP_ENABLE_API": "false",
|
97
|
+
"APP_ENABLE_FRONTEND": "false",
|
98
|
+
f"APP_ENABLE_{upper_snake_module_name}_MODULE": "true",
|
99
|
+
},
|
100
|
+
"ports": [f"{app_host_port_env}:{app_container_port_env}"],
|
101
|
+
"restart": "unless-stopped",
|
102
|
+
"profiles": ["microservices"],
|
103
|
+
"healthcheck": {
|
104
|
+
"test": f"curl --fail http://localhost:{app_container_port_env}/readiness || killall uvicorn", # noqa
|
105
|
+
"interval": "20s",
|
106
|
+
"timeout": "3s",
|
107
|
+
"retries": 10,
|
108
|
+
"start_period": "20s",
|
109
|
+
},
|
110
|
+
"networks": ["zrb"],
|
111
|
+
}
|
112
|
+
}
|
113
|
+
|
114
|
+
|
115
|
+
@typechecked
|
116
|
+
async def _create_automation_json_config(
|
117
|
+
task: Task,
|
118
|
+
project_dir: str,
|
119
|
+
app_name: str,
|
120
|
+
module_name: str,
|
121
|
+
):
|
122
|
+
snake_app_name = to_snake_case(app_name)
|
123
|
+
snake_module_name = to_snake_case(module_name)
|
124
|
+
json_modules_file_path = os.path.join(
|
125
|
+
project_dir, "_automate", snake_app_name, "config", "modules.json"
|
126
|
+
)
|
127
|
+
task.print_out(f"Read json config from: {json_modules_file_path}")
|
128
|
+
json_str = await read_text_file_async(json_modules_file_path)
|
129
|
+
task.print_out(f'Add "{snake_module_name}" to json config')
|
130
|
+
modules: List[str] = jsons.loads(json_str)
|
131
|
+
modules.append(snake_module_name)
|
132
|
+
json_str = jsons.dumps(modules)
|
133
|
+
task.print_out(f"Write new json config to: {json_modules_file_path}")
|
134
|
+
await write_text_file_async(json_modules_file_path, json_str)
|
135
|
+
return modules
|
136
|
+
|
137
|
+
|
138
|
+
@typechecked
|
139
|
+
async def _append_compose_env(
|
140
|
+
task: Task, modules: List[str], project_dir: str, app_name: str, module_name: str
|
141
|
+
):
|
142
|
+
kebab_app_name = to_kebab_case(app_name)
|
143
|
+
snake_module_name = to_snake_case(module_name)
|
144
|
+
upper_snake_module_name = snake_module_name.upper()
|
145
|
+
compose_template_env_path = os.path.join(
|
146
|
+
project_dir, "src", kebab_app_name, "docker-compose.env"
|
147
|
+
)
|
148
|
+
compose_env_map = dotenv_values(compose_template_env_path)
|
149
|
+
host_port = int(compose_env_map.get("APP_GATEWAY_HOST_PORT", "8080"))
|
150
|
+
module_app_port = host_port + len(modules)
|
151
|
+
new_env_str = "\n".join(
|
152
|
+
[
|
153
|
+
f"APP_{upper_snake_module_name}_HOST_MODULE_PORT={module_app_port}",
|
154
|
+
f"APP_{upper_snake_module_name}_MODULE_PORT={module_app_port}",
|
155
|
+
]
|
156
|
+
)
|
157
|
+
task.print_out(f"Add new environment to: {compose_template_env_path}")
|
158
|
+
await append_text_file_async(compose_template_env_path, new_env_str)
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import os
|
2
|
+
|
3
|
+
from zrb.helper.codemod.add_import_module import add_import_module
|
4
|
+
from zrb.helper.codemod.append_code_to_function import append_code_to_function
|
5
|
+
from zrb.helper.file.text import read_text_file_async, write_text_file_async
|
6
|
+
from zrb.helper.typecheck import typechecked
|
7
|
+
from zrb.helper.util import to_kebab_case, to_snake_case
|
8
|
+
from zrb.task.task import Task
|
9
|
+
|
10
|
+
|
11
|
+
@typechecked
|
12
|
+
async def register_migration(
|
13
|
+
task: Task, project_dir: str, app_name: str, module_name: str
|
14
|
+
):
|
15
|
+
kebab_app_name = to_kebab_case(app_name)
|
16
|
+
snake_module_name = to_snake_case(module_name)
|
17
|
+
app_migration_file_path = os.path.join(
|
18
|
+
project_dir, "src", kebab_app_name, "src", "migrate.py"
|
19
|
+
)
|
20
|
+
import_module_path = ".".join(["module", snake_module_name, "migrate"])
|
21
|
+
function_name = f"migrate_{snake_module_name}"
|
22
|
+
task.print_out(f"Read code from: {app_migration_file_path}")
|
23
|
+
code = await read_text_file_async(app_migration_file_path)
|
24
|
+
task.print_out(
|
25
|
+
f'Add import "{function_name}" from "{import_module_path}" to the code'
|
26
|
+
)
|
27
|
+
code = add_import_module(
|
28
|
+
code=code, module_path=import_module_path, resource=function_name
|
29
|
+
)
|
30
|
+
task.print_out(f'Add "{function_name}" call to the code')
|
31
|
+
code = append_code_to_function(
|
32
|
+
code=code, function_name="migrate", new_code=f"await {function_name}()"
|
33
|
+
)
|
34
|
+
task.print_out(f"Write modified code to: {app_migration_file_path}")
|
35
|
+
await write_text_file_async(app_migration_file_path, code)
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import os
|
2
|
+
|
3
|
+
from zrb.helper.codemod.add_function_call import add_function_call
|
4
|
+
from zrb.helper.codemod.add_import_module import add_import_module
|
5
|
+
from zrb.helper.file.text import read_text_file_async, write_text_file_async
|
6
|
+
from zrb.helper.typecheck import typechecked
|
7
|
+
from zrb.helper.util import to_kebab_case, to_snake_case
|
8
|
+
from zrb.task.task import Task
|
9
|
+
|
10
|
+
|
11
|
+
@typechecked
|
12
|
+
async def register_module(
|
13
|
+
task: Task, project_dir: str, app_name: str, module_name: str
|
14
|
+
):
|
15
|
+
kebab_app_name = to_kebab_case(app_name)
|
16
|
+
snake_module_name = to_snake_case(module_name)
|
17
|
+
app_main_file_path = os.path.join(
|
18
|
+
project_dir, "src", kebab_app_name, "src", "main.py"
|
19
|
+
)
|
20
|
+
import_module_path = ".".join(["module", snake_module_name, "register_module"])
|
21
|
+
function_name = f"register_{snake_module_name}"
|
22
|
+
task.print_out(f"Read code from: {app_main_file_path}")
|
23
|
+
code = await read_text_file_async(app_main_file_path)
|
24
|
+
task.print_out(
|
25
|
+
f'Add import "{function_name}" from "{import_module_path}" to the code'
|
26
|
+
)
|
27
|
+
code = add_import_module(
|
28
|
+
code=code, module_path=import_module_path, resource=function_name
|
29
|
+
)
|
30
|
+
task.print_out(f'Add "{function_name}" call to the code')
|
31
|
+
code = add_function_call(code=code, function_name=function_name, parameters=[])
|
32
|
+
task.print_out(f"Write modified code to: {app_main_file_path}")
|
33
|
+
await write_text_file_async(app_main_file_path, code)
|
@@ -88,57 +88,28 @@ async def add_fastapp_module(*args: Any, **kwargs: Any):
|
|
88
88
|
project_dir = kwargs.get("project_dir", ".")
|
89
89
|
app_name = kwargs.get("app_name")
|
90
90
|
module_name = kwargs.get("module_name")
|
91
|
-
kebab_app_name = util.to_kebab_case(app_name)
|
92
|
-
snake_app_name = util.to_snake_case(app_name)
|
93
|
-
kebab_module_name = util.to_kebab_case(module_name)
|
94
|
-
snake_module_name = util.to_snake_case(module_name)
|
95
|
-
upper_snake_module_name = snake_module_name.upper()
|
96
91
|
await asyncio.gather(
|
97
92
|
asyncio.create_task(
|
98
|
-
create_microservice_config(
|
99
|
-
task,
|
100
|
-
project_dir,
|
101
|
-
kebab_app_name,
|
102
|
-
snake_app_name,
|
103
|
-
kebab_module_name,
|
104
|
-
snake_module_name,
|
105
|
-
upper_snake_module_name,
|
106
|
-
)
|
107
|
-
),
|
108
|
-
asyncio.create_task(
|
109
|
-
register_module(task, project_dir, kebab_app_name, snake_module_name)
|
93
|
+
create_microservice_config(task, project_dir, app_name, module_name)
|
110
94
|
),
|
95
|
+
asyncio.create_task(register_module(task, project_dir, app_name, module_name)),
|
111
96
|
asyncio.create_task(
|
112
|
-
register_migration(task, project_dir,
|
97
|
+
register_migration(task, project_dir, app_name, module_name)
|
113
98
|
),
|
114
99
|
asyncio.create_task(
|
115
|
-
create_app_config(
|
116
|
-
task,
|
117
|
-
project_dir,
|
118
|
-
kebab_app_name,
|
119
|
-
snake_module_name,
|
120
|
-
upper_snake_module_name,
|
121
|
-
)
|
100
|
+
create_app_config(task, project_dir, app_name, module_name)
|
122
101
|
),
|
123
102
|
asyncio.create_task(
|
124
|
-
append_all_enabled_env(
|
125
|
-
task, project_dir, kebab_app_name, upper_snake_module_name
|
126
|
-
)
|
103
|
+
append_all_enabled_env(task, project_dir, app_name, module_name)
|
127
104
|
),
|
128
105
|
asyncio.create_task(
|
129
|
-
append_all_disabled_env(
|
130
|
-
task, project_dir, kebab_app_name, upper_snake_module_name
|
131
|
-
)
|
106
|
+
append_all_disabled_env(task, project_dir, app_name, module_name)
|
132
107
|
),
|
133
108
|
asyncio.create_task(
|
134
|
-
append_src_template_env(
|
135
|
-
task, project_dir, kebab_app_name, upper_snake_module_name
|
136
|
-
)
|
109
|
+
append_src_template_env(task, project_dir, app_name, module_name)
|
137
110
|
),
|
138
111
|
asyncio.create_task(
|
139
|
-
append_deployment_template_env(
|
140
|
-
task, project_dir, kebab_app_name, upper_snake_module_name
|
141
|
-
)
|
112
|
+
append_deployment_template_env(task, project_dir, app_name, module_name)
|
142
113
|
),
|
143
114
|
)
|
144
115
|
task.print_out(colored("Fastapp crud added", color="yellow"))
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from config import
|
1
|
+
from config import APP_ENABLE_SNAKE_ZRB_MODULE_NAME_MODULE
|
2
2
|
from helper.migration import migrate
|
3
3
|
from integration.db_connection import engine
|
4
4
|
from integration.log import logger
|
@@ -6,7 +6,7 @@ from module.snake_zrb_module_name.integration import Base
|
|
6
6
|
|
7
7
|
|
8
8
|
async def migrate_snake_zrb_module_name():
|
9
|
-
if not
|
9
|
+
if not APP_ENABLE_SNAKE_ZRB_MODULE_NAME_MODULE:
|
10
10
|
logger.info('🥪 Skip DB migration for "snake_zrb_module_name"')
|
11
11
|
return
|
12
12
|
logger.info('🥪 Perform DB migration for "snake_zrb_module_name"')
|
@@ -1,8 +1,8 @@
|
|
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
7
|
from integration.app.app import app
|
8
8
|
from integration.log import logger
|
@@ -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/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(
|
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_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()
|