Skip to content

Commit

Permalink
Fix some (but not all) bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
goFrendiAsgard committed Dec 14, 2024
1 parent 6f3eb5f commit bfe1bd2
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ async def validate_create_my_app_name_entity(ctx: AnyContext):
"my_entities": "{to_snake_case(ctx.input.plural)}",
"my-entities": "{to_kebab_case(ctx.input.plural)}",
},
transform_path={
"my_entity": "{to_snake_case(ctx.input.entity)}",
},
retries=0,
upstream=validate_create_my_app_name_entity,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from fastapp_template.module.my_module.service.my_entity.repository.factory import (
my_entity_repository,
)
from fastapp_template.module.my_module.service.my_entity.repository.repository import (
from fastapp_template.module.my_module.service.my_entity.repository.my_entity_repository import (
MyEntityRepository,
)
from fastapp_template.schema.my_entity import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ async def validate_create_my_app_name_module(ctx: AnyContext):
),
transform_content={
"module_template": "{to_snake_case(ctx.input.module)}",
"MY_MODULE_NAME": "{to_snake_case(ctx.input.module).upper()}",
"MY_MODULE": "{to_snake_case(ctx.input.module).upper()}",
"my_module": "{to_snake_case(ctx.input.module)}",
},
retries=0,
upstream=validate_create_my_app_name_module,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from fastapp_template.config import APP_MY_MODULE_NAME_BASE_URL
from fastapp_template.config import APP_MY_MODULE_BASE_URL
from fastapp_template.module.module_template.client.any_client import BaseClient


Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@

def serve_route():
if APP_MODE == "microservices" and (
len(APP_MODULES) > 0 and APP_MODULES[0] == "auth"
len(APP_MODULES) > 0 and APP_MODULES[0] == "my_module"
):
"""
To make sure health/readiness check is only served once,
the following will only run if this application run as a my_module microservice
"""

@app.api_route("/health", methods=["GET", "HEAD"], response_model=BasicResponse)
async def health():
Expand All @@ -19,5 +23,10 @@ async def readiness():
return BasicResponse(message="ok")


if APP_MODE == "microservices" and "auth" in APP_MODULES:
if APP_MODE == "monolith" or "my_module" in APP_MODULES:
"""
Will only serve route if one of these conditions is true:
- This application run as a monolith
- This application run as as a my_module microservice
"""
serve_route()
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import inspect
from enum import Enum
from functools import partial, wraps
from typing import Any, Callable, Sequence
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ def serve_route():
if APP_MODE == "microservices" and (
len(APP_MODULES) > 0 and APP_MODULES[0] == "auth"
):
"""
To make sure health/readiness check is only served once,
the following will only run if this application run as an auth microservice
"""

@app.api_route("/health", methods=["GET", "HEAD"], response_model=BasicResponse)
async def health():
Expand All @@ -22,5 +26,10 @@ async def readiness():
user_usecase.serve_route(app)


if APP_MODE == "microservices" and "auth" in APP_MODULES:
if APP_MODE == "monolith" or "auth" in APP_MODULES:
"""
Will only serve route if one of these conditions is true:
- This application run as a monolith
- This application run as as an auth microservice
"""
serve_route()
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

def serve_route():
if APP_MODE == "monolith" or (len(APP_MODULES) > 0 and APP_MODULES[0] == "gateway"):
"""
To make sure health/readiness check is only served once,
the following will only run if one of these conditions is true:
- This application run as a monolith
- This application run as a gateway microservice
"""

@app.api_route("/health", methods=["GET", "HEAD"], response_model=BasicResponse)
async def health():
Expand All @@ -28,4 +34,9 @@ async def auth_create_user(data: UserCreate | list[UserCreate]):


if APP_MODE == "monolith" or "gateway" in APP_MODULES:
"""
Will only serve route if one of these conditions is true:
- This application run as a monolith
- This application run as as a gateway microservice
"""
serve_route()
14 changes: 13 additions & 1 deletion src/zrb/task/scaffolder.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ def __init__(
destination_path: StrAttr | None = None,
render_destination_path: bool = True,
transform_path: TransformConfig = {},
render_transform_path: bool = True,
transform_content: (
list[AnyContentTransformer] | AnyContentTransformer | TransformConfig
) = [],
render_transform_content: bool = True,
execute_condition: BoolAttr = True,
retries: int = 2,
retry_period: float = 0,
Expand Down Expand Up @@ -70,7 +72,9 @@ def __init__(
self._destination_path = destination_path
self._render_destination_path = render_destination_path
self._content_transformers = transform_content
self._render_content_transformers = render_transform_content
self._path_transformer = transform_path
self._render_path_transformer = render_transform_path

def _get_source_path(self, ctx: AnyContext) -> str:
return get_str_attr(ctx, self._source_path, "", auto_render=True)
Expand All @@ -82,7 +86,13 @@ def _get_content_transformers(self) -> list[AnyContentTransformer]:
if callable(self._content_transformers):
return [ContentTransformer(match="*", transform=self._content_transformers)]
if isinstance(self._content_transformers, dict):
return [ContentTransformer(match="*", transform=self._content_transformers)]
return [
ContentTransformer(
match="*",
transform=self._content_transformers,
auto_render=self._render_content_transformers,
)
]
if isinstance(self._content_transformers, AnyContentTransformer):
return [self._content_transformers]
return self._content_transformers
Expand Down Expand Up @@ -128,6 +138,8 @@ def _transform_path(self, ctx: AnyContext, file_path: str):
return self._path_transformer(ctx, file_path)
new_file_path = file_path
for keyword, replacement in self._path_transformer.items():
if self._render_path_transformer:
replacement = ctx.render(replacement)
new_file_path = new_file_path.replace(keyword, replacement)
return new_file_path

Expand Down
5 changes: 3 additions & 2 deletions zrb_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
description="🔨 Test generate fastapp",
group=test_group,
alias="generate",
retries=0,
)
async def test_generate(ctx: AnyContext):
# Create project
Expand Down Expand Up @@ -216,8 +217,8 @@ async def test_generate(ctx: AnyContext):
)
# Start microservices
await run_cmd_test(
name="run-microservices",
cmd="zrb project fastapp run microservices",
name="run-all",
cmd="zrb project fastapp run all",
)


Expand Down

0 comments on commit bfe1bd2

Please sign in to comment.