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
@@ -0,0 +1,154 @@
1
+ import os
2
+
3
+ from my_app_name._zrb.config import APP_DIR
4
+ from my_app_name._zrb.util import get_existing_module_names
5
+
6
+ from zrb.context.any_context import AnyContext
7
+ from zrb.util.codemod.append_key_to_dict import append_key_to_dict
8
+ from zrb.util.file import read_file, write_file
9
+ from zrb.util.string.conversion import to_kebab_case, to_pascal_case, to_snake_case
10
+
11
+
12
+ def is_app_config_file(ctx: AnyContext, file_path: str) -> bool:
13
+ return file_path == os.path.join(APP_DIR, "config.py")
14
+
15
+
16
+ def is_app_main_file(ctx: AnyContext, file_path: str) -> bool:
17
+ return file_path == os.path.join(APP_DIR, "main.py")
18
+
19
+
20
+ def is_app_zrb_task_file(ctx: AnyContext, file_path: str) -> bool:
21
+ return file_path == os.path.join(APP_DIR, "_zrb", "task.py")
22
+
23
+
24
+ def is_app_zrb_config_file(ctx: AnyContext, file_path: str) -> bool:
25
+ return file_path == os.path.join(APP_DIR, "_zrb", "config.py")
26
+
27
+
28
+ def is_in_module_dir(ctx: AnyContext, file_path: str) -> bool:
29
+ return file_path.startswith(
30
+ os.path.join(APP_DIR, "module", to_snake_case(ctx.input.module))
31
+ )
32
+
33
+
34
+ def update_app_zrb_config_file(ctx: AnyContext, zrb_config_file_path: str):
35
+ existing_zrb_config_code = read_file(zrb_config_file_path)
36
+ module_name = ctx.input.module
37
+ upper_snake_module_name = to_snake_case(module_name).upper()
38
+ existing_module_names = get_existing_module_names()
39
+ module_port = 3001 + len(
40
+ [
41
+ existing_module_name
42
+ for existing_module_name in existing_module_names
43
+ if existing_module_name != to_snake_case(module_name)
44
+ ]
45
+ )
46
+ write_file(
47
+ file_path=zrb_config_file_path,
48
+ content=append_key_to_dict(
49
+ original_code=existing_zrb_config_code,
50
+ dictionary_name="MICROSERVICES_ENV_VARS",
51
+ new_key=f"MY_APP_NAME_{upper_snake_module_name}_BASE_URL",
52
+ new_value=f"http://localhost:{module_port}",
53
+ ),
54
+ )
55
+
56
+
57
+ def update_app_zrb_task_file(ctx: AnyContext, zrb_task_file_path: str):
58
+ existing_zrb_task_code = read_file(zrb_task_file_path)
59
+ write_file(
60
+ file_path=zrb_task_file_path,
61
+ content=[
62
+ existing_zrb_task_code.strip(),
63
+ "",
64
+ _get_task_definition_code(existing_zrb_task_code, ctx.input.module),
65
+ ],
66
+ )
67
+
68
+
69
+ def _get_task_definition_code(existing_code: str, module_name: str) -> str | None:
70
+ existing_module_names = get_existing_module_names()
71
+ module_port = 3001 + len(
72
+ [
73
+ existing_module_name
74
+ for existing_module_name in existing_module_names
75
+ if existing_module_name != to_snake_case(module_name)
76
+ ]
77
+ )
78
+ snake_module_name = to_snake_case(module_name)
79
+ kebab_module_name = to_kebab_case(module_name)
80
+ pascal_module_name = to_pascal_case(module_name)
81
+ task_definition_code = read_file(
82
+ file_path=os.path.join(
83
+ os.path.dirname(__file__), "template", "module_task_definition.py"
84
+ ),
85
+ replace_map={
86
+ "my_module": snake_module_name,
87
+ "my-module": kebab_module_name,
88
+ "My Module": pascal_module_name,
89
+ "3000": f"{module_port}",
90
+ },
91
+ ).strip()
92
+ if task_definition_code in existing_code:
93
+ return None
94
+ return task_definition_code
95
+
96
+
97
+ def update_app_main_file(ctx: AnyContext, app_main_file_path: str):
98
+ existing_app_main_code = read_file(app_main_file_path)
99
+ write_file(
100
+ file_path=app_main_file_path,
101
+ content=[
102
+ _get_import_module_route_code(existing_app_main_code, ctx.input.module),
103
+ existing_app_main_code,
104
+ "",
105
+ _get_assert_module_route_code(existing_app_main_code, ctx.input.module),
106
+ ],
107
+ )
108
+
109
+
110
+ def _get_import_module_route_code(existing_code: str, module_name: str) -> str | None:
111
+ snake_module_name = to_snake_case(module_name)
112
+ import_module_path = f"my_app_name.module.{snake_module_name}"
113
+ import_route_code = (
114
+ f"from {import_module_path} import route as {snake_module_name}_route"
115
+ )
116
+ if import_route_code in existing_code:
117
+ return None
118
+ return import_route_code
119
+
120
+
121
+ def _get_assert_module_route_code(existing_code: str, module_name: str) -> str | None:
122
+ snake_module_name = to_snake_case(module_name)
123
+ assert_route_code = f"assert {snake_module_name}_route"
124
+ return assert_route_code if assert_route_code not in existing_code else None
125
+
126
+
127
+ def update_app_config_file(ctx: AnyContext, module_config_path: str):
128
+ existing_config_code = read_file(module_config_path)
129
+ write_file(
130
+ module_config_path,
131
+ [
132
+ existing_config_code.strip(),
133
+ _get_new_module_config_code(existing_config_code, ctx.input.module),
134
+ ],
135
+ )
136
+
137
+
138
+ def _get_new_module_config_code(existing_code: str, module_name: str) -> str | None:
139
+ existing_module_names = get_existing_module_names()
140
+ module_port = 3000 + len(
141
+ [
142
+ existing_module_name
143
+ for existing_module_name in existing_module_names
144
+ if existing_module_name != to_snake_case(module_name)
145
+ ]
146
+ )
147
+ module_base_url = f"http://localhost:{module_port}"
148
+ upper_snake_module_name = to_snake_case(module_name).upper()
149
+ config_name = f"APP_{upper_snake_module_name}_BASE_URL"
150
+ env_name = f"MY_APP_NAME_{upper_snake_module_name}_BASE_URL"
151
+ config_code = f'{config_name} = os.getenv("{env_name}", "{module_base_url}")'
152
+ if config_code in existing_code:
153
+ return None
154
+ return config_code
@@ -0,0 +1,6 @@
1
+ from my_app_name.config import APP_MY_MODULE_BASE_URL
2
+ from my_app_name.module.module_template.client.any_client import AnyClient
3
+
4
+
5
+ class APIClient(AnyClient):
6
+ pass
@@ -0,0 +1,6 @@
1
+ from my_app_name.module.module_template.client.any_client import AnyClient
2
+ from my_app_name.module.module_template.service.user.usecase import user_usecase
3
+
4
+
5
+ class DirectClient(AnyClient):
6
+ pass
@@ -0,0 +1,9 @@
1
+ from my_app_name.config import APP_COMMUNICATION
2
+ from my_app_name.module.module_template.client.any_client import AnyClient
3
+ from my_app_name.module.module_template.client.api_client import APIClient
4
+ from my_app_name.module.module_template.client.direct_client import DirectClient
5
+
6
+ if APP_COMMUNICATION == "direct":
7
+ client: AnyClient = DirectClient()
8
+ elif APP_COMMUNICATION == "api":
9
+ client: AnyClient = APIClient()
@@ -1,8 +1,8 @@
1
1
  from logging.config import fileConfig
2
2
 
3
3
  from alembic import context
4
- from fastapp_template.config import APP_DB_URL
5
- from fastapp_template.module.my_module.migration_metadata import metadata
4
+ from my_app_name.config import APP_DB_URL
5
+ from my_app_name.module.my_module.migration_metadata import metadata
6
6
  from sqlalchemy import engine_from_config, pool
7
7
 
8
8
  # this is the Alembic Config object, which provides
@@ -68,7 +68,6 @@ def run_migrations_offline() -> None:
68
68
  target_metadata=target_metadata,
69
69
  literal_binds=True,
70
70
  dialect_opts={"paramstyle": "named"},
71
- imports=["import sqlmodel"], # 🔥 FastApp Modification
72
71
  version_table=MIGRATION_TABLE, # 🔥 FastApp Modification
73
72
  include_object=include_object, # 🔥 FastApp Modification
74
73
  )
@@ -94,7 +93,6 @@ def run_migrations_online() -> None:
94
93
  context.configure(
95
94
  connection=connection,
96
95
  target_metadata=target_metadata,
97
- imports=["import sqlmodel"], # 🔥 FastApp Modification
98
96
  version_table=MIGRATION_TABLE, # 🔥 FastApp Modification
99
97
  include_object=include_object, # 🔥 FastApp Modification
100
98
  )
@@ -9,6 +9,7 @@ from typing import Sequence, Union
9
9
 
10
10
  from alembic import op
11
11
  import sqlalchemy as sa
12
+ import sqlmodel # 🔥 FastApp Modification
12
13
  ${imports if imports else ""}
13
14
 
14
15
  # revision identifiers, used by Alembic.
@@ -1,7 +1,7 @@
1
1
  from fastapi import FastAPI
2
- from fastapp_template.common.app import app
3
- from fastapp_template.common.schema import BasicResponse
4
- from fastapp_template.config import APP_MAIN_MODULE, APP_MODE, APP_MODULES
2
+ from my_app_name.common.app import app
3
+ from my_app_name.common.schema import BasicResponse
4
+ from my_app_name.config import APP_MAIN_MODULE, APP_MODE, APP_MODULES
5
5
 
6
6
 
7
7
  def serve_health_check(app: FastAPI):
@@ -1,26 +1,24 @@
1
1
  import os
2
2
 
3
- from fastapp_template._zrb.column.create_column_task import create_my_app_name_column
4
- from fastapp_template._zrb.config import ACTIVATE_VENV_SCRIPT, APP_DIR
5
- from fastapp_template._zrb.entity.task import create_my_app_name_entity
6
- from fastapp_template._zrb.group import (
3
+ from my_app_name._zrb.column.create_column_task import add_my_app_name_column
4
+ from my_app_name._zrb.config import ACTIVATE_VENV_SCRIPT, APP_DIR
5
+ from my_app_name._zrb.entity.add_entity_task import add_my_app_name_entity
6
+ from my_app_name._zrb.format_task import format_my_app_name_code
7
+ from my_app_name._zrb.group import (
7
8
  app_create_migration_group,
8
9
  app_migrate_group,
9
10
  app_run_group,
10
11
  )
11
- from fastapp_template._zrb.module.task import create_my_app_name_module
12
- from fastapp_template._zrb.util import (
13
- create_migration,
14
- migrate_module,
15
- run_microservice,
16
- )
17
- from fastapp_template._zrb.venv_task import prepare_venv
12
+ from my_app_name._zrb.module.add_module_task import add_my_app_name_module
13
+ from my_app_name._zrb.util import create_migration, migrate_module, run_microservice
14
+ from my_app_name._zrb.venv_task import prepare_venv
18
15
 
19
16
  from zrb import CmdTask, Env, EnvFile, Task
20
17
 
21
- assert create_my_app_name_entity
22
- assert create_my_app_name_module
23
- assert create_my_app_name_column
18
+ assert add_my_app_name_entity
19
+ assert add_my_app_name_module
20
+ assert add_my_app_name_column
21
+ assert format_my_app_name_code
24
22
 
25
23
  # 🚀 Run/Migrate All ===========================================================
26
24
 
@@ -1,6 +1,6 @@
1
1
  import os
2
2
 
3
- from fastapp_template._zrb.config import (
3
+ from my_app_name._zrb.config import (
4
4
  ACTIVATE_VENV_SCRIPT,
5
5
  APP_DIR,
6
6
  MICROSERVICES_ENV_VARS,
@@ -1,6 +1,6 @@
1
1
  import os
2
2
 
3
- from fastapp_template._zrb.config import ACTIVATE_VENV_SCRIPT, APP_DIR
3
+ from my_app_name._zrb.config import ACTIVATE_VENV_SCRIPT, APP_DIR
4
4
 
5
5
  from zrb import CmdTask
6
6
 
@@ -1,8 +1,8 @@
1
1
  from contextlib import asynccontextmanager
2
2
 
3
3
  from fastapi import FastAPI
4
- from fastapp_template.common.db_engine import engine
5
- from fastapp_template.config import APP_MODE, APP_MODULES
4
+ from my_app_name.common.db_engine import engine
5
+ from my_app_name.config import APP_MODE, APP_MODULES
6
6
  from sqlmodel import SQLModel
7
7
 
8
8
 
@@ -1,6 +1,6 @@
1
1
  from typing import Any, Callable, Generic, Type, TypeVar
2
2
 
3
- from fastapp_template.common.error import NotFoundError
3
+ from my_app_name.common.error import NotFoundError
4
4
  from sqlalchemy import Engine
5
5
  from sqlalchemy.ext.asyncio import AsyncEngine, AsyncSession
6
6
  from sqlmodel import Session, SQLModel, select
@@ -1,4 +1,4 @@
1
- from fastapp_template.config import APP_DB_URL
1
+ from my_app_name.config import APP_DB_URL
2
2
  from sqlmodel import create_engine
3
3
 
4
4
  connect_args = {"check_same_thread": False}
@@ -0,0 +1,7 @@
1
+ from my_app_name.common.app import app
2
+ from my_app_name.module.auth import route as auth_route
3
+ from my_app_name.module.gateway import route as gateway_route
4
+
5
+ assert app
6
+ assert gateway_route
7
+ assert auth_route
@@ -0,0 +1,3 @@
1
+ from my_app_name.module.auth import migration as auth_migration
2
+
3
+ assert auth_migration
@@ -1,6 +1,6 @@
1
1
  from abc import ABC, abstractmethod
2
2
 
3
- from fastapp_template.schema.user import (
3
+ from my_app_name.schema.user import (
4
4
  UserCreateWithAudit,
5
5
  UserResponse,
6
6
  UserUpdateWithAudit,
@@ -0,0 +1,7 @@
1
+ from my_app_name.config import APP_AUTH_BASE_URL
2
+ from my_app_name.module.auth.client.any_client import AnyClient
3
+ from my_app_name.module.auth.service.user.user_usecase import user_usecase
4
+
5
+
6
+ class APIClient(user_usecase.as_api_client(base_url=APP_AUTH_BASE_URL), AnyClient):
7
+ pass
@@ -0,0 +1,6 @@
1
+ from my_app_name.module.auth.client.any_client import AnyClient
2
+ from my_app_name.module.auth.service.user.user_usecase import user_usecase
3
+
4
+
5
+ class DirectClient(user_usecase.as_direct_client(), AnyClient):
6
+ pass
@@ -0,0 +1,9 @@
1
+ from my_app_name.config import APP_COMMUNICATION
2
+ from my_app_name.module.auth.client.any_client import AnyClient
3
+ from my_app_name.module.auth.client.api_client import APIClient
4
+ from my_app_name.module.auth.client.direct_client import DirectClient
5
+
6
+ if APP_COMMUNICATION == "direct":
7
+ client: AnyClient = DirectClient()
8
+ elif APP_COMMUNICATION == "api":
9
+ client: AnyClient = APIClient()
@@ -1,8 +1,8 @@
1
1
  from logging.config import fileConfig
2
2
 
3
3
  from alembic import context
4
- from fastapp_template.config import APP_DB_URL
5
- from fastapp_template.module.auth.migration_metadata import metadata
4
+ from my_app_name.config import APP_DB_URL
5
+ from my_app_name.module.auth.migration_metadata import metadata
6
6
  from sqlalchemy import engine_from_config, pool
7
7
 
8
8
  # this is the Alembic Config object, which provides
@@ -68,7 +68,6 @@ def run_migrations_offline() -> None:
68
68
  target_metadata=target_metadata,
69
69
  literal_binds=True,
70
70
  dialect_opts={"paramstyle": "named"},
71
- imports=["import sqlmodel"], # 🔥 FastApp Modification
72
71
  version_table=MIGRATION_TABLE, # 🔥 FastApp Modification
73
72
  include_object=include_object, # 🔥 FastApp Modification
74
73
  )
@@ -94,7 +93,6 @@ def run_migrations_online() -> None:
94
93
  context.configure(
95
94
  connection=connection,
96
95
  target_metadata=target_metadata,
97
- imports=["import sqlmodel"], # 🔥 FastApp Modification
98
96
  version_table=MIGRATION_TABLE, # 🔥 FastApp Modification
99
97
  include_object=include_object, # 🔥 FastApp Modification
100
98
  )
@@ -9,6 +9,7 @@ from typing import Sequence, Union
9
9
 
10
10
  from alembic import op
11
11
  import sqlalchemy as sa
12
+ import sqlmodel # 🔥 FastApp Modification
12
13
  ${imports if imports else ""}
13
14
 
14
15
  # revision identifiers, used by Alembic.
@@ -1,4 +1,4 @@
1
- from fastapp_template.schema.user import User
1
+ from my_app_name.schema.user import User
2
2
  from sqlalchemy import MetaData
3
3
 
4
4
  metadata = MetaData()
@@ -1,8 +1,8 @@
1
1
  from fastapi import FastAPI
2
- from fastapp_template.common.app import app
3
- from fastapp_template.common.schema import BasicResponse
4
- from fastapp_template.config import APP_MAIN_MODULE, APP_MODE, APP_MODULES
5
- from fastapp_template.module.auth.service.user.user_usecase import user_usecase
2
+ from my_app_name.common.app import app
3
+ from my_app_name.common.schema import BasicResponse
4
+ from my_app_name.config import APP_MAIN_MODULE, APP_MODE, APP_MODULES
5
+ from my_app_name.module.auth.service.user.user_usecase import user_usecase
6
6
 
7
7
 
8
8
  def serve_health_check(app: FastAPI):
@@ -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.auth.service.user.repository.user_db_repository import (
4
+ UserDBRepository,
5
+ )
6
+ from my_app_name.module.auth.service.user.repository.user_repository import (
7
+ UserRepository,
8
+ )
9
+
10
+ if APP_REPOSITORY_TYPE == "db":
11
+ user_repository: UserRepository = UserDBRepository(engine)
12
+ else:
13
+ user_repository: UserRepository = 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.auth.service.user.repository.user_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.auth.service.user.repository.user_repository import (
4
4
  UserRepository,
5
5
  )
6
- from fastapp_template.schema.user import (
6
+ from my_app_name.schema.user import (
7
7
  User,
8
8
  UserCreateWithAudit,
9
9
  UserResponse,
@@ -1,6 +1,6 @@
1
1
  from abc import ABC, abstractmethod
2
2
 
3
- from fastapp_template.schema.user import (
3
+ from my_app_name.schema.user import (
4
4
  User,
5
5
  UserCreateWithAudit,
6
6
  UserResponse,
@@ -9,7 +9,6 @@ from fastapp_template.schema.user import (
9
9
 
10
10
 
11
11
  class UserRepository(ABC):
12
-
13
12
  @abstractmethod
14
13
  async def create(self, user_data: UserCreateWithAudit) -> UserResponse:
15
14
  pass
@@ -1,9 +1,9 @@
1
- from fastapp_template.common.base_usecase import BaseUsecase
2
- from fastapp_template.module.auth.service.user.repository.factory import user_repository
3
- from fastapp_template.module.auth.service.user.repository.user_repository import (
1
+ from my_app_name.common.base_usecase import BaseUsecase
2
+ from my_app_name.module.auth.service.user.repository.factory import user_repository
3
+ from my_app_name.module.auth.service.user.repository.user_repository import (
4
4
  UserRepository,
5
5
  )
6
- from fastapp_template.schema.user import (
6
+ from my_app_name.schema.user import (
7
7
  UserCreateWithAudit,
8
8
  UserResponse,
9
9
  UserUpdateWithAudit,
@@ -11,7 +11,6 @@ from fastapp_template.schema.user import (
11
11
 
12
12
 
13
13
  class UserUsecase(BaseUsecase):
14
-
15
14
  def __init__(self, user_repository: UserRepository):
16
15
  super().__init__()
17
16
  self.user_repository = user_repository
@@ -1,8 +1,8 @@
1
1
  from logging.config import fileConfig
2
2
 
3
3
  from alembic import context
4
- from fastapp_template.config import APP_DB_URL
5
- from fastapp_template.module.gateway.migration_metadata import metadata
4
+ from my_app_name.config import APP_DB_URL
5
+ from my_app_name.module.gateway.migration_metadata import metadata
6
6
  from sqlalchemy import engine_from_config, pool
7
7
 
8
8
  # this is the Alembic Config object, which provides
@@ -68,7 +68,6 @@ def run_migrations_offline() -> None:
68
68
  target_metadata=target_metadata,
69
69
  literal_binds=True,
70
70
  dialect_opts={"paramstyle": "named"},
71
- imports=["import sqlmodel"], # 🔥 FastApp Modification
72
71
  version_table=MIGRATION_TABLE, # 🔥 FastApp Modification
73
72
  include_object=include_object, # 🔥 FastApp Modification
74
73
  )
@@ -94,7 +93,6 @@ def run_migrations_online() -> None:
94
93
  context.configure(
95
94
  connection=connection,
96
95
  target_metadata=target_metadata,
97
- imports=["import sqlmodel"], # 🔥 FastApp Modification
98
96
  version_table=MIGRATION_TABLE, # 🔥 FastApp Modification
99
97
  include_object=include_object, # 🔥 FastApp Modification
100
98
  )
@@ -9,6 +9,7 @@ from typing import Sequence, Union
9
9
 
10
10
  from alembic import op
11
11
  import sqlalchemy as sa
12
+ import sqlmodel # 🔥 FastApp Modification
12
13
  ${imports if imports else ""}
13
14
 
14
15
  # revision identifiers, used by Alembic.
@@ -1,9 +1,9 @@
1
1
  from fastapi import FastAPI
2
- from fastapp_template.common.app import app
3
- from fastapp_template.common.schema import BasicResponse
4
- from fastapp_template.config import APP_MAIN_MODULE, APP_MODE, APP_MODULES
5
- from fastapp_template.module.auth.client.factory import client as auth_client
6
- from fastapp_template.schema.user import UserCreate, UserResponse
2
+ from my_app_name.common.app import app
3
+ from my_app_name.common.schema import BasicResponse
4
+ from my_app_name.config import APP_MAIN_MODULE, APP_MODE, APP_MODULES
5
+ from my_app_name.module.auth.client.factory import client as auth_client
6
+ from my_app_name.schema.user import UserCreate, UserResponse
7
7
 
8
8
 
9
9
  def serve_health_check(app: FastAPI):
@@ -1,14 +1,38 @@
1
+ import os
2
+
3
+ from zrb.context.any_context import AnyContext
4
+ from zrb.util.file import read_file, write_file
1
5
  from zrb.util.string.conversion import double_quote, to_snake_case
2
6
 
3
7
 
4
- def get_zrb_init_import_code(old_code: str) -> str | None:
8
+ def is_in_project_app_dir(ctx: AnyContext, file_path: str) -> bool:
9
+ return file_path.startswith(
10
+ os.path.join(ctx.input.project_dir, to_snake_case(ctx.input.app))
11
+ )
12
+
13
+
14
+ def is_project_zrb_init_file(ctx: AnyContext, file_path: str) -> bool:
15
+ return file_path == os.path.join(ctx.input.project_dir, "zrb_init.py")
16
+
17
+
18
+ def update_project_zrb_init_file(ctx: AnyContext, zrb_init_path: str):
19
+ existing_zrb_init_code = read_file(zrb_init_path)
20
+ write_file(
21
+ file_path=zrb_init_path,
22
+ content=[
23
+ _get_import_load_file_code(existing_zrb_init_code),
24
+ existing_zrb_init_code.strip(),
25
+ _get_load_app_name_task_code(ctx.input.app),
26
+ ],
27
+ )
28
+
29
+
30
+ def _get_import_load_file_code(existing_code: str) -> str | None:
5
31
  code = "from zrb import load_file"
6
- if code in old_code:
7
- return None
8
- return code
32
+ return code if code not in existing_code else None
9
33
 
10
34
 
11
- def get_zrb_init_load_app_name_task(app: str) -> str:
35
+ def _get_load_app_name_task_code(app: str) -> str:
12
36
  snake_app_name = to_snake_case(app)
13
37
  load_file_param = ", ".join(
14
38
  [double_quote(part) for part in [snake_app_name, "_zrb", "task.py"]]
zrb/builtin/python.py CHANGED
@@ -5,7 +5,10 @@ format_python_code = python_group.add_task(
5
5
  CmdTask(
6
6
  name="format-code",
7
7
  description="✏️ Format Python code",
8
- cmd=["isort .", "black ."],
8
+ cmd=[
9
+ "isort . --profile black --force-grid-wrap 0",
10
+ "black .",
11
+ ],
9
12
  ),
10
13
  alias="format",
11
14
  )