Skip to content

Commit

Permalink
style: formatted scaffold and helper code
Browse files Browse the repository at this point in the history
  • Loading branch information
ashupednekar committed Sep 26, 2024
1 parent 09b9262 commit 2a16aff
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
20 changes: 16 additions & 4 deletions robyn/helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from typing import Any, Type, Tuple
from pydantic_settings import BaseSettings, EnvSettingsSource, PydanticBaseSettingsSource
from pydantic_settings import (
BaseSettings,
EnvSettingsSource,
PydanticBaseSettingsSource,
)
from pydantic import ConfigDict

import importlib
Expand All @@ -14,16 +18,24 @@
def discover_routes(handler_path: str = "api.handlers") -> Robyn:
mux: Robyn = Robyn(__file__)
package = importlib.import_module(handler_path)
for _, module_name, _ in pkgutil.iter_modules(package.__path__, package.__name__ + "."):
for _, module_name, _ in pkgutil.iter_modules(
package.__path__, package.__name__ + "."
):
module = importlib.import_module(module_name)
logger.info(f"member: {module}")
mux.include_router(module.router)
return mux


class AcceptArrayEnvsSource(EnvSettingsSource):
def prepare_field_value(self, field_name: str, field: Any, value: Any, value_is_complex: bool) -> Any:
if isinstance(field.annotation, type) and issubclass(field.annotation, list) and isinstance(value, str):
def prepare_field_value(
self, field_name: str, field: Any, value: Any, value_is_complex: bool
) -> Any:
if (
isinstance(field.annotation, type)
and issubclass(field.annotation, list)
and isinstance(value, str)
):
return [x.strip() for x in value.split(",") if x]
return value

Expand Down
4 changes: 3 additions & 1 deletion robyn/scaffold/simple/postgres/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
DB_PASS = "password"
DB_PORT = "5455"

conn = psycopg2.connect(database=DB_NAME, host=DB_HOST, user=DB_USER, password=DB_PASS, port=DB_PORT)
conn = psycopg2.connect(
database=DB_NAME, host=DB_HOST, user=DB_USER, password=DB_PASS, port=DB_PORT
)

app = Robyn(__file__)

Expand Down
6 changes: 4 additions & 2 deletions robyn/scaffold/structured/no-db/api/handlers/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
class SampleHandlers:
@router.post("/one")
@staticmethod
def one(): ...
def one():
...

@router.get("/two")
@staticmethod
def two(): ...
def two():
...
6 changes: 4 additions & 2 deletions robyn/scaffold/structured/sqlalchemy/api/handlers/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
class SampleHandlers:
@router.post("/one")
@staticmethod
def one(): ...
def one():
...

@router.get("/two")
@staticmethod
def two(): ...
def two():
...
4 changes: 3 additions & 1 deletion robyn/scaffold/structured/sqlalchemy/migrations/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ def run_migrations_online() -> None:
"""
with get_pool() as session:
context.configure(connection=session.connection(), target_metadata=target_metadata)
context.configure(
connection=session.connection(), target_metadata=target_metadata
)
with context.begin_transaction():
context.run_migrations()

Expand Down

0 comments on commit 2a16aff

Please sign in to comment.