zrb 1.0.0a17__py3-none-any.whl → 1.0.0a19__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 (144) hide show
  1. zrb/__init__.py +2 -0
  2. zrb/builtin/project/add/fastapp/fastapp_task.py +25 -39
  3. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/.flake8 +3 -0
  4. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/column/create_column_task.py +14 -0
  5. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/add_entity_task.py +128 -0
  6. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/add_entity_util.py +213 -0
  7. zrb/builtin/project/add/fastapp/fastapp_template/{_zrb/entity/any_client_method.template.py → my_app_name/_zrb/entity/template/any_client_method.py} +1 -1
  8. zrb/builtin/project/add/fastapp/fastapp_template/{_zrb/entity/module_template → my_app_name/_zrb/entity/template/app_template/module/my_module}/service/my_entity/my_entity_usecase.py +4 -5
  9. 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
  10. zrb/builtin/project/add/fastapp/fastapp_template/{_zrb/entity/module_template → my_app_name/_zrb/entity/template/app_template/module/my_module}/service/my_entity/repository/my_entity_db_repository.py +4 -4
  11. zrb/builtin/project/add/fastapp/fastapp_template/{_zrb/entity/module_template → my_app_name/_zrb/entity/template/app_template/module/my_module}/service/my_entity/repository/my_entity_repository.py +1 -2
  12. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/format_task.py +17 -0
  13. zrb/builtin/project/add/fastapp/fastapp_template/{_zrb → my_app_name/_zrb}/input.py +1 -4
  14. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/add_module_task.py +85 -0
  15. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/add_module_util.py +154 -0
  16. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/client/api_client.py +6 -0
  17. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/client/direct_client.py +6 -0
  18. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/client/factory.py +9 -0
  19. zrb/builtin/project/add/fastapp/fastapp_template/{_zrb/module/template/module_template → my_app_name/_zrb/module/template/app_template/module/my_module}/migration/env.py +2 -4
  20. zrb/builtin/project/add/fastapp/fastapp_template/{_zrb/module/template/module_template → my_app_name/_zrb/module/template/app_template/module/my_module}/migration/script.py.mako +1 -0
  21. zrb/builtin/project/add/fastapp/fastapp_template/{_zrb/module/template/module_template → my_app_name/_zrb/module/template/app_template/module/my_module}/route.py +3 -3
  22. zrb/builtin/project/add/fastapp/fastapp_template/{_zrb → my_app_name/_zrb}/task.py +12 -14
  23. zrb/builtin/project/add/fastapp/fastapp_template/{_zrb → my_app_name/_zrb}/util.py +1 -1
  24. zrb/builtin/project/add/fastapp/fastapp_template/{_zrb → my_app_name/_zrb}/venv_task.py +1 -1
  25. zrb/builtin/project/add/fastapp/fastapp_template/{common → my_app_name/common}/app.py +2 -2
  26. zrb/builtin/project/add/fastapp/fastapp_template/{common → my_app_name/common}/base_db_repository.py +1 -1
  27. zrb/builtin/project/add/fastapp/fastapp_template/{common → my_app_name/common}/db_engine.py +1 -1
  28. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/main.py +7 -0
  29. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/migrate.py +3 -0
  30. zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/auth/client/any_client.py +1 -1
  31. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/client/api_client.py +7 -0
  32. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/client/direct_client.py +6 -0
  33. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/client/factory.py +9 -0
  34. zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/auth/migration/env.py +2 -4
  35. zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/auth/migration/script.py.mako +1 -0
  36. zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/auth/migration_metadata.py +1 -1
  37. zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/auth/route.py +4 -4
  38. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/user/repository/factory.py +13 -0
  39. zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/auth/service/user/repository/user_db_repository.py +4 -4
  40. zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/auth/service/user/repository/user_repository.py +1 -2
  41. zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/auth/service/user/user_usecase.py +4 -5
  42. zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/gateway/migration/env.py +2 -4
  43. zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/gateway/migration/script.py.mako +1 -0
  44. zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/gateway/route.py +5 -5
  45. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/subroute/auth.py +0 -0
  46. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/schema/__init__.py +0 -0
  47. zrb/builtin/project/add/fastapp/fastapp_util.py +29 -5
  48. zrb/builtin/python.py +4 -1
  49. zrb/builtin/todo.py +35 -14
  50. zrb/callback/callback.py +0 -1
  51. zrb/config.py +1 -0
  52. zrb/content_transformer/content_transformer.py +5 -3
  53. zrb/context/any_context.py +6 -6
  54. zrb/group/group.py +0 -1
  55. zrb/input/any_input.py +4 -0
  56. zrb/input/base_input.py +4 -4
  57. zrb/input/bool_input.py +1 -1
  58. zrb/input/float_input.py +2 -2
  59. zrb/input/int_input.py +1 -1
  60. zrb/input/option_input.py +2 -2
  61. zrb/input/password_input.py +2 -2
  62. zrb/input/text_input.py +2 -2
  63. zrb/runner/cli.py +2 -31
  64. zrb/runner/common_util.py +31 -0
  65. zrb/runner/web_app.py +25 -6
  66. zrb/runner/web_controller/static/pico.min.css +1 -1
  67. zrb/runner/web_controller/static/task-ui/common-util.js +63 -0
  68. zrb/runner/web_controller/static/task-ui/current-session.js +164 -0
  69. zrb/runner/web_controller/static/task-ui/event.js +120 -0
  70. zrb/runner/web_controller/static/task-ui/past-session.js +138 -0
  71. zrb/runner/web_controller/task_ui/controller.py +20 -19
  72. zrb/runner/web_controller/task_ui/view.html +12 -15
  73. zrb/session_state_logger/any_session_state_logger.py +0 -1
  74. zrb/session_state_logger/file_session_state_logger.py +0 -1
  75. zrb/task/base_trigger.py +0 -1
  76. zrb/task/llm_task.py +0 -1
  77. zrb/task/make_task.py +0 -1
  78. zrb/task/scaffolder.py +6 -4
  79. zrb/task/scheduler.py +0 -1
  80. zrb/util/cmd/command.py +0 -1
  81. zrb/util/codemod/append_code_to_class.py +4 -4
  82. zrb/util/codemod/append_code_to_function.py +2 -2
  83. zrb/util/codemod/append_code_to_method.py +2 -2
  84. zrb/util/codemod/prepend_code_to_module.py +2 -2
  85. zrb/util/file.py +1 -1
  86. zrb/util/todo.py +100 -17
  87. zrb/xcom/xcom.py +0 -1
  88. {zrb-1.0.0a17.dist-info → zrb-1.0.0a19.dist-info}/METADATA +1 -1
  89. zrb-1.0.0a19.dist-info/RECORD +241 -0
  90. zrb/builtin/project/add/fastapp/fastapp_template/_zrb/column/create_column_task.py +0 -11
  91. zrb/builtin/project/add/fastapp/fastapp_template/_zrb/entity/module_template/service/my_entity/repository/factory.py +0 -13
  92. zrb/builtin/project/add/fastapp/fastapp_template/_zrb/entity/task.py +0 -260
  93. zrb/builtin/project/add/fastapp/fastapp_template/_zrb/module/task.py +0 -143
  94. zrb/builtin/project/add/fastapp/fastapp_template/_zrb/module/template/module_template/client/api_client.py +0 -6
  95. zrb/builtin/project/add/fastapp/fastapp_template/_zrb/module/template/module_template/client/direct_client.py +0 -6
  96. zrb/builtin/project/add/fastapp/fastapp_template/_zrb/module/template/module_template/client/factory.py +0 -9
  97. zrb/builtin/project/add/fastapp/fastapp_template/main.py +0 -7
  98. zrb/builtin/project/add/fastapp/fastapp_template/migrate.py +0 -3
  99. zrb/builtin/project/add/fastapp/fastapp_template/module/auth/client/api_client.py +0 -7
  100. zrb/builtin/project/add/fastapp/fastapp_template/module/auth/client/direct_client.py +0 -6
  101. zrb/builtin/project/add/fastapp/fastapp_template/module/auth/client/factory.py +0 -9
  102. zrb/builtin/project/add/fastapp/fastapp_template/module/auth/service/user/repository/factory.py +0 -13
  103. zrb/runner/web_controller/task_ui/partial/common-util.js +0 -37
  104. zrb/runner/web_controller/task_ui/partial/main.js +0 -195
  105. zrb/runner/web_controller/task_ui/partial/show-existing-session.js +0 -97
  106. zrb/runner/web_controller/task_ui/partial/visualize-history.js +0 -104
  107. zrb-1.0.0a17.dist-info/RECORD +0 -234
  108. /zrb/builtin/project/add/fastapp/fastapp_template/{.gitignore → my_app_name/.gitignore} +0 -0
  109. /zrb/builtin/project/add/fastapp/fastapp_template/{README.md → my_app_name/README.md} +0 -0
  110. /zrb/builtin/project/add/fastapp/fastapp_template/{__init__.py → my_app_name/__init__.py} +0 -0
  111. /zrb/builtin/project/add/fastapp/fastapp_template/{_zrb → my_app_name/_zrb}/config.py +0 -0
  112. /zrb/builtin/project/add/fastapp/fastapp_template/{_zrb/entity/schema.template.py → my_app_name/_zrb/entity/template/app_template/schema/my_entity.py} +0 -0
  113. /zrb/builtin/project/add/fastapp/fastapp_template/{_zrb → my_app_name/_zrb}/group.py +0 -0
  114. /zrb/builtin/project/add/fastapp/fastapp_template/{_zrb/module/template/module_template/migration/versions/.gitkeep → my_app_name/_zrb/module/template/app_template/module/gateway/subroute/my_module.py} +0 -0
  115. /zrb/builtin/project/add/fastapp/fastapp_template/{_zrb/module/template/module_template → my_app_name/_zrb/module/template/app_template/module/my_module}/alembic.ini +0 -0
  116. /zrb/builtin/project/add/fastapp/fastapp_template/{_zrb/module/template/module_template → my_app_name/_zrb/module/template/app_template/module/my_module}/client/any_client.py +0 -0
  117. /zrb/builtin/project/add/fastapp/fastapp_template/{_zrb/module/template/module_template → my_app_name/_zrb/module/template/app_template/module/my_module}/migration/README +0 -0
  118. /zrb/builtin/project/add/fastapp/fastapp_template/{module/gateway → my_app_name/_zrb/module/template/app_template/module/my_module}/migration/versions/.gitkeep +0 -0
  119. /zrb/builtin/project/add/fastapp/fastapp_template/{_zrb/module/template/module_template → my_app_name/_zrb/module/template/app_template/module/my_module}/migration_metadata.py +0 -0
  120. /zrb/builtin/project/add/fastapp/fastapp_template/{_zrb/module/template/module_template → my_app_name/_zrb/module/template/app_template/module/my_module}/service/__init__.py +0 -0
  121. /zrb/builtin/project/add/fastapp/fastapp_template/{_zrb/module/template/task_definition.py → my_app_name/_zrb/module/template/module_task_definition.py} +0 -0
  122. /zrb/builtin/project/add/fastapp/fastapp_template/{common → my_app_name/common}/__init__.py +0 -0
  123. /zrb/builtin/project/add/fastapp/fastapp_template/{common → my_app_name/common}/base_usecase.py +0 -0
  124. /zrb/builtin/project/add/fastapp/fastapp_template/{common → my_app_name/common}/error.py +0 -0
  125. /zrb/builtin/project/add/fastapp/fastapp_template/{common → my_app_name/common}/schema.py +0 -0
  126. /zrb/builtin/project/add/fastapp/fastapp_template/{config.py → my_app_name/config.py} +0 -0
  127. /zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/__init__.py +0 -0
  128. /zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/auth/alembic.ini +0 -0
  129. /zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/auth/migration/README +0 -0
  130. /zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/auth/migration/versions/3093c7336477_add_user_table.py +0 -0
  131. /zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/auth/service/__init__.py +0 -0
  132. /zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/auth/service/user/__init__.py +0 -0
  133. /zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/auth/service/user/repository/__init__.py +0 -0
  134. /zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/gateway/alembic.ini +0 -0
  135. /zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/gateway/migration/README +0 -0
  136. /zrb/builtin/project/add/fastapp/fastapp_template/{schema/__init__.py → my_app_name/module/gateway/migration/versions/.gitkeep} +0 -0
  137. /zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/gateway/migration_metadata.py +0 -0
  138. /zrb/builtin/project/add/fastapp/fastapp_template/{requirements.txt → my_app_name/requirements.txt} +0 -0
  139. /zrb/builtin/project/add/fastapp/fastapp_template/{schema → my_app_name/schema}/permission.py +0 -0
  140. /zrb/builtin/project/add/fastapp/fastapp_template/{schema → my_app_name/schema}/role.py +0 -0
  141. /zrb/builtin/project/add/fastapp/fastapp_template/{schema → my_app_name/schema}/user.py +0 -0
  142. /zrb/builtin/project/add/fastapp/fastapp_template/{template.env → my_app_name/template.env} +0 -0
  143. {zrb-1.0.0a17.dist-info → zrb-1.0.0a19.dist-info}/WHEEL +0 -0
  144. {zrb-1.0.0a17.dist-info → zrb-1.0.0a19.dist-info}/entry_points.txt +0 -0
zrb/__init__.py CHANGED
@@ -27,6 +27,7 @@ from zrb.group.group import Group
27
27
  from zrb.input.any_input import AnyInput
28
28
  from zrb.input.base_input import BaseInput
29
29
  from zrb.input.bool_input import BoolInput
30
+ from zrb.input.float_input import FloatInput
30
31
  from zrb.input.int_input import IntInput
31
32
  from zrb.input.option_input import OptionInput
32
33
  from zrb.input.password_input import PasswordInput
@@ -73,6 +74,7 @@ assert CmdResult
73
74
  assert CmdTask
74
75
  assert HttpCheck
75
76
  assert TcpCheck
77
+ assert FloatInput
76
78
  assert IntInput
77
79
  assert OptionInput
78
80
  assert PasswordInput
@@ -6,19 +6,18 @@ from zrb.builtin.project.add.fastapp.fastapp_input import (
6
6
  project_dir_input,
7
7
  )
8
8
  from zrb.builtin.project.add.fastapp.fastapp_util import (
9
- get_zrb_init_import_code,
10
- get_zrb_init_load_app_name_task,
9
+ is_in_project_app_dir,
10
+ is_project_zrb_init_file,
11
+ update_project_zrb_init_file,
11
12
  )
13
+ from zrb.content_transformer.content_transformer import ContentTransformer
12
14
  from zrb.context.any_context import AnyContext
13
15
  from zrb.task.make_task import make_task
14
16
  from zrb.task.scaffolder import Scaffolder
15
17
  from zrb.task.task import Task
16
- from zrb.util.file import read_file, write_file
17
18
  from zrb.util.string.conversion import to_snake_case
18
19
  from zrb.util.string.name import get_random_name
19
20
 
20
- _DIR = os.path.dirname(__file__)
21
-
22
21
 
23
22
  @make_task(
24
23
  name="validate-create-fastapp",
@@ -41,51 +40,38 @@ scaffold_fastapp = Scaffolder(
41
40
  app_name_input,
42
41
  ],
43
42
  upstream=validate_create_fastapp,
44
- source_path=os.path.join(_DIR, "fastapp_template"),
43
+ source_path=os.path.join(os.path.dirname(__file__), "fastapp_template"),
45
44
  render_source_path=False,
46
- destination_path=lambda ctx: os.path.join(
47
- ctx.input.project_dir, to_snake_case(ctx.input.app)
48
- ),
49
- transform_content={
50
- "fastapp_template": "{to_snake_case(ctx.input.app)}",
51
- "My App Name": "{ctx.input.app.title()}",
52
- "my-app-name": "{to_kebab_case(ctx.input.app)}",
45
+ destination_path="{ctx.input.project_dir}",
46
+ transform_path={
53
47
  "my_app_name": "{to_snake_case(ctx.input.app)}",
54
- "MY_APP_NAME": "{to_snake_case(ctx.input.app).upper()}",
55
- "my-secure-password": lambda _: get_random_name(),
56
48
  },
57
- retries=0,
58
- )
59
-
60
-
61
- @make_task(
62
- name="update-fastapp-zrb-init",
63
- input=[
64
- project_dir_input,
65
- app_name_input,
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
66
  ],
67
- upstream=scaffold_fastapp,
68
67
  retries=0,
69
68
  )
70
- def update_fastapp_zrb_init(ctx: AnyContext):
71
- zrb_init_path = os.path.join(ctx.input.project_dir, "zrb_init.py")
72
- old_zrb_init_code = read_file(zrb_init_path)
73
- write_file(
74
- file_path=zrb_init_path,
75
- content=[
76
- get_zrb_init_import_code(old_zrb_init_code),
77
- old_zrb_init_code.strip(),
78
- get_zrb_init_load_app_name_task(ctx.input.app),
79
- "",
80
- ],
81
- )
82
-
83
69
 
84
70
  add_fastapp_to_project = add_to_project_group.add_task(
85
71
  Task(
86
72
  name="add-fastapp",
87
73
  description="🚀 Add FastApp to project",
88
- upstream=update_fastapp_zrb_init,
74
+ upstream=scaffold_fastapp,
89
75
  retries=0,
90
76
  ),
91
77
  alias="fastapp",
@@ -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
+ )
@@ -4,7 +4,7 @@ async def get_my_entity_by_id(self, my_entity_id: str) -> MyEntityResponse:
4
4
 
5
5
 
6
6
  @abstractmethod
7
- async def get_all_my_entitys(self) -> list[MyEntityResponse]:
7
+ async def get_all_my_entities(self) -> list[MyEntityResponse]:
8
8
  pass
9
9
 
10
10
 
@@ -1,11 +1,11 @@
1
- from fastapp_template.common.base_usecase import BaseUsecase
2
- from fastapp_template.module.my_module.service.my_entity.repository.factory import (
1
+ from my_app_name.common.base_usecase import BaseUsecase
2
+ from my_app_name.module.my_module.service.my_entity.repository.factory import (
3
3
  my_entity_repository,
4
4
  )
5
- from fastapp_template.module.my_module.service.my_entity.repository.my_entity_repository import (
5
+ from my_app_name.module.my_module.service.my_entity.repository.my_entity_repository import (
6
6
  MyEntityRepository,
7
7
  )
8
- from fastapp_template.schema.my_entity import (
8
+ from my_app_name.schema.my_entity import (
9
9
  MyEntityCreateWithAudit,
10
10
  MyEntityResponse,
11
11
  MyEntityUpdateWithAudit,
@@ -13,7 +13,6 @@ from fastapp_template.schema.my_entity import (
13
13
 
14
14
 
15
15
  class MyEntityUsecase(BaseUsecase):
16
-
17
16
  def __init__(self, my_entity_repository: MyEntityRepository):
18
17
  super().__init__()
19
18
  self.my_entity_repository = my_entity_repository
@@ -0,0 +1,13 @@
1
+ from my_app_name.common.db_engine import engine
2
+ from my_app_name.config import APP_REPOSITORY_TYPE
3
+ from my_app_name.module.my_module.service.my_entity.repository.my_entity_db_repository import (
4
+ MyEntityDBRepository,
5
+ )
6
+ from my_app_name.module.my_module.service.my_entity.repository.my_entity_repository import (
7
+ MyEntityRepository,
8
+ )
9
+
10
+ if APP_REPOSITORY_TYPE == "db":
11
+ my_entity_repository: MyEntityRepository = MyEntityDBRepository(engine)
12
+ else:
13
+ my_entity_repository: MyEntityRepository = None
@@ -1,9 +1,9 @@
1
- from fastapp_template.common.base_db_repository import BaseDBRepository
2
- from fastapp_template.common.error import NotFoundError
3
- from fastapp_template.module.my_module.service.my_entity.repository.my_entity_repository import (
1
+ from my_app_name.common.base_db_repository import BaseDBRepository
2
+ from my_app_name.common.error import NotFoundError
3
+ from my_app_name.module.my_module.service.my_entity.repository.my_entity_repository import (
4
4
  MyEntityRepository,
5
5
  )
6
- from fastapp_template.schema.my_entity import (
6
+ from my_app_name.schema.my_entity import (
7
7
  MyEntity,
8
8
  MyEntityCreateWithAudit,
9
9
  MyEntityResponse,
@@ -1,6 +1,6 @@
1
1
  from abc import ABC, abstractmethod
2
2
 
3
- from fastapp_template.schema.my_entity import (
3
+ from my_app_name.schema.my_entity import (
4
4
  MyEntity,
5
5
  MyEntityCreateWithAudit,
6
6
  MyEntityResponse,
@@ -9,7 +9,6 @@ from fastapp_template.schema.my_entity import (
9
9
 
10
10
 
11
11
  class MyEntityRepository(ABC):
12
-
13
12
  @abstractmethod
14
13
  async def create(self, my_entity_data: MyEntityCreateWithAudit) -> MyEntityResponse:
15
14
  pass
@@ -0,0 +1,17 @@
1
+ from my_app_name._zrb.config import APP_DIR
2
+ from my_app_name._zrb.group import app_group
3
+
4
+ from zrb.task.cmd_task import CmdTask
5
+
6
+ format_my_app_name_code = app_group.add_task(
7
+ CmdTask(
8
+ name="format-my-app-name-code",
9
+ description="✏️ Format Python code",
10
+ cmd=[
11
+ "isort . --profile black --force-grid-wrap 0",
12
+ "black .",
13
+ ],
14
+ cwd=APP_DIR,
15
+ ),
16
+ alias="format",
17
+ )
@@ -1,7 +1,4 @@
1
- from fastapp_template._zrb.util import (
2
- get_existing_module_names,
3
- get_existing_schema_names,
4
- )
1
+ from my_app_name._zrb.util import get_existing_module_names, get_existing_schema_names
5
2
 
6
3
  from zrb import OptionInput, StrInput
7
4
  from zrb.util.string.conversion import pluralize
@@ -0,0 +1,85 @@
1
+ import os
2
+
3
+ from my_app_name._zrb.config import APP_DIR
4
+ from my_app_name._zrb.format_task import format_my_app_name_code
5
+ from my_app_name._zrb.group import app_create_group
6
+ from my_app_name._zrb.input import new_module_input
7
+ from my_app_name._zrb.module.add_module_util import (
8
+ is_app_config_file,
9
+ is_app_main_file,
10
+ is_app_zrb_config_file,
11
+ is_app_zrb_task_file,
12
+ is_in_module_dir,
13
+ update_app_config_file,
14
+ update_app_main_file,
15
+ update_app_zrb_config_file,
16
+ update_app_zrb_task_file,
17
+ )
18
+ from my_app_name._zrb.util import get_existing_module_names
19
+
20
+ from zrb import AnyContext, ContentTransformer, Scaffolder, Task, make_task
21
+
22
+
23
+ @make_task(
24
+ name="validate-create-my-app-name-module",
25
+ input=new_module_input,
26
+ retries=0,
27
+ )
28
+ async def validate_create_my_app_name_module(ctx: AnyContext):
29
+ if ctx.input.module in get_existing_module_names():
30
+ raise ValueError(f"Module already exists: {ctx.input.module}")
31
+
32
+
33
+ scaffold_my_app_name_module = Scaffolder(
34
+ name="scaffold-my-app-name-module",
35
+ input=new_module_input,
36
+ source_path=os.path.join(os.path.dirname(__file__), "template", "app_template"),
37
+ render_source_path=False,
38
+ destination_path=APP_DIR,
39
+ transform_path={
40
+ "my_module": "{to_snake_case(ctx.input.module)}",
41
+ },
42
+ transform_content=[
43
+ # Common transformation (my_app_name/module/snake_module_name)
44
+ ContentTransformer(
45
+ match=is_in_module_dir,
46
+ transform={
47
+ "MY_MODULE": "{to_snake_case(ctx.input.module).upper()}",
48
+ "my_module": "{to_snake_case(ctx.input.module)}",
49
+ },
50
+ ),
51
+ # Register module config to my_app_name/config.py
52
+ ContentTransformer(
53
+ match=is_app_config_file,
54
+ transform=update_app_config_file,
55
+ ),
56
+ # Register module route to my_app_name/main.py
57
+ ContentTransformer(
58
+ match=is_app_main_file,
59
+ transform=update_app_main_file,
60
+ ),
61
+ # Register module's tasks to my_app_name/_zrb/task.py
62
+ ContentTransformer(
63
+ match=is_app_zrb_task_file,
64
+ transform=update_app_zrb_task_file,
65
+ ),
66
+ # Register module's base url to my_app_name/_zrb/config.py
67
+ ContentTransformer(
68
+ match=is_app_zrb_config_file,
69
+ transform=update_app_zrb_config_file,
70
+ ),
71
+ ],
72
+ retries=0,
73
+ upstream=validate_create_my_app_name_module,
74
+ )
75
+
76
+ add_my_app_name_module = app_create_group.add_task(
77
+ Task(
78
+ name="add-my-app-name-module",
79
+ description="🧩 Create new module on My App Name",
80
+ upstream=scaffold_my_app_name_module,
81
+ successor=format_my_app_name_code,
82
+ retries=0,
83
+ ),
84
+ alias="module",
85
+ )