zrb 1.0.0a1__py3-none-any.whl → 1.0.0a3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. zrb/__init__.py +48 -39
  2. zrb/__main__.py +3 -3
  3. zrb/attr/type.py +2 -1
  4. zrb/builtin/__init__.py +40 -2
  5. zrb/builtin/base64.py +32 -0
  6. zrb/builtin/git.py +156 -0
  7. zrb/builtin/git_subtree.py +88 -0
  8. zrb/builtin/group.py +34 -0
  9. zrb/builtin/llm.py +31 -0
  10. zrb/builtin/md5.py +34 -0
  11. zrb/builtin/project/__init__.py +0 -0
  12. zrb/builtin/project/add/__init__.py +0 -0
  13. zrb/builtin/project/add/fastapp.py +72 -0
  14. zrb/builtin/project/add/fastapp_template/.gitignore +4 -0
  15. zrb/builtin/project/add/fastapp_template/README.md +7 -0
  16. zrb/builtin/project/add/fastapp_template/__init__.py +0 -0
  17. zrb/builtin/project/add/fastapp_template/_zrb/config.py +17 -0
  18. zrb/builtin/project/add/fastapp_template/_zrb/group.py +16 -0
  19. zrb/builtin/project/add/fastapp_template/_zrb/helper.py +97 -0
  20. zrb/builtin/project/add/fastapp_template/_zrb/main.py +132 -0
  21. zrb/builtin/project/add/fastapp_template/_zrb/venv_task.py +22 -0
  22. zrb/builtin/project/add/fastapp_template/common/__init__.py +0 -0
  23. zrb/builtin/project/add/fastapp_template/common/app.py +18 -0
  24. zrb/builtin/project/add/fastapp_template/common/db_engine.py +5 -0
  25. zrb/builtin/project/add/fastapp_template/common/db_repository.py +134 -0
  26. zrb/builtin/project/add/fastapp_template/common/error.py +8 -0
  27. zrb/builtin/project/add/fastapp_template/common/schema.py +5 -0
  28. zrb/builtin/project/add/fastapp_template/common/usecase.py +232 -0
  29. zrb/builtin/project/add/fastapp_template/config.py +29 -0
  30. zrb/builtin/project/add/fastapp_template/main.py +7 -0
  31. zrb/builtin/project/add/fastapp_template/migrate.py +3 -0
  32. zrb/builtin/project/add/fastapp_template/module/__init__.py +0 -0
  33. zrb/builtin/project/add/fastapp_template/module/auth/alembic.ini +117 -0
  34. zrb/builtin/project/add/fastapp_template/module/auth/client/api_client.py +7 -0
  35. zrb/builtin/project/add/fastapp_template/module/auth/client/base_client.py +27 -0
  36. zrb/builtin/project/add/fastapp_template/module/auth/client/direct_client.py +6 -0
  37. zrb/builtin/project/add/fastapp_template/module/auth/client/factory.py +9 -0
  38. zrb/builtin/project/add/fastapp_template/module/auth/migration/README +1 -0
  39. zrb/builtin/project/add/fastapp_template/module/auth/migration/env.py +108 -0
  40. zrb/builtin/project/add/fastapp_template/module/auth/migration/script.py.mako +26 -0
  41. zrb/builtin/project/add/fastapp_template/module/auth/migration/versions/3093c7336477_add_user_table.py +37 -0
  42. zrb/builtin/project/add/fastapp_template/module/auth/migration_metadata.py +6 -0
  43. zrb/builtin/project/add/fastapp_template/module/auth/route.py +22 -0
  44. zrb/builtin/project/add/fastapp_template/module/auth/service/__init__.py +0 -0
  45. zrb/builtin/project/add/fastapp_template/module/auth/service/user/__init__.py +0 -0
  46. zrb/builtin/project/add/fastapp_template/module/auth/service/user/repository/__init__.py +0 -0
  47. zrb/builtin/project/add/fastapp_template/module/auth/service/user/repository/db_repository.py +39 -0
  48. zrb/builtin/project/add/fastapp_template/module/auth/service/user/repository/factory.py +13 -0
  49. zrb/builtin/project/add/fastapp_template/module/auth/service/user/repository/repository.py +34 -0
  50. zrb/builtin/project/add/fastapp_template/module/auth/service/user/usecase.py +45 -0
  51. zrb/builtin/project/add/fastapp_template/module/gateway/alembic.ini +117 -0
  52. zrb/builtin/project/add/fastapp_template/module/gateway/migration/README +1 -0
  53. zrb/builtin/project/add/fastapp_template/module/gateway/migration/env.py +108 -0
  54. zrb/builtin/project/add/fastapp_template/module/gateway/migration/script.py.mako +26 -0
  55. zrb/builtin/project/add/fastapp_template/module/gateway/migration/versions/.gitkeep +0 -0
  56. zrb/builtin/project/add/fastapp_template/module/gateway/migration_metadata.py +3 -0
  57. zrb/builtin/project/add/fastapp_template/module/gateway/route.py +27 -0
  58. zrb/builtin/project/add/fastapp_template/requirements.txt +6 -0
  59. zrb/builtin/project/add/fastapp_template/schema/__init__.py +0 -0
  60. zrb/builtin/project/add/fastapp_template/schema/role.py +31 -0
  61. zrb/builtin/project/add/fastapp_template/schema/user.py +31 -0
  62. zrb/builtin/project/add/fastapp_template/template.env +2 -0
  63. zrb/builtin/project/create/__init__.py +0 -0
  64. zrb/builtin/project/create/create.py +41 -0
  65. zrb/builtin/project/create/project-template/README.md +3 -0
  66. zrb/builtin/project/create/project-template/zrb_init.py +7 -0
  67. zrb/builtin/python.py +11 -0
  68. zrb/builtin/shell/__init__.py +0 -5
  69. zrb/builtin/shell/autocomplete/__init__.py +0 -9
  70. zrb/builtin/shell/autocomplete/bash.py +5 -6
  71. zrb/builtin/shell/autocomplete/subcmd.py +7 -8
  72. zrb/builtin/shell/autocomplete/zsh.py +5 -6
  73. zrb/builtin/todo.py +186 -0
  74. zrb/callback/any_callback.py +1 -1
  75. zrb/callback/callback.py +5 -5
  76. zrb/cmd/cmd_val.py +2 -2
  77. zrb/config.py +4 -1
  78. zrb/content_transformer/any_content_transformer.py +1 -1
  79. zrb/content_transformer/content_transformer.py +2 -2
  80. zrb/context/any_context.py +5 -1
  81. zrb/context/any_shared_context.py +3 -3
  82. zrb/context/context.py +15 -9
  83. zrb/context/shared_context.py +9 -8
  84. zrb/env/__init__.py +0 -3
  85. zrb/env/any_env.py +2 -2
  86. zrb/env/env.py +4 -5
  87. zrb/env/env_file.py +4 -4
  88. zrb/env/env_map.py +4 -4
  89. zrb/group/__init__.py +0 -3
  90. zrb/group/any_group.py +3 -3
  91. zrb/group/group.py +7 -6
  92. zrb/input/any_input.py +1 -1
  93. zrb/input/base_input.py +4 -4
  94. zrb/input/bool_input.py +5 -5
  95. zrb/input/float_input.py +3 -3
  96. zrb/input/int_input.py +3 -3
  97. zrb/input/option_input.py +51 -0
  98. zrb/input/password_input.py +2 -2
  99. zrb/input/str_input.py +1 -1
  100. zrb/input/text_input.py +12 -10
  101. zrb/runner/cli.py +79 -44
  102. zrb/runner/web_app/group_info_ui/controller.py +7 -8
  103. zrb/runner/web_app/group_info_ui/view.html +2 -2
  104. zrb/runner/web_app/home_page/controller.py +7 -6
  105. zrb/runner/web_app/home_page/view.html +2 -2
  106. zrb/runner/web_app/task_ui/controller.py +13 -13
  107. zrb/runner/web_app/task_ui/partial/common-util.js +37 -0
  108. zrb/runner/web_app/task_ui/partial/main.js +9 -2
  109. zrb/runner/web_app/task_ui/partial/show-existing-session.js +20 -5
  110. zrb/runner/web_app/task_ui/partial/visualize-history.js +1 -41
  111. zrb/runner/web_app/task_ui/view.html +4 -2
  112. zrb/runner/web_server.py +137 -211
  113. zrb/runner/web_util.py +5 -35
  114. zrb/session/any_session.py +13 -7
  115. zrb/session/session.py +80 -41
  116. zrb/session_state_log/session_state_log.py +7 -5
  117. zrb/session_state_logger/any_session_state_logger.py +1 -1
  118. zrb/session_state_logger/default_session_state_logger.py +2 -2
  119. zrb/session_state_logger/file_session_state_logger.py +19 -27
  120. zrb/task/any_task.py +8 -3
  121. zrb/task/base_task.py +47 -33
  122. zrb/task/base_trigger.py +11 -12
  123. zrb/task/cmd_task.py +55 -43
  124. zrb/task/http_check.py +8 -8
  125. zrb/task/llm_task.py +160 -0
  126. zrb/task/make_task.py +9 -9
  127. zrb/task/rsync_task.py +7 -7
  128. zrb/task/scaffolder.py +14 -11
  129. zrb/task/scheduler.py +6 -7
  130. zrb/task/task.py +1 -1
  131. zrb/task/tcp_check.py +8 -8
  132. zrb/util/attr.py +19 -3
  133. zrb/util/cli/style.py +71 -2
  134. zrb/util/cli/subcommand.py +2 -2
  135. zrb/util/codemod/__init__.py +0 -0
  136. zrb/util/codemod/add_code_to_class.py +35 -0
  137. zrb/util/codemod/add_code_to_function.py +36 -0
  138. zrb/util/codemod/add_code_to_method.py +55 -0
  139. zrb/util/codemod/add_key_to_dict.py +51 -0
  140. zrb/util/codemod/add_param_to_function_call.py +39 -0
  141. zrb/util/codemod/add_property_to_class.py +55 -0
  142. zrb/util/git.py +156 -0
  143. zrb/util/git_subtree.py +94 -0
  144. zrb/util/group.py +2 -2
  145. zrb/util/llm/tool.py +63 -0
  146. zrb/util/string/conversion.py +7 -0
  147. zrb/util/todo.py +135 -0
  148. {zrb-1.0.0a1.dist-info → zrb-1.0.0a3.dist-info}/METADATA +11 -7
  149. zrb-1.0.0a3.dist-info/RECORD +194 -0
  150. zrb/builtin/shell/_group.py +0 -9
  151. zrb/builtin/shell/autocomplete/_group.py +0 -6
  152. zrb/runner/web_app/any_request_handler.py +0 -24
  153. zrb/runner/web_server.bak.py +0 -208
  154. zrb-1.0.0a1.dist-info/RECORD +0 -120
  155. {zrb-1.0.0a1.dist-info → zrb-1.0.0a3.dist-info}/WHEEL +0 -0
  156. {zrb-1.0.0a1.dist-info → zrb-1.0.0a3.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,39 @@
1
+ from fastapp_template.common.db_repository import BaseDBRepository
2
+ from fastapp_template.common.error import NotFoundError
3
+ from fastapp_template.module.auth.service.user.repository.repository import (
4
+ UserRepository,
5
+ )
6
+ from fastapp_template.schema.user import User, UserCreate, UserResponse, UserUpdate
7
+ from passlib.context import CryptContext
8
+ from sqlalchemy.ext.asyncio import AsyncSession
9
+ from sqlmodel import Session, select
10
+
11
+ # Password hashing context
12
+ pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
13
+
14
+
15
+ def hash_password(password: str) -> str:
16
+ return pwd_context.hash(password)
17
+
18
+
19
+ class UserDBRepository(
20
+ BaseDBRepository[User, UserResponse, UserCreate, UserUpdate], UserRepository
21
+ ):
22
+ db_model = User
23
+ response_model = UserResponse
24
+ create_model = UserCreate
25
+ update_model = UserUpdate
26
+ entity_name = "user"
27
+ column_preprocessors = {"password": hash_password}
28
+
29
+ async def get_by_credentials(self, username: str, password: str) -> UserResponse:
30
+ statement = select(User).where(User.username == username)
31
+ if self.is_async:
32
+ async with AsyncSession(self.engine) as session:
33
+ user = await session.exec(statement).first
34
+ else:
35
+ with Session(self.engine) as session:
36
+ user = session.exec(statement).first()
37
+ if not user or not pwd_context.verify(password, user.hashed_password):
38
+ raise NotFoundError(f"{self.entity_name} not found")
39
+ return self._to_response(user)
@@ -0,0 +1,13 @@
1
+ from fastapp_template.common.db_engine import engine
2
+ from fastapp_template.config import APP_REPOSITORY_TYPE
3
+ from fastapp_template.module.auth.service.user.repository.db_repository import (
4
+ UserDBRepository,
5
+ )
6
+ from fastapp_template.module.auth.service.user.repository.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
@@ -0,0 +1,34 @@
1
+ from abc import ABC, abstractmethod
2
+
3
+ from fastapp_template.schema.user import User, UserCreate, UserResponse, UserUpdate
4
+
5
+
6
+ class UserRepository(ABC):
7
+
8
+ @abstractmethod
9
+ async def create(self, user_data: UserCreate) -> UserResponse:
10
+ pass
11
+
12
+ @abstractmethod
13
+ async def get_by_id(self, user_id: str) -> User:
14
+ pass
15
+
16
+ @abstractmethod
17
+ async def get_all(self) -> list[User]:
18
+ pass
19
+
20
+ @abstractmethod
21
+ async def update(self, user_id: str, user_data: UserUpdate) -> User:
22
+ pass
23
+
24
+ @abstractmethod
25
+ async def delete(self, user_id: str) -> User:
26
+ pass
27
+
28
+ @abstractmethod
29
+ async def create_bulk(self, user_data_list: list[UserCreate]) -> list[UserResponse]:
30
+ pass
31
+
32
+ @abstractmethod
33
+ async def get_by_credentials(self, username: str, password: str) -> UserResponse:
34
+ pass
@@ -0,0 +1,45 @@
1
+ from fastapp_template.common.usecase import BaseUsecase
2
+ from fastapp_template.module.auth.service.user.repository.factory import user_repository
3
+ from fastapp_template.schema.user import UserCreate, UserResponse, UserUpdate
4
+
5
+
6
+ class UserUsecase(BaseUsecase):
7
+
8
+ @BaseUsecase.route(
9
+ "/api/v1/users/{user_id}", methods=["get"], response_model=UserResponse
10
+ )
11
+ async def get_user_by_id(self, user_id: str) -> UserResponse:
12
+ return await user_repository.get_by_id(user_id)
13
+
14
+ @BaseUsecase.route(
15
+ "/api/v1/users", methods=["get"], response_model=list[UserResponse]
16
+ )
17
+ async def get_all_users(self) -> list[UserResponse]:
18
+ return await user_repository.get_all()
19
+
20
+ @BaseUsecase.route(
21
+ "/api/v1/users",
22
+ methods=["post"],
23
+ response_model=UserResponse | list[UserResponse],
24
+ )
25
+ async def create_user(
26
+ self, data: UserCreate | list[UserCreate]
27
+ ) -> UserResponse | list[UserResponse]:
28
+ if isinstance(data, UserCreate):
29
+ return await user_repository.create(data)
30
+ return await user_repository.create_bulk(data)
31
+
32
+ @BaseUsecase.route(
33
+ "/api/v1/users/{user_id}", methods=["put"], response_model=UserResponse
34
+ )
35
+ async def update_user(self, user_id: str, data: UserUpdate) -> UserResponse:
36
+ return await user_repository.update(user_id, data)
37
+
38
+ @BaseUsecase.route(
39
+ "/api/v1/users/{user_id}", methods=["delete"], response_model=UserResponse
40
+ )
41
+ async def delete_user(self, user_id: str) -> UserResponse:
42
+ return await user_repository.delete(user_id)
43
+
44
+
45
+ user_usecase = UserUsecase()
@@ -0,0 +1,117 @@
1
+ # A generic, single database configuration.
2
+
3
+ [alembic]
4
+ # path to migration scripts
5
+ # Use forward slashes (/) also on windows to provide an os agnostic path
6
+ script_location = migration
7
+
8
+ # template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
9
+ # Uncomment the line below if you want the files to be prepended with date and time
10
+ # see https://alembic.sqlalchemy.org/en/latest/tutorial.html#editing-the-ini-file
11
+ # for all available tokens
12
+ # file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s
13
+
14
+ # sys.path path, will be prepended to sys.path if present.
15
+ # defaults to the current working directory.
16
+ prepend_sys_path = ../..
17
+
18
+ # timezone to use when rendering the date within the migration file
19
+ # as well as the filename.
20
+ # If specified, requires the python>=3.9 or backports.zoneinfo library.
21
+ # Any required deps can installed by adding `alembic[tz]` to the pip requirements
22
+ # string value is passed to ZoneInfo()
23
+ # leave blank for localtime
24
+ # timezone =
25
+
26
+ # max length of characters to apply to the "slug" field
27
+ # truncate_slug_length = 40
28
+
29
+ # set to 'true' to run the environment during
30
+ # the 'revision' command, regardless of autogenerate
31
+ # revision_environment = false
32
+
33
+ # set to 'true' to allow .pyc and .pyo files without
34
+ # a source .py file to be detected as revisions in the
35
+ # versions/ directory
36
+ # sourceless = false
37
+
38
+ # version location specification; This defaults
39
+ # to migration/versions. When using multiple version
40
+ # directories, initial revisions must be specified with --version-path.
41
+ # The path separator used here should be the separator specified by "version_path_separator" below.
42
+ # version_locations = %(here)s/bar:%(here)s/bat:migration/versions
43
+
44
+ # version path separator; As mentioned above, this is the character used to split
45
+ # version_locations. The default within new alembic.ini files is "os", which uses os.pathsep.
46
+ # If this key is omitted entirely, it falls back to the legacy behavior of splitting on spaces and/or commas.
47
+ # Valid values for version_path_separator are:
48
+ #
49
+ # version_path_separator = :
50
+ # version_path_separator = ;
51
+ # version_path_separator = space
52
+ # version_path_separator = newline
53
+ version_path_separator = os # Use os.pathsep. Default configuration used for new projects.
54
+
55
+ # set to 'true' to search source files recursively
56
+ # in each "version_locations" directory
57
+ # new in Alembic version 1.10
58
+ # recursive_version_locations = false
59
+
60
+ # the output encoding used when revision files
61
+ # are written from script.py.mako
62
+ # output_encoding = utf-8
63
+
64
+ sqlalchemy.url = driver://user:pass@localhost/dbname
65
+
66
+
67
+ [post_write_hooks]
68
+ # post_write_hooks defines scripts or Python functions that are run
69
+ # on newly generated revision scripts. See the documentation for further
70
+ # detail and examples
71
+
72
+ # format using "black" - use the console_scripts runner, against the "black" entrypoint
73
+ # hooks = black
74
+ # black.type = console_scripts
75
+ # black.entrypoint = black
76
+ # black.options = -l 79 REVISION_SCRIPT_FILENAME
77
+
78
+ # lint with attempts to fix using "ruff" - use the exec runner, execute a binary
79
+ # hooks = ruff
80
+ # ruff.type = exec
81
+ # ruff.executable = %(here)s/.venv/bin/ruff
82
+ # ruff.options = --fix REVISION_SCRIPT_FILENAME
83
+
84
+ # Logging configuration
85
+ [loggers]
86
+ keys = root,sqlalchemy,alembic
87
+
88
+ [handlers]
89
+ keys = console
90
+
91
+ [formatters]
92
+ keys = generic
93
+
94
+ [logger_root]
95
+ level = WARNING
96
+ handlers = console
97
+ qualname =
98
+
99
+ [logger_sqlalchemy]
100
+ level = WARNING
101
+ handlers =
102
+ qualname = sqlalchemy.engine
103
+
104
+ [logger_alembic]
105
+ level = INFO
106
+ handlers =
107
+ qualname = alembic
108
+
109
+ [handler_console]
110
+ class = StreamHandler
111
+ args = (sys.stderr,)
112
+ level = NOTSET
113
+ formatter = generic
114
+
115
+ [formatter_generic]
116
+ format = %(levelname)-5.5s [%(name)s] %(message)s
117
+ datefmt = %H:%M:%S
@@ -0,0 +1 @@
1
+ Generic single-database configuration.
@@ -0,0 +1,108 @@
1
+ from logging.config import fileConfig
2
+
3
+ from alembic import context
4
+ from fastapp_template.config import APP_DB_URL
5
+ from fastapp_template.module.gateway.migration_metadata import metadata
6
+ from sqlalchemy import engine_from_config, pool
7
+
8
+ # this is the Alembic Config object, which provides
9
+ # access to the values within the .ini file in use.
10
+ config = context.config
11
+
12
+ # 🔥 FastApp Modification
13
+ MIGRATION_TABLE = "_migration_gateway"
14
+ # 🔥 FastApp Modification
15
+ config.set_section_option(config.config_ini_section, "sqlalchemy.url", APP_DB_URL)
16
+
17
+ # Interpret the config file for Python logging.
18
+ # This line sets up loggers basically.
19
+ if config.config_file_name is not None:
20
+ fileConfig(config.config_file_name)
21
+
22
+ # add your model's MetaData object here
23
+ # for 'autogenerate' support
24
+ # from myapp import mymodel
25
+ # target_metadata = mymodel.Base.metadata
26
+ target_metadata = metadata
27
+
28
+ # other values from the config, defined by the needs of env.py,
29
+ # can be acquired:
30
+ # my_important_option = config.get_main_option("my_important_option")
31
+ # ... etc.
32
+
33
+
34
+ # 🔥 FastApp Modification
35
+ def include_object(object, name, type_, reflected, compare_to):
36
+ """
37
+ Filter which objects Alembic should include in migrations.
38
+ Args:
39
+ object: The SQLAlchemy object (table, column, etc.)
40
+ name: The name of the object
41
+ type_: The type of the object ("table", "column", etc.)
42
+ reflected: True if the object is reflected from the database
43
+ compare_to: The object being compared against
44
+ Returns:
45
+ bool: True to include, False to exclude
46
+ """
47
+ # Exclude tables not in metadata
48
+ if type_ == "table" and name not in target_metadata.tables:
49
+ return False # Skip this table
50
+ return True
51
+
52
+
53
+ def run_migrations_offline() -> None:
54
+ """Run migrations in 'offline' mode.
55
+
56
+ This configures the context with just a URL
57
+ and not an Engine, though an Engine is acceptable
58
+ here as well. By skipping the Engine creation
59
+ we don't even need a DBAPI to be available.
60
+
61
+ Calls to context.execute() here emit the given string to the
62
+ script output.
63
+
64
+ """
65
+ url = config.get_main_option("sqlalchemy.url")
66
+ context.configure(
67
+ url=url,
68
+ target_metadata=target_metadata,
69
+ literal_binds=True,
70
+ dialect_opts={"paramstyle": "named"},
71
+ imports=["import sqlmodel"], # 🔥 FastApp Modification
72
+ version_table=MIGRATION_TABLE, # 🔥 FastApp Modification
73
+ include_object=include_object, # 🔥 FastApp Modification
74
+ )
75
+
76
+ with context.begin_transaction():
77
+ context.run_migrations()
78
+
79
+
80
+ def run_migrations_online() -> None:
81
+ """Run migrations in 'online' mode.
82
+
83
+ In this scenario we need to create an Engine
84
+ and associate a connection with the context.
85
+
86
+ """
87
+ connectable = engine_from_config(
88
+ config.get_section(config.config_ini_section, {}),
89
+ prefix="sqlalchemy.",
90
+ poolclass=pool.NullPool,
91
+ )
92
+
93
+ with connectable.connect() as connection:
94
+ context.configure(
95
+ connection=connection,
96
+ target_metadata=target_metadata,
97
+ imports=["import sqlmodel"], # 🔥 FastApp Modification
98
+ version_table=MIGRATION_TABLE, # 🔥 FastApp Modification
99
+ include_object=include_object, # 🔥 FastApp Modification
100
+ )
101
+ with context.begin_transaction():
102
+ context.run_migrations()
103
+
104
+
105
+ if context.is_offline_mode():
106
+ run_migrations_offline()
107
+ else:
108
+ run_migrations_online()
@@ -0,0 +1,26 @@
1
+ """${message}
2
+
3
+ Revision ID: ${up_revision}
4
+ Revises: ${down_revision | comma,n}
5
+ Create Date: ${create_date}
6
+
7
+ """
8
+ from typing import Sequence, Union
9
+
10
+ from alembic import op
11
+ import sqlalchemy as sa
12
+ ${imports if imports else ""}
13
+
14
+ # revision identifiers, used by Alembic.
15
+ revision: str = ${repr(up_revision)}
16
+ down_revision: Union[str, None] = ${repr(down_revision)}
17
+ branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
18
+ depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}
19
+
20
+
21
+ def upgrade() -> None:
22
+ ${upgrades if upgrades else "pass"}
23
+
24
+
25
+ def downgrade() -> None:
26
+ ${downgrades if downgrades else "pass"}
@@ -0,0 +1,3 @@
1
+ from sqlalchemy import MetaData
2
+
3
+ metadata = MetaData()
@@ -0,0 +1,27 @@
1
+ from fastapp_template.common.app import app
2
+ from fastapp_template.common.schema import BasicResponse
3
+ from fastapp_template.config import APP_MODE, APP_MODULES
4
+ from fastapp_template.module.auth.client.factory import client as auth_client
5
+ from fastapp_template.schema.user import UserCreate, UserResponse
6
+
7
+ if APP_MODE == "monolith" or "gateway" in APP_MODULES:
8
+
9
+ if APP_MODE == "monolith" or (len(APP_MODULES) > 0 and APP_MODULES[0] == "gateway"):
10
+
11
+ @app.api_route("/health", methods=["GET", "HEAD"], response_model=BasicResponse)
12
+ async def health():
13
+ return BasicResponse(message="ok")
14
+
15
+ @app.api_route(
16
+ "/readiness", methods=["GET", "HEAD"], response_model=BasicResponse
17
+ )
18
+ async def readiness():
19
+ return BasicResponse(message="ok")
20
+
21
+ @app.get("/api/v1/users", response_model=list[UserResponse])
22
+ async def auth_get_all_users() -> UserResponse:
23
+ return await auth_client.get_all_users()
24
+
25
+ @app.post("/api/v1/users", response_model=UserResponse | list[UserResponse])
26
+ async def auth_create_user(data: UserCreate | list[UserCreate]):
27
+ return await auth_client.create_user(data)
@@ -0,0 +1,6 @@
1
+ fastapi[standard]==0.115.4
2
+ aiosqlite==0.20.0
3
+ alembic==1.14.0
4
+ sqlmodel==0.0.22
5
+ ulid-py==1.1.0
6
+ passlib==1.7.4
@@ -0,0 +1,31 @@
1
+ import datetime
2
+
3
+ import ulid
4
+ from sqlmodel import Field, SQLModel
5
+
6
+
7
+ class RoleBase(SQLModel):
8
+ name: str
9
+
10
+
11
+ class RoleCreate(RoleBase):
12
+ description: str
13
+
14
+
15
+ class RoleUpdate(SQLModel):
16
+ name: str | None = None
17
+ description: str | None = None
18
+
19
+
20
+ class RoleResponse(RoleBase):
21
+ id: str
22
+
23
+
24
+ class Role(SQLModel, table=True):
25
+ id: str = Field(default_factory=lambda: ulid.new().str, primary_key=True)
26
+ created_at: datetime.datetime | None
27
+ created_by: str | None
28
+ updated_at: datetime.datetime | None
29
+ updated_by: str | None
30
+ name: str
31
+ description: str
@@ -0,0 +1,31 @@
1
+ import datetime
2
+
3
+ import ulid
4
+ from sqlmodel import Field, SQLModel
5
+
6
+
7
+ class UserBase(SQLModel):
8
+ username: str
9
+
10
+
11
+ class UserCreate(UserBase):
12
+ password: str
13
+
14
+
15
+ class UserUpdate(SQLModel):
16
+ username: str | None = None
17
+ password: str | None = None
18
+
19
+
20
+ class UserResponse(UserBase):
21
+ id: str
22
+
23
+
24
+ class User(SQLModel, table=True):
25
+ id: str = Field(default_factory=lambda: ulid.new().str, primary_key=True)
26
+ created_at: datetime.datetime
27
+ created_by: str
28
+ updated_at: datetime.datetime
29
+ updated_by: str
30
+ username: str
31
+ password: str
@@ -0,0 +1,2 @@
1
+ export APP_NAME_MODE=monolith
2
+ export APP_NAME_PORT=3000
File without changes
@@ -0,0 +1,41 @@
1
+ import os
2
+
3
+ from zrb.builtin.group import project_group
4
+ from zrb.input.str_input import StrInput
5
+ from zrb.task.scaffolder import Scaffolder
6
+ from zrb.task.task import Task
7
+
8
+ _DIR = os.path.dirname(__file__)
9
+
10
+ scaffold_project = Scaffolder(
11
+ name="scaffold-project",
12
+ description="🌟 Create project",
13
+ input=[
14
+ StrInput(
15
+ name="project-dir",
16
+ description="Project directory",
17
+ prompt="Project directory",
18
+ default_str=lambda _: os.getcwd(),
19
+ ),
20
+ StrInput(
21
+ name="project-name",
22
+ description="Project name",
23
+ prompt="Project name",
24
+ default_str=lambda ctx: os.path.basename(ctx.input["project-dir"]),
25
+ ),
26
+ ],
27
+ source_path=os.path.join(_DIR, "project-template"),
28
+ auto_render_source_path=False,
29
+ destination_path="{ctx.input['project-dir']}",
30
+ transform_content={"Project Name": "{ctx.input['project-name'].title()}"},
31
+ retries=0,
32
+ )
33
+
34
+ create_project = project_group.add_task(
35
+ Task(
36
+ name="create-project",
37
+ description="🌟 Create project",
38
+ ),
39
+ alias="create",
40
+ )
41
+ scaffold_project >> create_project
@@ -0,0 +1,3 @@
1
+ # Project Name
2
+
3
+ Welcome to Project Name
@@ -0,0 +1,7 @@
1
+ import os
2
+
3
+ from zrb import load_file
4
+
5
+ _DIR = os.path.dirname(__file__)
6
+
7
+ assert load_file
zrb/builtin/python.py ADDED
@@ -0,0 +1,11 @@
1
+ from zrb.builtin.group import python_group
2
+ from zrb.task.cmd_task import CmdTask
3
+
4
+ format_python_code = python_group.add_task(
5
+ CmdTask(
6
+ name="format-code",
7
+ description="✏️ Format Python code",
8
+ cmd=["isort .", "black ."],
9
+ ),
10
+ alias="format",
11
+ )
@@ -1,5 +0,0 @@
1
- from . import autocomplete
2
- from ._group import shell_group
3
-
4
- assert autocomplete
5
- assert shell_group
@@ -1,9 +0,0 @@
1
- from ._group import shell_autocomplete_group
2
- from .bash import make_bash_autocomplete
3
- from .subcmd import get_shell_subcommands
4
- from .zsh import make_zsh_autocomplete
5
-
6
- assert shell_autocomplete_group
7
- assert make_bash_autocomplete
8
- assert make_zsh_autocomplete
9
- assert get_shell_subcommands
@@ -1,6 +1,6 @@
1
- from ....context.context import Context
2
- from ....task.make_task import make_task
3
- from ._group import shell_autocomplete_group
1
+ from zrb.builtin.group import shell_autocomplete_group
2
+ from zrb.context.context import Context
3
+ from zrb.task.make_task import make_task
4
4
 
5
5
  _COMPLETION_SCRIPT = """
6
6
  # Bash dynamic completion script
@@ -33,9 +33,8 @@ complete -F _zrb_complete zrb
33
33
  @make_task(
34
34
  name="make-bash-autocomplete",
35
35
  description="Create Zrb autocomplete script for bash",
36
+ group=shell_autocomplete_group,
37
+ alias="bash",
36
38
  )
37
39
  def make_bash_autocomplete(ctx: Context):
38
40
  return _COMPLETION_SCRIPT
39
-
40
-
41
- shell_autocomplete_group.add_task(make_bash_autocomplete, "bash")
@@ -1,13 +1,15 @@
1
- from ....context.context import Context
2
- from ....runner.cli import cli
3
- from ....task.make_task import make_task
4
- from ....util.cli.subcommand import get_group_subcommands
5
- from ._group import shell_autocomplete_group
1
+ from zrb.builtin.group import shell_autocomplete_group
2
+ from zrb.context.context import Context
3
+ from zrb.runner.cli import cli
4
+ from zrb.task.make_task import make_task
5
+ from zrb.util.cli.subcommand import get_group_subcommands
6
6
 
7
7
 
8
8
  @make_task(
9
9
  name="get-shell-subcommands",
10
10
  description="Get subcommand of any Zrb command",
11
+ group=shell_autocomplete_group,
12
+ alias="subcmd",
11
13
  )
12
14
  def get_shell_subcommands(ctx: Context):
13
15
  subcommands = get_group_subcommands(cli)
@@ -15,6 +17,3 @@ def get_shell_subcommands(ctx: Context):
15
17
  if subcommand.paths == ctx.args:
16
18
  return " ".join(subcommand.nexts)
17
19
  return ""
18
-
19
-
20
- shell_autocomplete_group.add_task(get_shell_subcommands, "subcmd")
@@ -1,6 +1,6 @@
1
- from ....context.context import Context
2
- from ....task.make_task import make_task
3
- from ._group import shell_autocomplete_group
1
+ from zrb.builtin.group import shell_autocomplete_group
2
+ from zrb.context.context import Context
3
+ from zrb.task.make_task import make_task
4
4
 
5
5
  _COMPLETION_SCRIPT = """
6
6
  # Zsh dynamic completion script
@@ -30,9 +30,8 @@ compdef _zrb_complete zrb
30
30
  @make_task(
31
31
  name="make-zsh-autocomplete",
32
32
  description="Create Zrb autocomplete script for zsh",
33
+ group=shell_autocomplete_group,
34
+ alias="zsh",
33
35
  )
34
36
  def make_zsh_autocomplete(ctx: Context):
35
37
  return _COMPLETION_SCRIPT
36
-
37
-
38
- shell_autocomplete_group.add_task(make_zsh_autocomplete, "zsh")