zrb 1.0.0a2__py3-none-any.whl → 1.0.0a3__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 +48 -39
- zrb/__main__.py +3 -3
- zrb/attr/type.py +2 -1
- zrb/builtin/__init__.py +40 -2
- zrb/builtin/base64.py +32 -0
- zrb/builtin/git.py +156 -0
- zrb/builtin/git_subtree.py +88 -0
- zrb/builtin/group.py +34 -0
- zrb/builtin/llm.py +31 -0
- zrb/builtin/md5.py +34 -0
- zrb/builtin/project/__init__.py +0 -0
- zrb/builtin/project/add/__init__.py +0 -0
- zrb/builtin/project/add/fastapp.py +72 -0
- zrb/builtin/project/add/fastapp_template/.gitignore +4 -0
- zrb/builtin/project/add/fastapp_template/README.md +7 -0
- zrb/builtin/project/add/fastapp_template/__init__.py +0 -0
- zrb/builtin/project/add/fastapp_template/_zrb/config.py +17 -0
- zrb/builtin/project/add/fastapp_template/_zrb/group.py +16 -0
- zrb/builtin/project/add/fastapp_template/_zrb/helper.py +97 -0
- zrb/builtin/project/add/fastapp_template/_zrb/main.py +132 -0
- zrb/builtin/project/add/fastapp_template/_zrb/venv_task.py +22 -0
- zrb/builtin/project/add/fastapp_template/common/__init__.py +0 -0
- zrb/builtin/project/add/fastapp_template/common/app.py +18 -0
- zrb/builtin/project/add/fastapp_template/common/db_engine.py +5 -0
- zrb/builtin/project/add/fastapp_template/common/db_repository.py +134 -0
- zrb/builtin/project/add/fastapp_template/common/error.py +8 -0
- zrb/builtin/project/add/fastapp_template/common/schema.py +5 -0
- zrb/builtin/project/add/fastapp_template/common/usecase.py +232 -0
- zrb/builtin/project/add/fastapp_template/config.py +29 -0
- zrb/builtin/project/add/fastapp_template/main.py +7 -0
- zrb/builtin/project/add/fastapp_template/migrate.py +3 -0
- zrb/builtin/project/add/fastapp_template/module/__init__.py +0 -0
- zrb/builtin/project/add/fastapp_template/module/auth/alembic.ini +117 -0
- zrb/builtin/project/add/fastapp_template/module/auth/client/api_client.py +7 -0
- zrb/builtin/project/add/fastapp_template/module/auth/client/base_client.py +27 -0
- zrb/builtin/project/add/fastapp_template/module/auth/client/direct_client.py +6 -0
- zrb/builtin/project/add/fastapp_template/module/auth/client/factory.py +9 -0
- zrb/builtin/project/add/fastapp_template/module/auth/migration/README +1 -0
- zrb/builtin/project/add/fastapp_template/module/auth/migration/env.py +108 -0
- zrb/builtin/project/add/fastapp_template/module/auth/migration/script.py.mako +26 -0
- zrb/builtin/project/add/fastapp_template/module/auth/migration/versions/3093c7336477_add_user_table.py +37 -0
- zrb/builtin/project/add/fastapp_template/module/auth/migration_metadata.py +6 -0
- zrb/builtin/project/add/fastapp_template/module/auth/route.py +22 -0
- zrb/builtin/project/add/fastapp_template/module/auth/service/__init__.py +0 -0
- zrb/builtin/project/add/fastapp_template/module/auth/service/user/__init__.py +0 -0
- zrb/builtin/project/add/fastapp_template/module/auth/service/user/repository/__init__.py +0 -0
- zrb/builtin/project/add/fastapp_template/module/auth/service/user/repository/db_repository.py +39 -0
- zrb/builtin/project/add/fastapp_template/module/auth/service/user/repository/factory.py +13 -0
- zrb/builtin/project/add/fastapp_template/module/auth/service/user/repository/repository.py +34 -0
- zrb/builtin/project/add/fastapp_template/module/auth/service/user/usecase.py +45 -0
- zrb/builtin/project/add/fastapp_template/module/gateway/alembic.ini +117 -0
- zrb/builtin/project/add/fastapp_template/module/gateway/migration/README +1 -0
- zrb/builtin/project/add/fastapp_template/module/gateway/migration/env.py +108 -0
- zrb/builtin/project/add/fastapp_template/module/gateway/migration/script.py.mako +26 -0
- zrb/builtin/project/add/fastapp_template/module/gateway/migration/versions/.gitkeep +0 -0
- zrb/builtin/project/add/fastapp_template/module/gateway/migration_metadata.py +3 -0
- zrb/builtin/project/add/fastapp_template/module/gateway/route.py +27 -0
- zrb/builtin/project/add/fastapp_template/requirements.txt +6 -0
- zrb/builtin/project/add/fastapp_template/schema/__init__.py +0 -0
- zrb/builtin/project/add/fastapp_template/schema/role.py +31 -0
- zrb/builtin/project/add/fastapp_template/schema/user.py +31 -0
- zrb/builtin/project/add/fastapp_template/template.env +2 -0
- zrb/builtin/project/create/__init__.py +0 -0
- zrb/builtin/project/create/create.py +41 -0
- zrb/builtin/project/create/project-template/README.md +3 -0
- zrb/builtin/project/create/project-template/zrb_init.py +7 -0
- zrb/builtin/python.py +11 -0
- zrb/builtin/shell/__init__.py +0 -5
- zrb/builtin/shell/autocomplete/__init__.py +0 -9
- zrb/builtin/shell/autocomplete/bash.py +5 -6
- zrb/builtin/shell/autocomplete/subcmd.py +7 -8
- zrb/builtin/shell/autocomplete/zsh.py +5 -6
- zrb/builtin/todo.py +186 -0
- zrb/callback/any_callback.py +1 -1
- zrb/callback/callback.py +5 -5
- zrb/cmd/cmd_val.py +2 -2
- zrb/config.py +4 -1
- zrb/content_transformer/any_content_transformer.py +1 -1
- zrb/content_transformer/content_transformer.py +2 -2
- zrb/context/any_context.py +1 -1
- zrb/context/any_shared_context.py +3 -3
- zrb/context/context.py +10 -8
- zrb/context/shared_context.py +9 -8
- zrb/env/__init__.py +0 -3
- zrb/env/any_env.py +1 -1
- zrb/env/env.py +3 -4
- zrb/env/env_file.py +4 -4
- zrb/env/env_map.py +2 -2
- zrb/group/__init__.py +0 -3
- zrb/group/any_group.py +3 -3
- zrb/group/group.py +7 -6
- zrb/input/any_input.py +1 -1
- zrb/input/base_input.py +4 -4
- zrb/input/bool_input.py +5 -5
- zrb/input/float_input.py +3 -3
- zrb/input/int_input.py +3 -3
- zrb/input/option_input.py +51 -0
- zrb/input/password_input.py +2 -2
- zrb/input/str_input.py +1 -1
- zrb/input/text_input.py +12 -10
- zrb/runner/cli.py +79 -45
- zrb/runner/web_app/group_info_ui/controller.py +7 -8
- zrb/runner/web_app/group_info_ui/view.html +2 -2
- zrb/runner/web_app/home_page/controller.py +7 -6
- zrb/runner/web_app/home_page/view.html +2 -2
- zrb/runner/web_app/task_ui/controller.py +8 -12
- zrb/runner/web_app/task_ui/view.html +2 -2
- zrb/runner/web_server.py +137 -211
- zrb/runner/web_util.py +5 -35
- zrb/session/any_session.py +13 -7
- zrb/session/session.py +78 -40
- zrb/session_state_log/session_state_log.py +7 -5
- zrb/session_state_logger/any_session_state_logger.py +1 -1
- zrb/session_state_logger/default_session_state_logger.py +2 -2
- zrb/session_state_logger/file_session_state_logger.py +19 -27
- zrb/task/any_task.py +4 -4
- zrb/task/base_task.py +33 -23
- zrb/task/base_trigger.py +11 -12
- zrb/task/cmd_task.py +48 -39
- zrb/task/http_check.py +8 -8
- zrb/task/llm_task.py +160 -0
- zrb/task/make_task.py +9 -9
- zrb/task/rsync_task.py +7 -7
- zrb/task/scaffolder.py +14 -11
- zrb/task/scheduler.py +6 -7
- zrb/task/task.py +1 -1
- zrb/task/tcp_check.py +8 -8
- zrb/util/attr.py +19 -3
- zrb/util/cli/style.py +71 -2
- zrb/util/cli/subcommand.py +2 -2
- zrb/util/codemod/__init__.py +0 -0
- zrb/util/codemod/add_code_to_class.py +35 -0
- zrb/util/codemod/add_code_to_function.py +36 -0
- zrb/util/codemod/add_code_to_method.py +55 -0
- zrb/util/codemod/add_key_to_dict.py +51 -0
- zrb/util/codemod/add_param_to_function_call.py +39 -0
- zrb/util/codemod/add_property_to_class.py +55 -0
- zrb/util/git.py +156 -0
- zrb/util/git_subtree.py +94 -0
- zrb/util/group.py +2 -2
- zrb/util/llm/tool.py +63 -0
- zrb/util/string/conversion.py +7 -0
- zrb/util/todo.py +135 -0
- {zrb-1.0.0a2.dist-info → zrb-1.0.0a3.dist-info}/METADATA +8 -5
- zrb-1.0.0a3.dist-info/RECORD +194 -0
- zrb/builtin/shell/_group.py +0 -9
- zrb/builtin/shell/autocomplete/_group.py +0 -6
- zrb/runner/web_app/any_request_handler.py +0 -24
- zrb-1.0.0a2.dist-info/RECORD +0 -120
- {zrb-1.0.0a2.dist-info → zrb-1.0.0a3.dist-info}/WHEEL +0 -0
- {zrb-1.0.0a2.dist-info → zrb-1.0.0a3.dist-info}/entry_points.txt +0 -0
zrb/__init__.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
from .attr.type import (
|
1
|
+
from zrb.attr.type import (
|
2
2
|
AnyAttr,
|
3
3
|
BoolAttr,
|
4
4
|
FloatAttr,
|
@@ -7,44 +7,50 @@ from .attr.type import (
|
|
7
7
|
StrDictAttr,
|
8
8
|
fstring,
|
9
9
|
)
|
10
|
-
from .callback.any_callback import AnyCallback
|
11
|
-
from .callback.callback import Callback
|
12
|
-
from .cmd.cmd_result import CmdResult
|
13
|
-
from .cmd.cmd_val import Cmd, CmdPath
|
14
|
-
from .config import SHOULD_LOAD_BUILTIN
|
15
|
-
from .content_transformer.any_content_transformer import AnyContentTransformer
|
16
|
-
from .content_transformer.content_transformer import ContentTransformer
|
17
|
-
from .context.any_context import AnyContext
|
18
|
-
from .context.any_shared_context import AnySharedContext
|
19
|
-
from .context.context import Context
|
20
|
-
from .context.shared_context import SharedContext
|
21
|
-
from .env.any_env import AnyEnv
|
22
|
-
from .env.env import Env
|
23
|
-
from .env.env_file import EnvFile
|
24
|
-
from .env.env_map import EnvMap
|
25
|
-
from .group.any_group import AnyGroup
|
26
|
-
from .group.group import Group
|
27
|
-
from .input.any_input import AnyInput
|
28
|
-
from .input.base_input import BaseInput
|
29
|
-
from .input.
|
30
|
-
from .input.
|
31
|
-
from .input.
|
32
|
-
from .input.
|
33
|
-
from .
|
34
|
-
from .
|
35
|
-
from .
|
36
|
-
from .
|
37
|
-
from .task.
|
38
|
-
from .task.
|
39
|
-
from .task.
|
40
|
-
from .task.
|
41
|
-
from .task.
|
42
|
-
from .task.
|
43
|
-
from .task.
|
44
|
-
from .task.
|
45
|
-
from .task.
|
46
|
-
from .
|
10
|
+
from zrb.callback.any_callback import AnyCallback
|
11
|
+
from zrb.callback.callback import Callback
|
12
|
+
from zrb.cmd.cmd_result import CmdResult
|
13
|
+
from zrb.cmd.cmd_val import Cmd, CmdPath
|
14
|
+
from zrb.config import SHOULD_LOAD_BUILTIN
|
15
|
+
from zrb.content_transformer.any_content_transformer import AnyContentTransformer
|
16
|
+
from zrb.content_transformer.content_transformer import ContentTransformer
|
17
|
+
from zrb.context.any_context import AnyContext
|
18
|
+
from zrb.context.any_shared_context import AnySharedContext
|
19
|
+
from zrb.context.context import Context
|
20
|
+
from zrb.context.shared_context import SharedContext
|
21
|
+
from zrb.env.any_env import AnyEnv
|
22
|
+
from zrb.env.env import Env
|
23
|
+
from zrb.env.env_file import EnvFile
|
24
|
+
from zrb.env.env_map import EnvMap
|
25
|
+
from zrb.group.any_group import AnyGroup
|
26
|
+
from zrb.group.group import Group
|
27
|
+
from zrb.input.any_input import AnyInput
|
28
|
+
from zrb.input.base_input import BaseInput
|
29
|
+
from zrb.input.bool_input import BoolInput
|
30
|
+
from zrb.input.int_input import IntInput
|
31
|
+
from zrb.input.option_input import OptionInput
|
32
|
+
from zrb.input.password_input import PasswordInput
|
33
|
+
from zrb.input.str_input import StrInput
|
34
|
+
from zrb.input.text_input import TextInput
|
35
|
+
from zrb.runner.cli import cli
|
36
|
+
from zrb.session.session import Session
|
37
|
+
from zrb.task.any_task import AnyTask
|
38
|
+
from zrb.task.base_task import BaseTask
|
39
|
+
from zrb.task.base_trigger import BaseTrigger
|
40
|
+
from zrb.task.cmd_task import CmdTask
|
41
|
+
from zrb.task.http_check import HttpCheck
|
42
|
+
from zrb.task.llm_task import LLMTask
|
43
|
+
from zrb.task.make_task import make_task
|
44
|
+
from zrb.task.rsync_task import RsyncTask
|
45
|
+
from zrb.task.scaffolder import Scaffolder
|
46
|
+
from zrb.task.scheduler import Scheduler
|
47
|
+
from zrb.task.task import Task
|
48
|
+
from zrb.task.tcp_check import TcpCheck
|
49
|
+
from zrb.util.load import load_file, load_module
|
50
|
+
from zrb.xcom.xcom import Xcom
|
47
51
|
|
52
|
+
assert load_file
|
53
|
+
assert load_module
|
48
54
|
assert fstring
|
49
55
|
assert AnyAttr
|
50
56
|
assert BoolAttr
|
@@ -60,6 +66,7 @@ assert EnvFile
|
|
60
66
|
assert EnvMap
|
61
67
|
assert AnyInput
|
62
68
|
assert BaseInput
|
69
|
+
assert BoolInput
|
63
70
|
assert Cmd
|
64
71
|
assert CmdPath
|
65
72
|
assert CmdResult
|
@@ -67,6 +74,7 @@ assert CmdTask
|
|
67
74
|
assert HttpCheck
|
68
75
|
assert TcpCheck
|
69
76
|
assert IntInput
|
77
|
+
assert OptionInput
|
70
78
|
assert PasswordInput
|
71
79
|
assert StrInput
|
72
80
|
assert TextInput
|
@@ -77,6 +85,7 @@ assert BaseTask
|
|
77
85
|
assert BaseTrigger
|
78
86
|
assert RsyncTask
|
79
87
|
assert Task
|
88
|
+
assert LLMTask
|
80
89
|
assert Session
|
81
90
|
assert AnyContext
|
82
91
|
assert Context
|
@@ -91,6 +100,6 @@ assert cli
|
|
91
100
|
assert Xcom
|
92
101
|
|
93
102
|
if SHOULD_LOAD_BUILTIN:
|
94
|
-
from
|
103
|
+
from zrb import builtin
|
95
104
|
|
96
105
|
assert builtin
|
zrb/__main__.py
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
import sys
|
2
2
|
|
3
|
-
from .runner.cli import cli
|
4
|
-
from .util.cli.style import stylize_error
|
5
|
-
from .util.group import NodeNotFoundError
|
3
|
+
from zrb.runner.cli import cli
|
4
|
+
from zrb.util.cli.style import stylize_error
|
5
|
+
from zrb.util.group import NodeNotFoundError
|
6
6
|
|
7
7
|
|
8
8
|
def serve_cli():
|
zrb/attr/type.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
from typing import Any, Callable
|
2
2
|
|
3
|
-
from
|
3
|
+
from zrb.context.any_shared_context import AnySharedContext
|
4
4
|
|
5
5
|
fstring = str
|
6
6
|
AnyAttr = Any | fstring | Callable[[AnySharedContext], Any]
|
@@ -9,3 +9,4 @@ BoolAttr = bool | fstring | Callable[[AnySharedContext], bool]
|
|
9
9
|
IntAttr = int | fstring | Callable[[AnySharedContext], int]
|
10
10
|
FloatAttr = float | fstring | Callable[[AnySharedContext], float]
|
11
11
|
StrDictAttr = dict[str, StrAttr] | Callable[[AnySharedContext], dict[str, Any]]
|
12
|
+
StrListAttr = list[StrAttr] | Callable[[AnySharedContext], list[str]]
|
zrb/builtin/__init__.py
CHANGED
@@ -1,3 +1,41 @@
|
|
1
|
-
from . import
|
1
|
+
from zrb.builtin.base64 import decode_base64, encode_base64
|
2
|
+
from zrb.builtin.git import (
|
3
|
+
get_git_diff,
|
4
|
+
git_commit,
|
5
|
+
git_pull,
|
6
|
+
git_push,
|
7
|
+
prune_local_branches,
|
8
|
+
)
|
9
|
+
from zrb.builtin.git_subtree import git_add_subtree, git_pull_subtree, git_push_subtree
|
10
|
+
from zrb.builtin.llm import llm_chat
|
11
|
+
from zrb.builtin.md5 import hash_md5, sum_md5
|
12
|
+
from zrb.builtin.project.add.fastapp import add_fastapp_to_project
|
13
|
+
from zrb.builtin.project.create.create import create_project
|
14
|
+
from zrb.builtin.python import format_python_code
|
15
|
+
from zrb.builtin.shell.autocomplete.bash import make_bash_autocomplete
|
16
|
+
from zrb.builtin.shell.autocomplete.subcmd import get_shell_subcommands
|
17
|
+
from zrb.builtin.shell.autocomplete.zsh import make_zsh_autocomplete
|
18
|
+
from zrb.builtin.todo import todo_add, todo_edit, todo_list
|
2
19
|
|
3
|
-
assert
|
20
|
+
assert create_project
|
21
|
+
assert add_fastapp_to_project
|
22
|
+
assert get_shell_subcommands
|
23
|
+
assert make_bash_autocomplete
|
24
|
+
assert make_zsh_autocomplete
|
25
|
+
assert encode_base64
|
26
|
+
assert decode_base64
|
27
|
+
assert llm_chat
|
28
|
+
assert hash_md5
|
29
|
+
assert sum_md5
|
30
|
+
assert get_git_diff
|
31
|
+
assert prune_local_branches
|
32
|
+
assert format_python_code
|
33
|
+
assert git_commit
|
34
|
+
assert git_pull
|
35
|
+
assert git_push
|
36
|
+
assert git_add_subtree
|
37
|
+
assert git_pull_subtree
|
38
|
+
assert git_push_subtree
|
39
|
+
assert todo_list
|
40
|
+
assert todo_add
|
41
|
+
assert todo_edit
|
zrb/builtin/base64.py
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
import base64
|
2
|
+
|
3
|
+
from zrb.builtin.group import base64_group
|
4
|
+
from zrb.context.any_context import AnyContext
|
5
|
+
from zrb.input.str_input import StrInput
|
6
|
+
from zrb.task.make_task import make_task
|
7
|
+
|
8
|
+
|
9
|
+
@make_task(
|
10
|
+
name="encode-base64",
|
11
|
+
input=StrInput(name="text", description="Text", prompt="Text to encode"),
|
12
|
+
description="🔐 Encode text to base64",
|
13
|
+
group=base64_group,
|
14
|
+
alias="encode",
|
15
|
+
)
|
16
|
+
def encode_base64(ctx: AnyContext) -> str:
|
17
|
+
result = base64.b64encode(ctx.input.text.encode()).decode()
|
18
|
+
ctx.print(result)
|
19
|
+
return result
|
20
|
+
|
21
|
+
|
22
|
+
@make_task(
|
23
|
+
name="decode-base64",
|
24
|
+
input=StrInput(name="text", description="Text", prompt="Text to encode"),
|
25
|
+
description="🔓 Decode base64 text",
|
26
|
+
group=base64_group,
|
27
|
+
alias="decode",
|
28
|
+
)
|
29
|
+
def decode_base64(ctx: AnyContext) -> str:
|
30
|
+
result = base64.b64decode(ctx.input.text.encode()).decode()
|
31
|
+
ctx.print(result)
|
32
|
+
return result
|
zrb/builtin/git.py
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
from zrb.builtin.group import git_branch_group, git_group
|
2
|
+
from zrb.context.any_context import AnyContext
|
3
|
+
from zrb.input.bool_input import BoolInput
|
4
|
+
from zrb.input.str_input import StrInput
|
5
|
+
from zrb.task.make_task import make_task
|
6
|
+
from zrb.util.cli.style import stylize_green, stylize_red, stylize_yellow
|
7
|
+
from zrb.util.git import (
|
8
|
+
add,
|
9
|
+
commit,
|
10
|
+
delete_branch,
|
11
|
+
get_branches,
|
12
|
+
get_current_branch,
|
13
|
+
get_diff,
|
14
|
+
pull,
|
15
|
+
push,
|
16
|
+
)
|
17
|
+
|
18
|
+
|
19
|
+
@make_task(
|
20
|
+
name="get-git-diff",
|
21
|
+
input=[
|
22
|
+
StrInput(
|
23
|
+
name="source",
|
24
|
+
description="Source branch/tag/commit",
|
25
|
+
prompt="Source branch/tag/commit",
|
26
|
+
default_str="main",
|
27
|
+
),
|
28
|
+
StrInput(
|
29
|
+
name="current",
|
30
|
+
description="Current branch/tag/commit",
|
31
|
+
prompt="Current branch/tag/commit",
|
32
|
+
default_str="HEAD",
|
33
|
+
),
|
34
|
+
BoolInput(
|
35
|
+
name="created",
|
36
|
+
description="Include created files",
|
37
|
+
prompt="Include created files",
|
38
|
+
default_str="True",
|
39
|
+
),
|
40
|
+
BoolInput(
|
41
|
+
name="removed",
|
42
|
+
description="Include removed files",
|
43
|
+
prompt="Include removed files",
|
44
|
+
default_str="True",
|
45
|
+
),
|
46
|
+
BoolInput(
|
47
|
+
name="updated",
|
48
|
+
description="Include updated files",
|
49
|
+
prompt="Include updated files",
|
50
|
+
default_str="True",
|
51
|
+
),
|
52
|
+
],
|
53
|
+
description="🔍 Get modified files",
|
54
|
+
group=git_group,
|
55
|
+
alias="diff",
|
56
|
+
)
|
57
|
+
def get_git_diff(ctx: AnyContext):
|
58
|
+
diff = get_diff(ctx.input.source, ctx.input.current)
|
59
|
+
result = []
|
60
|
+
decorated = []
|
61
|
+
if ctx.input.created and diff.created:
|
62
|
+
decorated += [stylize_green(f"++ {name}") for name in diff.created]
|
63
|
+
result += diff.created
|
64
|
+
if ctx.input.updated and diff.updated:
|
65
|
+
decorated += [stylize_yellow(f"+- {name}") for name in diff.updated]
|
66
|
+
result += diff.updated
|
67
|
+
if ctx.input.removed and diff.removed:
|
68
|
+
decorated += [stylize_red(f"-- {name}") for name in diff.removed]
|
69
|
+
result += diff.removed
|
70
|
+
if len(decorated) > 0:
|
71
|
+
decorated = [""] + decorated + [""]
|
72
|
+
ctx.print(
|
73
|
+
"\n" + "\n".join((f" {decorated_line}" for decorated_line in decorated))
|
74
|
+
)
|
75
|
+
return "\n".join(result)
|
76
|
+
|
77
|
+
|
78
|
+
@make_task(
|
79
|
+
name="prune-local-git-branches",
|
80
|
+
description="🧹 Prune local branches",
|
81
|
+
group=git_branch_group,
|
82
|
+
alias="prune",
|
83
|
+
)
|
84
|
+
def prune_local_branches(ctx: AnyContext):
|
85
|
+
branches = get_branches()
|
86
|
+
current_branch = get_current_branch()
|
87
|
+
for branch in branches:
|
88
|
+
if branch == current_branch or branch == "main" or branch == "master":
|
89
|
+
continue
|
90
|
+
ctx.print(stylize_yellow(f"Removing local branch: {branch}"))
|
91
|
+
try:
|
92
|
+
delete_branch(branch)
|
93
|
+
except Exception as e:
|
94
|
+
ctx.log_error(e)
|
95
|
+
|
96
|
+
|
97
|
+
@make_task(
|
98
|
+
name="git-commit",
|
99
|
+
input=StrInput(
|
100
|
+
name="message",
|
101
|
+
description="Commit message",
|
102
|
+
prompt="Commit message",
|
103
|
+
default_str="Add feature/fix bug",
|
104
|
+
),
|
105
|
+
description="📝 Commit changes",
|
106
|
+
group=git_group,
|
107
|
+
alias="commit",
|
108
|
+
)
|
109
|
+
def git_commit(ctx: AnyContext):
|
110
|
+
ctx.print("Add changes to staging")
|
111
|
+
add()
|
112
|
+
ctx.print("Commit changes")
|
113
|
+
try:
|
114
|
+
commit(ctx.input.message)
|
115
|
+
except Exception as e:
|
116
|
+
ctx.log_error(e)
|
117
|
+
|
118
|
+
|
119
|
+
@make_task(
|
120
|
+
name="git-pull",
|
121
|
+
description="📥 Pull changes from remote repository",
|
122
|
+
input=StrInput(
|
123
|
+
name="remote",
|
124
|
+
description="Remote name",
|
125
|
+
prompt="Remote name",
|
126
|
+
default_str="origin",
|
127
|
+
),
|
128
|
+
upstream=git_commit,
|
129
|
+
group=git_group,
|
130
|
+
alias="pull",
|
131
|
+
)
|
132
|
+
def git_pull(ctx: AnyContext):
|
133
|
+
remote = ctx.input.remote
|
134
|
+
current_branch = get_current_branch()
|
135
|
+
ctx.print(f"Pulling from {remote}/{current_branch}")
|
136
|
+
pull(remote, current_branch)
|
137
|
+
|
138
|
+
|
139
|
+
@make_task(
|
140
|
+
name="git-push",
|
141
|
+
description="📤 Push changes to remote repository",
|
142
|
+
input=StrInput(
|
143
|
+
name="remote",
|
144
|
+
description="Remote name",
|
145
|
+
prompt="Remote name",
|
146
|
+
default_str="origin",
|
147
|
+
),
|
148
|
+
upstream=git_commit,
|
149
|
+
group=git_group,
|
150
|
+
alias="push",
|
151
|
+
)
|
152
|
+
def git_push(ctx: AnyContext):
|
153
|
+
remote = ctx.input.remote
|
154
|
+
current_branch = get_current_branch()
|
155
|
+
ctx.print(f"Pushing to {remote}/{current_branch}")
|
156
|
+
push(remote, current_branch)
|
@@ -0,0 +1,88 @@
|
|
1
|
+
from zrb.builtin.git import git_commit
|
2
|
+
from zrb.builtin.group import git_subtree_group
|
3
|
+
from zrb.context.any_context import AnyContext
|
4
|
+
from zrb.input.str_input import StrInput
|
5
|
+
from zrb.task.make_task import make_task
|
6
|
+
from zrb.util.git_subtree import add_subtree, load_config, pull_subtree, push_subtree
|
7
|
+
|
8
|
+
|
9
|
+
@make_task(
|
10
|
+
name="git-add-subtree",
|
11
|
+
input=[
|
12
|
+
StrInput(
|
13
|
+
name="name", description="Subtree config name", prompt="Subtree config name"
|
14
|
+
),
|
15
|
+
StrInput(
|
16
|
+
name="repo-url", description="Subtree repo URL", prompt="Subtree repo URL"
|
17
|
+
),
|
18
|
+
StrInput(
|
19
|
+
name="repo-branch",
|
20
|
+
description="Subtree repo branch",
|
21
|
+
prompt="Subtree repo branch",
|
22
|
+
),
|
23
|
+
StrInput(
|
24
|
+
name="repo-prefix",
|
25
|
+
description="Subtree repo prefix",
|
26
|
+
prompt="Subtree repo prefix",
|
27
|
+
),
|
28
|
+
],
|
29
|
+
description="➕ Add subtree",
|
30
|
+
upstream=git_commit,
|
31
|
+
group=git_subtree_group,
|
32
|
+
alias="add",
|
33
|
+
)
|
34
|
+
def git_add_subtree(ctx: AnyContext):
|
35
|
+
add_subtree(
|
36
|
+
name=ctx.input.name,
|
37
|
+
repo_url=ctx.input["repo-url"],
|
38
|
+
branch=ctx.input["repo-branch"],
|
39
|
+
prefix=ctx.input["repo-prefix"],
|
40
|
+
)
|
41
|
+
|
42
|
+
|
43
|
+
@make_task(
|
44
|
+
name="git-pull-subtree",
|
45
|
+
description="📥 Pull subtree",
|
46
|
+
upstream=git_commit,
|
47
|
+
group=git_subtree_group,
|
48
|
+
alias="pull",
|
49
|
+
)
|
50
|
+
def git_pull_subtree(ctx: AnyContext):
|
51
|
+
config = load_config()
|
52
|
+
if not config.data:
|
53
|
+
raise ValueError("No subtree config found")
|
54
|
+
first_err: Exception | None = None
|
55
|
+
for name, detail in config.data.items():
|
56
|
+
try:
|
57
|
+
ctx.print(f"Pull from subtree {name}")
|
58
|
+
pull_subtree(detail.prefix, detail.repo_url, detail.branch)
|
59
|
+
except Exception as e:
|
60
|
+
if first_err is None:
|
61
|
+
first_err = e
|
62
|
+
ctx.log_error(e)
|
63
|
+
if first_err is not None:
|
64
|
+
raise first_err
|
65
|
+
|
66
|
+
|
67
|
+
@make_task(
|
68
|
+
name="git-push-subtree",
|
69
|
+
description="📤 Push subtree",
|
70
|
+
upstream=git_commit,
|
71
|
+
group=git_subtree_group,
|
72
|
+
alias="push",
|
73
|
+
)
|
74
|
+
def git_push_subtree(ctx: AnyContext):
|
75
|
+
config = load_config()
|
76
|
+
if not config.data:
|
77
|
+
raise ValueError("No subtree config found")
|
78
|
+
first_err: Exception | None = None
|
79
|
+
for name, detail in config.data.items():
|
80
|
+
try:
|
81
|
+
ctx.print(f"Push to subtree {name}")
|
82
|
+
push_subtree(detail.prefix, detail.repo_url, detail.branch)
|
83
|
+
except Exception as e:
|
84
|
+
if first_err is None:
|
85
|
+
first_err = e
|
86
|
+
ctx.log_error(e)
|
87
|
+
if first_err is not None:
|
88
|
+
raise first_err
|
zrb/builtin/group.py
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
from zrb.group.group import Group
|
2
|
+
from zrb.runner.cli import cli
|
3
|
+
|
4
|
+
base64_group = cli.add_group(Group(name="base64", description="📄 Base64 operations"))
|
5
|
+
git_group = cli.add_group(Group(name="git", description="🌱 Git related commands"))
|
6
|
+
git_branch_group = git_group.add_group(
|
7
|
+
Group(name="branch", description="🌿 Git branch related commands")
|
8
|
+
)
|
9
|
+
git_subtree_group = git_group.add_group(
|
10
|
+
Group(name="subtree", description="🌳 Git subtree related commands")
|
11
|
+
)
|
12
|
+
llm_group = cli.add_group(Group(name="llm", description="🤖 LLM operations"))
|
13
|
+
md5_group = cli.add_group(Group(name="md5", description="🔢 Md5 operations"))
|
14
|
+
python_group = cli.add_group(
|
15
|
+
Group(name="python", description="🐍 Python related commands")
|
16
|
+
)
|
17
|
+
todo_group = cli.add_group(Group(name="todo", description="✅ Todo management"))
|
18
|
+
|
19
|
+
shell_group = cli.add_group(
|
20
|
+
Group(name="shell", description="💬 Shell related commands")
|
21
|
+
)
|
22
|
+
shell_autocomplete_group: Group = shell_group.add_group(
|
23
|
+
Group(name="autocomplete", description="⌨️ Shell autocomplete related commands")
|
24
|
+
)
|
25
|
+
|
26
|
+
project_group = cli.add_group(
|
27
|
+
Group(name="project", description="📁 Project related commands")
|
28
|
+
)
|
29
|
+
add_to_project_group = project_group.add_group(
|
30
|
+
Group(name="add", description="➕ Add things to project")
|
31
|
+
)
|
32
|
+
add_fastapp_to_project_group = add_to_project_group.add_group(
|
33
|
+
Group(name="fastapp", description="🚀 Add Fastapp resources")
|
34
|
+
)
|
zrb/builtin/llm.py
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
from zrb.builtin.group import llm_group
|
2
|
+
from zrb.config import LLM_MODEL, LLM_SYSTEM_PROMPT
|
3
|
+
from zrb.input.str_input import StrInput
|
4
|
+
from zrb.input.text_input import TextInput
|
5
|
+
from zrb.task.llm_task import LLMTask
|
6
|
+
|
7
|
+
llm_chat = llm_group.add_task(
|
8
|
+
LLMTask(
|
9
|
+
name="llm-chat",
|
10
|
+
input=[
|
11
|
+
StrInput(
|
12
|
+
"model",
|
13
|
+
description="LLM Model",
|
14
|
+
prompt="LLM Model",
|
15
|
+
default_str=LLM_MODEL,
|
16
|
+
),
|
17
|
+
StrInput(
|
18
|
+
"system-prompt",
|
19
|
+
description="System prompt",
|
20
|
+
prompt="System prompt",
|
21
|
+
default_str=LLM_SYSTEM_PROMPT,
|
22
|
+
),
|
23
|
+
TextInput("message", description="User message", prompt="Your message"),
|
24
|
+
],
|
25
|
+
description="Chat with LLM",
|
26
|
+
model="{ctx.input.model}",
|
27
|
+
system_prompt="{ctx.input['system-prompt']}",
|
28
|
+
message="{ctx.input.message}",
|
29
|
+
),
|
30
|
+
alias="chat",
|
31
|
+
)
|
zrb/builtin/md5.py
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
import hashlib
|
2
|
+
|
3
|
+
from zrb.builtin.group import md5_group
|
4
|
+
from zrb.context.any_context import AnyContext
|
5
|
+
from zrb.input.str_input import StrInput
|
6
|
+
from zrb.task.make_task import make_task
|
7
|
+
|
8
|
+
|
9
|
+
@make_task(
|
10
|
+
name="hash-md5",
|
11
|
+
input=StrInput(name="text", description="Text", prompt="Text to encode"),
|
12
|
+
description="🧩 Hash text to md5",
|
13
|
+
group=md5_group,
|
14
|
+
alias="hash",
|
15
|
+
)
|
16
|
+
def hash_md5(ctx: AnyContext) -> str:
|
17
|
+
result = hashlib.md5(ctx.input.text.encode()).hexdigest()
|
18
|
+
ctx.print(result)
|
19
|
+
return result
|
20
|
+
|
21
|
+
|
22
|
+
@make_task(
|
23
|
+
name="sum-md5",
|
24
|
+
input=StrInput(name="file", description="File name", prompt="File name"),
|
25
|
+
description="➕ Get md5 checksum of a file",
|
26
|
+
group=md5_group,
|
27
|
+
alias="sum",
|
28
|
+
)
|
29
|
+
def sum_md5(ctx: AnyContext) -> str:
|
30
|
+
with open(ctx.input.file, mode="rb") as file:
|
31
|
+
content = file.read()
|
32
|
+
result = hashlib.md5(content).hexdigest()
|
33
|
+
ctx.print(result)
|
34
|
+
return result
|
File without changes
|
File without changes
|
@@ -0,0 +1,72 @@
|
|
1
|
+
import os
|
2
|
+
|
3
|
+
from zrb.builtin.group import add_to_project_group
|
4
|
+
from zrb.context.any_context import AnyContext
|
5
|
+
from zrb.input.str_input import StrInput
|
6
|
+
from zrb.task.make_task import make_task
|
7
|
+
from zrb.task.scaffolder import Scaffolder
|
8
|
+
from zrb.task.task import Task
|
9
|
+
from zrb.util.string.conversion import double_quote
|
10
|
+
from zrb.util.string.name import get_random_name
|
11
|
+
|
12
|
+
_DIR = os.path.dirname(__file__)
|
13
|
+
|
14
|
+
|
15
|
+
scaffold_fastapp = Scaffolder(
|
16
|
+
name="scaffold-fastapp",
|
17
|
+
input=[
|
18
|
+
StrInput(
|
19
|
+
name="project-dir",
|
20
|
+
description="Project directory",
|
21
|
+
prompt="Project directory",
|
22
|
+
default_str=lambda _: os.getcwd(),
|
23
|
+
),
|
24
|
+
StrInput(
|
25
|
+
name="app-name",
|
26
|
+
description="App name",
|
27
|
+
prompt="App name",
|
28
|
+
default_str=lambda _: get_random_name(separator="_"),
|
29
|
+
),
|
30
|
+
],
|
31
|
+
source_path=os.path.join(_DIR, "fastapp_template"),
|
32
|
+
auto_render_source_path=False,
|
33
|
+
destination_path=lambda ctx: os.path.join(
|
34
|
+
ctx.input["project-dir"], ctx.input["app-name"]
|
35
|
+
),
|
36
|
+
transform_content={
|
37
|
+
"fastapp_template": "{to_snake_case(ctx.input['app-name'])}",
|
38
|
+
"App Name": "{ctx.input['app-name'].title()}",
|
39
|
+
"App name": "{ctx.input['app-name'].capitalize()}",
|
40
|
+
"app-name": "{to_kebab_case(ctx.input['app-name'])}",
|
41
|
+
"app_name": "{to_snake_case(ctx.input['app-name'])}",
|
42
|
+
"APP_NAME": "{to_snake_case(ctx.input['app-name']).upper()}",
|
43
|
+
"secure-password": lambda _: get_random_name(),
|
44
|
+
},
|
45
|
+
retries=0,
|
46
|
+
)
|
47
|
+
|
48
|
+
|
49
|
+
@make_task(
|
50
|
+
name="register-fastapp-automation",
|
51
|
+
)
|
52
|
+
def register_fastapp_automation(ctx: AnyContext):
|
53
|
+
project_dir_path = ctx.input["project-dir"]
|
54
|
+
zrb_init_path = os.path.join(project_dir_path, "zrb_init.py")
|
55
|
+
app_dir_path = ctx.input["app-name"]
|
56
|
+
app_automation_file_part = ", ".join(
|
57
|
+
[double_quote(part) for part in [app_dir_path, "_zrb", "main.py"]]
|
58
|
+
)
|
59
|
+
with open(zrb_init_path, "+a") as f:
|
60
|
+
f.write(f"load_file(os.path.join(_DIR, {app_automation_file_part}))\n")
|
61
|
+
|
62
|
+
|
63
|
+
scaffold_fastapp >> register_fastapp_automation
|
64
|
+
|
65
|
+
add_fastapp_to_project = add_to_project_group.add_task(
|
66
|
+
Task(
|
67
|
+
name="add-fastapp",
|
68
|
+
description="🚀 Add FastApp to project",
|
69
|
+
),
|
70
|
+
alias="fastapp",
|
71
|
+
)
|
72
|
+
add_fastapp_to_project << [register_fastapp_automation]
|
File without changes
|