zrb 1.0.0a15__py3-none-any.whl → 1.0.0a18__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.
Files changed (151) hide show
  1. zrb/__main__.py +3 -0
  2. zrb/builtin/__init__.py +2 -2
  3. zrb/builtin/git.py +16 -8
  4. zrb/builtin/git_subtree.py +7 -2
  5. zrb/builtin/llm/tool/rag.py +2 -2
  6. zrb/builtin/project/add/fastapp/fastapp_input.py +16 -0
  7. zrb/builtin/project/add/fastapp/fastapp_task.py +78 -0
  8. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/.flake8 +3 -0
  9. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/column/create_column_task.py +14 -0
  10. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/add_entity_task.py +128 -0
  11. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/add_entity_util.py +213 -0
  12. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/template/any_client_method.py +27 -0
  13. zrb/builtin/project/add/{fastapp_template/_zrb/entity/module_template → fastapp/fastapp_template/my_app_name/_zrb/entity/template/app_template/module/my_module}/service/my_entity/my_entity_usecase.py +9 -10
  14. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/template/app_template/module/my_module/service/my_entity/repository/factory.py +13 -0
  15. zrb/builtin/project/add/{fastapp_template/_zrb/entity/module_template → fastapp/fastapp_template/my_app_name/_zrb/entity/template/app_template/module/my_module}/service/my_entity/repository/my_entity_db_repository.py +14 -9
  16. zrb/builtin/project/add/{fastapp_template/_zrb/entity/module_template → fastapp/fastapp_template/my_app_name/_zrb/entity/template/app_template/module/my_module}/service/my_entity/repository/my_entity_repository.py +6 -7
  17. zrb/builtin/project/add/{fastapp_template/_zrb/entity/schema.template.py → fastapp/fastapp_template/my_app_name/_zrb/entity/template/app_template/schema/my_entity.py} +8 -0
  18. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/format_task.py +17 -0
  19. zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/_zrb/input.py +1 -4
  20. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/add_module_task.py +85 -0
  21. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/add_module_util.py +154 -0
  22. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/client/any_client.py +7 -0
  23. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/client/api_client.py +6 -0
  24. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/client/direct_client.py +6 -0
  25. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/client/factory.py +9 -0
  26. zrb/builtin/project/add/{fastapp_template/_zrb/module/module_template → fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module}/migration/env.py +2 -4
  27. zrb/builtin/project/add/{fastapp_template/module/auth → fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module}/migration/script.py.mako +1 -0
  28. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/route.py +33 -0
  29. zrb/builtin/project/add/{fastapp_template/_zrb/main.py → fastapp/fastapp_template/my_app_name/_zrb/task.py} +12 -14
  30. zrb/builtin/project/add/{fastapp_template/_zrb/helper.py → fastapp/fastapp_template/my_app_name/_zrb/util.py} +1 -1
  31. zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/_zrb/venv_task.py +1 -1
  32. zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/common/app.py +2 -2
  33. zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/common/base_db_repository.py +1 -1
  34. zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/common/base_usecase.py +19 -6
  35. zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/common/db_engine.py +1 -1
  36. zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/config.py +1 -0
  37. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/main.py +7 -0
  38. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/migrate.py +3 -0
  39. zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/auth/client/any_client.py +10 -4
  40. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/client/api_client.py +7 -0
  41. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/client/direct_client.py +6 -0
  42. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/client/factory.py +9 -0
  43. zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/auth/migration/env.py +2 -4
  44. zrb/builtin/project/add/{fastapp_template/module/gateway → fastapp/fastapp_template/my_app_name/module/auth}/migration/script.py.mako +1 -0
  45. zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/auth/migration_metadata.py +1 -1
  46. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/route.py +37 -0
  47. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/user/repository/factory.py +13 -0
  48. zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/auth/service/user/repository/user_db_repository.py +13 -7
  49. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/user/repository/user_repository.py +42 -0
  50. zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/auth/service/user/user_usecase.py +13 -8
  51. zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/gateway/migration/env.py +2 -4
  52. zrb/builtin/project/add/{fastapp_template/_zrb/module/module_template → fastapp/fastapp_template/my_app_name/module/gateway}/migration/script.py.mako +1 -0
  53. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/route.py +43 -0
  54. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/subroute/auth.py +0 -0
  55. zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/requirements.txt +1 -1
  56. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/schema/__init__.py +0 -0
  57. zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/schema/permission.py +8 -0
  58. zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/schema/role.py +8 -0
  59. zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/schema/user.py +8 -0
  60. zrb/builtin/project/add/fastapp/fastapp_util.py +46 -0
  61. zrb/builtin/project/create/{create.py → project_task.py} +1 -1
  62. zrb/builtin/python.py +4 -1
  63. zrb/builtin/setup/asdf/asdf_helper.py +4 -8
  64. zrb/builtin/setup/tmux/tmux.py +7 -12
  65. zrb/builtin/todo.py +45 -29
  66. zrb/callback/callback.py +0 -1
  67. zrb/cmd/cmd_val.py +2 -2
  68. zrb/config.py +1 -0
  69. zrb/content_transformer/content_transformer.py +8 -7
  70. zrb/context/any_context.py +6 -6
  71. zrb/group/group.py +0 -1
  72. zrb/input/base_input.py +13 -1
  73. zrb/input/text_input.py +4 -4
  74. zrb/runner/cli.py +0 -1
  75. zrb/runner/web_app.py +5 -2
  76. zrb/runner/web_controller/group_info_ui/controller.py +6 -14
  77. zrb/runner/web_controller/home_page/controller.py +6 -14
  78. zrb/runner/web_controller/task_ui/controller.py +12 -19
  79. zrb/session_state_logger/any_session_state_logger.py +0 -1
  80. zrb/session_state_logger/file_session_state_logger.py +4 -8
  81. zrb/task/base_trigger.py +0 -1
  82. zrb/task/cmd_task.py +1 -1
  83. zrb/task/llm_task.py +3 -6
  84. zrb/task/make_task.py +0 -1
  85. zrb/task/scaffolder.py +18 -4
  86. zrb/task/scheduler.py +0 -1
  87. zrb/util/cmd/command.py +0 -1
  88. zrb/util/codemod/{add_code_to_class.py → append_code_to_class.py} +4 -4
  89. zrb/util/codemod/{add_code_to_function.py → append_code_to_function.py} +5 -3
  90. zrb/util/codemod/{add_code_to_method.py → append_code_to_method.py} +3 -3
  91. zrb/util/codemod/{add_key_to_dict.py → append_key_to_dict.py} +1 -1
  92. zrb/util/codemod/{add_param_to_function_call.py → append_param_to_function_call.py} +1 -1
  93. zrb/util/codemod/{add_code_to_module.py → prepend_code_to_module.py} +2 -2
  94. zrb/util/codemod/{add_parent_to_class.py → prepend_parent_to_class.py} +1 -1
  95. zrb/util/codemod/{add_property_to_class.py → prepend_property_to_class.py} +1 -1
  96. zrb/util/file.py +18 -0
  97. zrb/util/git_subtree.py +3 -4
  98. zrb/util/todo.py +105 -24
  99. zrb/xcom/xcom.py +0 -1
  100. {zrb-1.0.0a15.dist-info → zrb-1.0.0a18.dist-info}/METADATA +2 -2
  101. zrb-1.0.0a18.dist-info/RECORD +240 -0
  102. zrb/builtin/project/add/fastapp.py +0 -87
  103. zrb/builtin/project/add/fastapp_template/_zrb/column/create_column_task.py +0 -11
  104. zrb/builtin/project/add/fastapp_template/_zrb/entity/create_entity_task.py +0 -196
  105. zrb/builtin/project/add/fastapp_template/_zrb/entity/module_template/service/my_entity/repository/factory.py +0 -13
  106. zrb/builtin/project/add/fastapp_template/_zrb/module/create_module_task.py +0 -136
  107. zrb/builtin/project/add/fastapp_template/_zrb/module/module_template/client/any_client.py +0 -27
  108. zrb/builtin/project/add/fastapp_template/_zrb/module/module_template/client/api_client.py +0 -6
  109. zrb/builtin/project/add/fastapp_template/_zrb/module/module_template/client/direct_client.py +0 -6
  110. zrb/builtin/project/add/fastapp_template/_zrb/module/module_template/client/factory.py +0 -9
  111. zrb/builtin/project/add/fastapp_template/_zrb/module/module_template/route.py +0 -19
  112. zrb/builtin/project/add/fastapp_template/main.py +0 -7
  113. zrb/builtin/project/add/fastapp_template/migrate.py +0 -3
  114. zrb/builtin/project/add/fastapp_template/module/auth/client/api_client.py +0 -7
  115. zrb/builtin/project/add/fastapp_template/module/auth/client/direct_client.py +0 -6
  116. zrb/builtin/project/add/fastapp_template/module/auth/client/factory.py +0 -9
  117. zrb/builtin/project/add/fastapp_template/module/auth/migration/versions/3093c7336477_add_user_table.py +0 -37
  118. zrb/builtin/project/add/fastapp_template/module/auth/route.py +0 -22
  119. zrb/builtin/project/add/fastapp_template/module/auth/service/user/repository/factory.py +0 -13
  120. zrb/builtin/project/add/fastapp_template/module/auth/service/user/repository/user_repository.py +0 -34
  121. zrb/builtin/project/add/fastapp_template/module/gateway/route.py +0 -27
  122. zrb-1.0.0a15.dist-info/RECORD +0 -231
  123. /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/.gitignore +0 -0
  124. /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/README.md +0 -0
  125. /zrb/builtin/project/add/{__init__.py → fastapp/fastapp_template/my_app_name/__init__.py} +0 -0
  126. /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/_zrb/config.py +0 -0
  127. /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/_zrb/group.py +0 -0
  128. /zrb/builtin/project/add/{fastapp_template/__init__.py → fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/gateway/subroute/my_module.py} +0 -0
  129. /zrb/builtin/project/add/{fastapp_template/_zrb/module/module_template → fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module}/alembic.ini +0 -0
  130. /zrb/builtin/project/add/{fastapp_template/_zrb/module/module_template → fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module}/migration/README +0 -0
  131. /zrb/builtin/project/add/{fastapp_template/module/gateway → fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module}/migration/versions/.gitkeep +0 -0
  132. /zrb/builtin/project/add/{fastapp_template/_zrb/module/module_template → fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module}/migration_metadata.py +0 -0
  133. /zrb/builtin/project/add/{fastapp_template/_zrb/module/module_template → fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module}/service/__init__.py +0 -0
  134. /zrb/builtin/project/add/{fastapp_template/_zrb/module/run_module.template.py → fastapp/fastapp_template/my_app_name/_zrb/module/template/module_task_definition.py} +0 -0
  135. /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/common/__init__.py +0 -0
  136. /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/common/error.py +0 -0
  137. /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/common/schema.py +0 -0
  138. /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/__init__.py +0 -0
  139. /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/auth/alembic.ini +0 -0
  140. /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/auth/migration/README +0 -0
  141. /zrb/builtin/project/add/{fastapp_template/_zrb/module/module_template → fastapp/fastapp_template/my_app_name/module/auth}/migration/versions/3093c7336477_add_user_table.py +0 -0
  142. /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/auth/service/__init__.py +0 -0
  143. /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/auth/service/user/__init__.py +0 -0
  144. /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/auth/service/user/repository/__init__.py +0 -0
  145. /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/gateway/alembic.ini +0 -0
  146. /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/gateway/migration/README +0 -0
  147. /zrb/builtin/project/add/{fastapp_template/schema/__init__.py → fastapp/fastapp_template/my_app_name/module/gateway/migration/versions/.gitkeep} +0 -0
  148. /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/gateway/migration_metadata.py +0 -0
  149. /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/template.env +0 -0
  150. {zrb-1.0.0a15.dist-info → zrb-1.0.0a18.dist-info}/WHEEL +0 -0
  151. {zrb-1.0.0a15.dist-info → zrb-1.0.0a18.dist-info}/entry_points.txt +0 -0
zrb/__main__.py CHANGED
@@ -14,6 +14,9 @@ def serve_cli():
14
14
  for init_script in INIT_SCRIPTS:
15
15
  load_file(init_script, -1)
16
16
  cli.run(sys.argv[1:])
17
+ except RuntimeError as e:
18
+ if "Event loop is closed" not in f"{e}":
19
+ raise e
17
20
  except KeyboardInterrupt:
18
21
  print(stylize_warning("\nStopped"), file=sys.stderr)
19
22
  except NodeNotFoundError as e:
zrb/builtin/__init__.py CHANGED
@@ -9,8 +9,8 @@ from zrb.builtin.git import (
9
9
  from zrb.builtin.git_subtree import git_add_subtree, git_pull_subtree, git_push_subtree
10
10
  from zrb.builtin.llm.llm_chat import llm_chat
11
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
12
+ from zrb.builtin.project.add.fastapp.fastapp_task import add_fastapp_to_project
13
+ from zrb.builtin.project.create.project_task import create_project
14
14
  from zrb.builtin.python import format_python_code
15
15
  from zrb.builtin.setup.asdf.asdf import setup_asdf
16
16
  from zrb.builtin.setup.latex.ubuntu import setup_latex_on_ubuntu
zrb/builtin/git.py CHANGED
@@ -3,7 +3,7 @@ from zrb.context.any_context import AnyContext
3
3
  from zrb.input.bool_input import BoolInput
4
4
  from zrb.input.str_input import StrInput
5
5
  from zrb.task.make_task import make_task
6
- from zrb.util.cli.style import stylize_green, stylize_red, stylize_yellow
6
+ from zrb.util.cli.style import stylize_faint, stylize_green, stylize_red, stylize_yellow
7
7
  from zrb.util.git import (
8
8
  add,
9
9
  commit,
@@ -56,6 +56,7 @@ from zrb.util.git import (
56
56
  alias="diff",
57
57
  )
58
58
  async def get_git_diff(ctx: AnyContext):
59
+ ctx.print(stylize_faint("Get directory"))
59
60
  repo_dir = await get_repo_dir(log_method=ctx.print)
60
61
  diff = await get_diff(
61
62
  repo_dir, ctx.input.source, ctx.input.current, log_method=ctx.print
@@ -86,13 +87,16 @@ async def get_git_diff(ctx: AnyContext):
86
87
  alias="prune",
87
88
  )
88
89
  async def prune_local_branches(ctx: AnyContext):
90
+ ctx.print(stylize_faint("Get directory"))
89
91
  repo_dir = await get_repo_dir(log_method=ctx.print)
92
+ ctx.print(stylize_faint("Get existing branches"))
90
93
  branches = await get_branches(repo_dir, log_method=ctx.print)
94
+ ctx.print(stylize_faint("Get current branch"))
91
95
  current_branch = await get_current_branch(repo_dir, log_method=ctx.print)
92
96
  for branch in branches:
93
97
  if branch == current_branch or branch == "main" or branch == "master":
94
98
  continue
95
- ctx.print(stylize_yellow(f"Removing local branch: {branch}"))
99
+ ctx.print(stylize_faint(f"Removing local branch: {branch}"))
96
100
  try:
97
101
  await delete_branch(repo_dir, branch, log_method=ctx.print)
98
102
  except Exception as e:
@@ -112,10 +116,11 @@ async def prune_local_branches(ctx: AnyContext):
112
116
  alias="commit",
113
117
  )
114
118
  async def git_commit(ctx: AnyContext):
119
+ ctx.print(stylize_faint("Get directory"))
115
120
  repo_dir = await get_repo_dir(log_method=ctx.print)
116
- ctx.print("Add changes to staging")
121
+ ctx.print(stylize_faint("Add changes to staging"))
117
122
  await add(repo_dir, log_method=ctx.print)
118
- ctx.print("Commit changes")
123
+ ctx.print(stylize_faint("Commit changes"))
119
124
  await commit(repo_dir, ctx.input.message, log_method=ctx.print)
120
125
 
121
126
 
@@ -133,10 +138,12 @@ async def git_commit(ctx: AnyContext):
133
138
  alias="pull",
134
139
  )
135
140
  async def git_pull(ctx: AnyContext):
141
+ ctx.print(stylize_faint("Get directory"))
136
142
  repo_dir = await get_repo_dir(log_method=ctx.print)
137
- remote = ctx.input.remote
143
+ ctx.print(stylize_faint("Get current branch"))
138
144
  current_branch = await get_current_branch(repo_dir, log_method=ctx.print)
139
- ctx.print(f"Pulling from {remote}/{current_branch}")
145
+ remote = ctx.input.remote
146
+ ctx.print(stylize_faint(f"Pulling from {remote}/{current_branch}"))
140
147
  await pull(repo_dir, remote, current_branch, log_method=ctx.print)
141
148
 
142
149
 
@@ -155,7 +162,8 @@ async def git_pull(ctx: AnyContext):
155
162
  )
156
163
  async def git_push(ctx: AnyContext):
157
164
  repo_dir = await get_repo_dir(log_method=ctx.print)
158
- remote = ctx.input.remote
165
+ ctx.print(stylize_faint("Get current branch"))
159
166
  current_branch = await get_current_branch(repo_dir, log_method=ctx.print)
160
- ctx.print(f"Pushing to {remote}/{current_branch}")
167
+ remote = ctx.input.remote
168
+ ctx.print(stylize_faint(f"Pushing to {remote}/{current_branch}"))
161
169
  await push(repo_dir, remote, current_branch, log_method=ctx.print)
@@ -3,6 +3,7 @@ from zrb.builtin.group import git_subtree_group
3
3
  from zrb.context.any_context import AnyContext
4
4
  from zrb.input.str_input import StrInput
5
5
  from zrb.task.make_task import make_task
6
+ from zrb.util.cli.style import stylize_faint
6
7
  from zrb.util.git import get_repo_dir
7
8
  from zrb.util.git_subtree import add_subtree, load_config, pull_subtree, push_subtree
8
9
 
@@ -33,7 +34,9 @@ from zrb.util.git_subtree import add_subtree, load_config, pull_subtree, push_su
33
34
  alias="add",
34
35
  )
35
36
  async def git_add_subtree(ctx: AnyContext):
37
+ ctx.print(stylize_faint("Get directory"))
36
38
  repo_dir = await get_repo_dir(log_method=ctx.print)
39
+ ctx.print(stylize_faint("Add subtree"))
37
40
  await add_subtree(
38
41
  repo_dir=repo_dir,
39
42
  name=ctx.input.name,
@@ -52,6 +55,7 @@ async def git_add_subtree(ctx: AnyContext):
52
55
  alias="pull",
53
56
  )
54
57
  async def git_pull_subtree(ctx: AnyContext):
58
+ ctx.print(stylize_faint("Get directory"))
55
59
  repo_dir = await get_repo_dir(log_method=ctx.print)
56
60
  config = load_config(repo_dir)
57
61
  if not config.data:
@@ -59,7 +63,7 @@ async def git_pull_subtree(ctx: AnyContext):
59
63
  first_err: Exception | None = None
60
64
  for name, detail in config.data.items():
61
65
  try:
62
- ctx.print(f"Pull from subtree {name}")
66
+ ctx.print(stylize_faint(f"Pull from subtree {name}"))
63
67
  await pull_subtree(
64
68
  repo_dir=repo_dir,
65
69
  prefix=detail.prefix,
@@ -83,6 +87,7 @@ async def git_pull_subtree(ctx: AnyContext):
83
87
  alias="push",
84
88
  )
85
89
  async def git_push_subtree(ctx: AnyContext):
90
+ ctx.print(stylize_faint("Get directory"))
86
91
  repo_dir = await get_repo_dir(log_method=ctx.print)
87
92
  config = load_config(repo_dir)
88
93
  if not config.data:
@@ -90,7 +95,7 @@ async def git_push_subtree(ctx: AnyContext):
90
95
  first_err: Exception | None = None
91
96
  for name, detail in config.data.items():
92
97
  try:
93
- ctx.print(f"Push to subtree {name}")
98
+ ctx.print(stylize_faint(f"Push to subtree {name}"))
94
99
  await push_subtree(
95
100
  repo_dir=repo_dir,
96
101
  prefix=detail.prefix,
@@ -12,6 +12,7 @@ from zrb.config import (
12
12
  RAG_OVERLAP,
13
13
  )
14
14
  from zrb.util.cli.style import stylize_error, stylize_faint
15
+ from zrb.util.file import read_file
15
16
  from zrb.util.run import run_async
16
17
 
17
18
  Document = str | Callable[[], str]
@@ -137,8 +138,7 @@ def get_rag_documents(document_dir_path: str) -> Callable[[], list[Callable[[],
137
138
  def _get_text_reader(file_path: str):
138
139
  def read():
139
140
  print(stylize_faint(f"Start reading {file_path}"), file=sys.stderr)
140
- with open(file_path, "r", encoding="utf-8") as f:
141
- content = f.read()
141
+ content = read_file(file_path)
142
142
  print(stylize_faint(f"Complete reading {file_path}"), file=sys.stderr)
143
143
  return content
144
144
 
@@ -0,0 +1,16 @@
1
+ import os
2
+
3
+ from zrb.input.str_input import StrInput
4
+
5
+ project_dir_input = StrInput(
6
+ name="project-dir",
7
+ description="Project directory",
8
+ prompt="Project directory",
9
+ default_str=lambda _: os.getcwd(),
10
+ )
11
+
12
+ app_name_input = StrInput(
13
+ name="app",
14
+ description="App name",
15
+ prompt="App name",
16
+ )
@@ -0,0 +1,78 @@
1
+ import os
2
+
3
+ from zrb.builtin.group import add_to_project_group
4
+ from zrb.builtin.project.add.fastapp.fastapp_input import (
5
+ app_name_input,
6
+ project_dir_input,
7
+ )
8
+ from zrb.builtin.project.add.fastapp.fastapp_util import (
9
+ is_in_project_app_dir,
10
+ is_project_zrb_init_file,
11
+ update_project_zrb_init_file,
12
+ )
13
+ from zrb.content_transformer.content_transformer import ContentTransformer
14
+ from zrb.context.any_context import AnyContext
15
+ from zrb.task.make_task import make_task
16
+ from zrb.task.scaffolder import Scaffolder
17
+ from zrb.task.task import Task
18
+ from zrb.util.string.conversion import to_snake_case
19
+ from zrb.util.string.name import get_random_name
20
+
21
+
22
+ @make_task(
23
+ name="validate-create-fastapp",
24
+ input=[project_dir_input, app_name_input],
25
+ retries=0,
26
+ )
27
+ async def validate_create_fastapp(ctx: AnyContext):
28
+ project_dir = ctx.input.project_dir
29
+ if not os.path.isdir(project_dir):
30
+ raise ValueError(f"Project directory not exists: {project_dir}")
31
+ app_dir = os.path.join(project_dir, to_snake_case(ctx.input.app))
32
+ if os.path.exists(app_dir):
33
+ raise ValueError(f"Application directory already exists: {app_dir}")
34
+
35
+
36
+ scaffold_fastapp = Scaffolder(
37
+ name="scaffold-fastapp",
38
+ input=[
39
+ project_dir_input,
40
+ app_name_input,
41
+ ],
42
+ upstream=validate_create_fastapp,
43
+ source_path=os.path.join(os.path.dirname(__file__), "fastapp_template"),
44
+ render_source_path=False,
45
+ destination_path="{ctx.input.project_dir}",
46
+ transform_path={
47
+ "my_app_name": "{to_snake_case(ctx.input.app)}",
48
+ },
49
+ transform_content=[
50
+ # Common transformation (project_dir/app_dir/**/*)
51
+ ContentTransformer(
52
+ match=is_in_project_app_dir,
53
+ transform={
54
+ "My App Name": "{ctx.input.app.title()}",
55
+ "my-app-name": "{to_kebab_case(ctx.input.app)}",
56
+ "my_app_name": "{to_snake_case(ctx.input.app)}",
57
+ "MY_APP_NAME": "{to_snake_case(ctx.input.app).upper()}",
58
+ "my-secure-password": lambda _: get_random_name(),
59
+ },
60
+ ),
61
+ # Register fastapp's tasks to project's zrb_init (project_dir/zrb_init.py)
62
+ ContentTransformer(
63
+ match=is_project_zrb_init_file,
64
+ transform=update_project_zrb_init_file,
65
+ ),
66
+ ],
67
+ retries=0,
68
+ )
69
+
70
+ add_fastapp_to_project = add_to_project_group.add_task(
71
+ Task(
72
+ name="add-fastapp",
73
+ description="🚀 Add FastApp to project",
74
+ upstream=scaffold_fastapp,
75
+ retries=0,
76
+ ),
77
+ alias="fastapp",
78
+ )
@@ -0,0 +1,3 @@
1
+ [flake8]
2
+ max-line-length = 95
3
+ extend-ignore = E203, E704
@@ -0,0 +1,14 @@
1
+ from my_app_name._zrb.format_task import format_my_app_name_code
2
+ from my_app_name._zrb.group import app_create_group
3
+
4
+ from zrb import Task
5
+
6
+ add_my_app_name_column = app_create_group.add_task(
7
+ Task(
8
+ name="add-my-app-name-column",
9
+ description="📊 Create new column on an entity",
10
+ successor=format_my_app_name_code,
11
+ retries=0,
12
+ ),
13
+ alias="column",
14
+ )
@@ -0,0 +1,128 @@
1
+ import os
2
+
3
+ from my_app_name._zrb.config import APP_DIR
4
+ from my_app_name._zrb.entity.add_entity_util import (
5
+ is_in_app_schema_dir,
6
+ is_in_module_entity_dir,
7
+ is_module_any_client_file,
8
+ is_module_api_client_file,
9
+ is_module_direct_client_file,
10
+ is_module_migration_metadata_file,
11
+ is_module_route_file,
12
+ update_any_client,
13
+ update_api_client,
14
+ update_direct_client,
15
+ update_migration_metadata,
16
+ update_route,
17
+ )
18
+ from my_app_name._zrb.format_task import format_my_app_name_code
19
+ from my_app_name._zrb.group import app_create_group
20
+ from my_app_name._zrb.input import (
21
+ existing_module_input,
22
+ new_entity_column_input,
23
+ new_entity_input,
24
+ plural_entity_input,
25
+ )
26
+ from my_app_name._zrb.util import get_existing_module_names, get_existing_schema_names
27
+
28
+ from zrb import AnyContext, ContentTransformer, Scaffolder, Task, make_task
29
+ from zrb.util.string.conversion import to_snake_case
30
+
31
+
32
+ @make_task(
33
+ name="validate-create-my-app-name-entity",
34
+ input=[
35
+ existing_module_input,
36
+ new_entity_input,
37
+ plural_entity_input,
38
+ new_entity_column_input,
39
+ ],
40
+ retries=0,
41
+ )
42
+ async def validate_create_my_app_name_entity(ctx: AnyContext):
43
+ module_name = to_snake_case(ctx.input.module)
44
+ if module_name not in get_existing_module_names():
45
+ raise ValueError(f"Module not exist: {module_name}")
46
+ schema_name = to_snake_case(ctx.input.entity)
47
+ if schema_name in get_existing_schema_names():
48
+ raise ValueError(f"Schema already exists: {schema_name}")
49
+
50
+
51
+ scaffold_my_app_name_entity = Scaffolder(
52
+ name="scaffold-my-app-name-entity",
53
+ input=[
54
+ existing_module_input,
55
+ new_entity_input,
56
+ plural_entity_input,
57
+ new_entity_column_input,
58
+ ],
59
+ source_path=os.path.join(os.path.dirname(__file__), "template", "app_template"),
60
+ render_source_path=False,
61
+ destination_path=APP_DIR,
62
+ transform_path={
63
+ "my_module": "{to_snake_case(ctx.input.module)}",
64
+ "my_entity": "{to_snake_case(ctx.input.entity)}",
65
+ },
66
+ transform_content=[
67
+ # Schema tranformation (my_app_name/schema/snake_entity_name)
68
+ ContentTransformer(
69
+ match=is_in_app_schema_dir,
70
+ transform={
71
+ "MyEntity": "{to_pascal_case(ctx.input.entity)}",
72
+ "my_column": "{to_snake_case(ctx.input.column)}",
73
+ },
74
+ ),
75
+ # Common module's entity transformation
76
+ # (my_app_name/module/snake_module_name/service/snake_entity_name)
77
+ ContentTransformer(
78
+ match=is_in_module_entity_dir,
79
+ transform={
80
+ "my_module": "{to_snake_case(ctx.input.module)}",
81
+ "MyEntity": "{to_pascal_case(ctx.input.entity)}",
82
+ "my_entity": "{to_snake_case(ctx.input.entity)}",
83
+ "my_entities": "{to_snake_case(ctx.input.plural)}",
84
+ "my-entities": "{to_kebab_case(ctx.input.plural)}",
85
+ },
86
+ ),
87
+ # Add entity to migration metadata
88
+ # (my_app_name/module/snake_module_name/migration_metadata.py)
89
+ ContentTransformer(
90
+ match=is_module_migration_metadata_file,
91
+ transform=update_migration_metadata,
92
+ ),
93
+ # Update API Client (my_app_name/module/snake_module_name/client/api_client.py)
94
+ ContentTransformer(
95
+ match=is_module_api_client_file,
96
+ transform=update_api_client,
97
+ ),
98
+ # Update Direct Client (my_app_name/module/snake_module_name/client/direct_client.py)
99
+ ContentTransformer(
100
+ match=is_module_direct_client_file,
101
+ transform=update_direct_client,
102
+ ),
103
+ # Update Any Client (my_app_name/module/snake_module_name/client/any_client.py)
104
+ ContentTransformer(
105
+ match=is_module_any_client_file,
106
+ transform=update_any_client,
107
+ ),
108
+ # Update module route (my_app_name/module/route.py)
109
+ ContentTransformer(
110
+ match=is_module_route_file,
111
+ transform=update_route,
112
+ ),
113
+ # TODO: Register gateway route
114
+ ],
115
+ retries=0,
116
+ upstream=validate_create_my_app_name_entity,
117
+ )
118
+
119
+ add_my_app_name_entity = app_create_group.add_task(
120
+ Task(
121
+ name="add-my-app-name-entity",
122
+ description="🏗️ Create new entity on a module",
123
+ upstream=scaffold_my_app_name_entity,
124
+ successor=format_my_app_name_code,
125
+ retries=0,
126
+ ),
127
+ alias="entity",
128
+ )
@@ -0,0 +1,213 @@
1
+ import os
2
+
3
+ from my_app_name._zrb.config import APP_DIR
4
+
5
+ from zrb.context.any_context import AnyContext
6
+ from zrb.util.codemod.append_code_to_class import append_code_to_class
7
+ from zrb.util.codemod.append_code_to_function import append_code_to_function
8
+ from zrb.util.codemod.prepend_code_to_module import prepend_code_to_module
9
+ from zrb.util.codemod.prepend_parent_to_class import prepend_parent_class
10
+ from zrb.util.file import read_file, write_file
11
+ from zrb.util.string.conversion import to_pascal_case, to_snake_case
12
+
13
+
14
+ def is_in_app_schema_dir(ctx: AnyContext, file_path: str) -> bool:
15
+ return file_path.startswith(
16
+ os.path.join(APP_DIR, "schema", to_snake_case(ctx.input.entity))
17
+ )
18
+
19
+
20
+ def is_in_module_entity_dir(ctx: AnyContext, file_path: str) -> bool:
21
+ return file_path.startswith(
22
+ os.path.join(
23
+ APP_DIR,
24
+ "module",
25
+ to_snake_case(ctx.input.module),
26
+ "service",
27
+ to_snake_case(ctx.input.entity),
28
+ )
29
+ )
30
+
31
+
32
+ def is_module_route_file(ctx: AnyContext, file_path: str) -> bool:
33
+ module_route_file = os.path.join(
34
+ APP_DIR,
35
+ "module",
36
+ to_snake_case(ctx.input.module),
37
+ "route.py",
38
+ )
39
+ return file_path == module_route_file
40
+
41
+
42
+ def is_module_migration_metadata_file(ctx: AnyContext, file_path: str) -> bool:
43
+ module_migration_metadata_file = os.path.join(
44
+ APP_DIR,
45
+ "module",
46
+ to_snake_case(ctx.input.module),
47
+ "migration_metadata.py",
48
+ )
49
+ return file_path == module_migration_metadata_file
50
+
51
+
52
+ def is_module_any_client_file(ctx: AnyContext, file_path: str) -> bool:
53
+ module_any_client_file = os.path.join(
54
+ APP_DIR,
55
+ "module",
56
+ to_snake_case(ctx.input.module),
57
+ "client",
58
+ "any_client.py",
59
+ )
60
+ return file_path == module_any_client_file
61
+
62
+
63
+ def is_module_api_client_file(ctx: AnyContext, file_path: str) -> bool:
64
+ module_api_client_file = os.path.join(
65
+ APP_DIR,
66
+ "module",
67
+ to_snake_case(ctx.input.module),
68
+ "client",
69
+ "api_client.py",
70
+ )
71
+ return file_path == module_api_client_file
72
+
73
+
74
+ def is_module_direct_client_file(ctx: AnyContext, file_path: str) -> bool:
75
+ module_direct_client_file = os.path.join(
76
+ APP_DIR,
77
+ "module",
78
+ to_snake_case(ctx.input.module),
79
+ "client",
80
+ "direct_client.py",
81
+ )
82
+ return file_path == module_direct_client_file
83
+
84
+
85
+ def update_migration_metadata(ctx: AnyContext, migration_metadata_file_path: str):
86
+ app_name = os.path.basename(APP_DIR)
87
+ existing_migration_metadata_code = read_file(migration_metadata_file_path)
88
+ write_file(
89
+ file_path=migration_metadata_file_path,
90
+ content=[
91
+ _get_import_schema_code(
92
+ existing_migration_metadata_code, app_name, ctx.input.entity
93
+ ),
94
+ existing_migration_metadata_code.strip(),
95
+ _get_entity_metadata_assignment_code(
96
+ existing_migration_metadata_code, ctx.input.entity
97
+ ),
98
+ ],
99
+ )
100
+
101
+
102
+ def _get_import_schema_code(
103
+ existing_code: str, app_name: str, entity_name: str
104
+ ) -> str | None:
105
+ snake_entity_name = to_snake_case(entity_name)
106
+ pascal_entity_name = to_pascal_case(entity_name)
107
+ import_module_path = f"{app_name}.schema.{snake_entity_name}"
108
+ import_schema_code = f"from {import_module_path} import {pascal_entity_name}"
109
+ if import_schema_code in existing_code:
110
+ return None
111
+ return import_schema_code
112
+
113
+
114
+ def _get_entity_metadata_assignment_code(
115
+ existing_code: str, entity_name: str
116
+ ) -> str | None:
117
+ pascal_entity_name = to_pascal_case(entity_name)
118
+ entity_metadata_assignment_code = "\n".join(
119
+ [
120
+ f"{pascal_entity_name}.metadata = metadata",
121
+ f"{pascal_entity_name}.__table__.tometadata(metadata)",
122
+ ]
123
+ )
124
+ if entity_metadata_assignment_code in existing_code:
125
+ return None
126
+ return entity_metadata_assignment_code
127
+
128
+
129
+ def update_any_client(ctx: AnyContext, any_client_file_path: str):
130
+ existing_any_client_code = read_file(any_client_file_path)
131
+ app_name = os.path.basename(APP_DIR)
132
+ snake_entity_name = to_snake_case(ctx.input.entity)
133
+ snake_plural_entity_name = to_snake_case(ctx.input.plural)
134
+ pascal_entity_name = to_pascal_case(ctx.input.entity)
135
+ any_client_method = read_file(
136
+ file_path=os.path.join(
137
+ os.path.dirname(__file__), "template", "any_client_method.py"
138
+ ),
139
+ replace_map={
140
+ "my_entity": snake_entity_name,
141
+ "my_entities": snake_plural_entity_name,
142
+ "MyEntity": pascal_entity_name,
143
+ },
144
+ )
145
+ new_code = append_code_to_class(
146
+ existing_any_client_code, "AnyClient", any_client_method
147
+ )
148
+ write_file(
149
+ file_path=any_client_file_path,
150
+ content=[
151
+ f"from {app_name}.schema.{snake_entity_name}.{snake_entity_name} import (",
152
+ f" {pascal_entity_name}CreateWithAudit, {pascal_entity_name}Response, {pascal_entity_name}UpdateWithAudit", # noqa
153
+ ")",
154
+ new_code.strip(),
155
+ ],
156
+ )
157
+
158
+
159
+ def update_api_client(ctx: AnyContext, api_client_file_path: str):
160
+ existing_api_client_code = read_file(api_client_file_path)
161
+ upper_snake_module_name = to_snake_case(ctx.input.module).upper()
162
+ app_name = os.path.basename(APP_DIR)
163
+ snake_entity_name = to_snake_case(ctx.input.entity)
164
+ snake_module_name = to_snake_case(ctx.input.module)
165
+ write_file(
166
+ file_path=api_client_file_path,
167
+ content=[
168
+ f"from {app_name}.module.{snake_module_name}.service.{snake_entity_name}.{snake_entity_name}_usecase import {snake_entity_name}_usecase", # noqa
169
+ prepend_code_to_module(
170
+ prepend_parent_class(
171
+ existing_api_client_code, "APIClient", "user_api_client"
172
+ ),
173
+ f"user_api_client = user_usecase.as_api_client(base_url=APP_{upper_snake_module_name}_BASE_URL)", # noqa
174
+ ),
175
+ ],
176
+ )
177
+
178
+
179
+ def update_direct_client(ctx: AnyContext, direct_client_file_path: str):
180
+ existing_direct_client_code = read_file(direct_client_file_path)
181
+ app_name = os.path.basename(APP_DIR)
182
+ snake_entity_name = to_snake_case(ctx.input.entity)
183
+ snake_module_name = to_snake_case(ctx.input.module)
184
+ write_file(
185
+ file_path=direct_client_file_path,
186
+ content=[
187
+ f"from {app_name}.module.{snake_module_name}.service.{snake_entity_name}.{snake_entity_name}_usecase import {snake_entity_name}_usecase", # noqa
188
+ prepend_code_to_module(
189
+ prepend_parent_class(
190
+ existing_direct_client_code, "DirectClient", "user_direct_client"
191
+ ),
192
+ "user_direct_client = user_usecase.as_direct_client()",
193
+ ).strip(),
194
+ ],
195
+ )
196
+
197
+
198
+ def update_route(ctx: AnyContext, route_file_path: str):
199
+ existing_route_code = read_file(route_file_path)
200
+ entity_name = to_snake_case(ctx.input.entity)
201
+ app_name = os.path.basename(APP_DIR)
202
+ module_name = to_snake_case(ctx.input.module)
203
+ write_file(
204
+ file_path=route_file_path,
205
+ content=[
206
+ f"from {app_name}.module.{module_name}.service.{entity_name}.{entity_name}_usecase import {entity_name}_usecase", # noqa
207
+ append_code_to_function(
208
+ existing_route_code,
209
+ "serve_route",
210
+ f"{entity_name}_usecase.serve_route(app)",
211
+ ),
212
+ ],
213
+ )
@@ -0,0 +1,27 @@
1
+ @abstractmethod
2
+ async def get_my_entity_by_id(self, my_entity_id: str) -> MyEntityResponse:
3
+ pass
4
+
5
+
6
+ @abstractmethod
7
+ async def get_all_my_entities(self) -> list[MyEntityResponse]:
8
+ pass
9
+
10
+
11
+ @abstractmethod
12
+ async def create_my_entity(
13
+ self, data: MyEntityCreateWithAudit | list[MyEntityCreateWithAudit]
14
+ ) -> MyEntityResponse | list[MyEntityResponse]:
15
+ pass
16
+
17
+
18
+ @abstractmethod
19
+ async def update_my_entity(
20
+ self, my_entity_id: str, data: MyEntityUpdateWithAudit
21
+ ) -> MyEntityResponse:
22
+ pass
23
+
24
+
25
+ @abstractmethod
26
+ async def delete_my_entity(self, my_entity_id: str) -> MyEntityResponse:
27
+ pass