-
-
Notifications
You must be signed in to change notification settings - Fork 221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support for structured scaffold in create command #970
Open
ashupednekar
wants to merge
41
commits into
sparckles:main
Choose a base branch
from
ashupednekar:feat_structured_scaffold
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+593
−16
Open
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
9828c99
feat: added simple/structured scaffolding
ashupednekar 56e174a
chore: adding auto discover routes
ashupednekar 03918ac
chore: added discover routes
ashupednekar 10d3c83
chore: updated server
ashupednekar 0baab2b
feat: finished no db scaffolding
ashupednekar 481bed8
chore: copied over no db stuff to db
ashupednekar c0c5dd4
chore: added db connection pool and envs to sqlalchemy structured sca…
ashupednekar a4c2730
feat: added sqlalchemy and pydantic example models to scaffold
ashupednekar e98ce50
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] cdcb947
feat: added alembic migration support
ashupednekar 6005967
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 095916f
Merge branch 'sparckles:main' into feat_structured_scaffold
ashupednekar 832bd8f
feat: added alembic migration setup to sqlalchemy structured scaffold
ashupednekar 09b9262
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 2a16aff
style: formatted scaffold and helper code
ashupednekar a4b49b1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 25840fa
dep: added sqlalchemy dep to scaffolding
ashupednekar 6f2e58c
dep: added alembic to req in scaffold
ashupednekar 4922b1a
dep: added psycopg2 binary to dep in scaffolding
ashupednekar f2ae1f7
chore: updated sqlalchemy scaffold structure
ashupednekar c964335
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 4391a39
fix: updated import in models init in sqlalchemy scaffold
ashupednekar 9d66596
chore: reverted accidental change to simple sqlalchemy scaffold
ashupednekar 43726fb
chore: added mutator/selector abc classes to sqlalchemy structured sc…
ashupednekar 9159a71
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] b5895dd
chore: updated test for create_app, added additional test
ashupednekar f155900
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 182f9cf
chore: ignoring errors in case of docker N, if devops directory doesn…
ashupednekar 054570b
chore: udpated ruff suggestions
ashupednekar 3a93374
Merge branch 'sparckles:main' into feat_structured_scaffold
ashupednekar 155acd7
fix: updated subrouter initializations in scaffold
ashupednekar d2ddba8
chore: upadated scaffold
ashupednekar d282b36
chore: updated handler to include pool from a global dependency
ashupednekar 9d7fcf0
chore: added missing arg
ashupednekar 8a3c2ab
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 8ce0753
style: ruff formatting on structured directory
ashupednekar 0a9cbb6
chore: added sample selector and used "session" in sample handler in …
ashupednekar 42c61fc
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] ffe6629
feat: switched to sqlalchemy async
ashupednekar 138e530
fix: updated handler to await async selectors appropriately
ashupednekar 646b58b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from typing import Any, Type, Tuple | ||
from pydantic_settings import ( | ||
BaseSettings, | ||
EnvSettingsSource, | ||
PydanticBaseSettingsSource, | ||
) | ||
from pydantic import ConfigDict | ||
|
||
import importlib | ||
import pkgutil | ||
import logging | ||
|
||
from robyn import Robyn | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
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__ + "."): | ||
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): | ||
return [x.strip() for x in value.split(",") if x] | ||
return value | ||
|
||
|
||
class BaseConfig(BaseSettings): | ||
@classmethod | ||
def settings_customise_sources( | ||
cls, | ||
settings_cls: Type[BaseSettings], | ||
init_settings: PydanticBaseSettingsSource, | ||
env_settings: PydanticBaseSettingsSource, | ||
dotenv_settings: PydanticBaseSettingsSource, | ||
file_secret_settings: PydanticBaseSettingsSource, | ||
) -> Tuple[PydanticBaseSettingsSource, ...]: | ||
return (AcceptArrayEnvsSource(settings_cls),) | ||
|
||
model_config = ConfigDict(extra="ignore") # Ignore extra environment variables |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from robyn import SubRouter | ||
|
||
|
||
router = SubRouter(__name__, prefix="/") | ||
|
||
|
||
@router.get("/livez/") | ||
def livez() -> str: | ||
return "live" | ||
|
||
|
||
@router.get("/healthz/") | ||
def healthz() -> str: | ||
return "healthy" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from robyn import SubRouter | ||
|
||
router = SubRouter(__name__, "/sample") | ||
|
||
|
||
class SampleHandlers: | ||
@router.post("/one") | ||
@staticmethod | ||
def one(): ... | ||
|
||
@router.get("/two") | ||
@staticmethod | ||
def two(): ... | ||
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from robyn.helpers import BaseConfig | ||
|
||
|
||
class Settings(BaseConfig): | ||
service_port: int | ||
|
||
|
||
settings = Settings() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SERVICE_PORT=3000 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where is this being used |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
FROM python:3.11-bookworm AS builder | ||
|
||
WORKDIR /workspace | ||
|
||
COPY . . | ||
RUN pip install --no-cache-dir --upgrade -r requirements.txt --target=/workspace/deps | ||
|
||
FROM gcr.io/distroless/python3-debian11 | ||
|
||
WORKDIR /workspace | ||
COPY --from=builder /workspace /workspace | ||
ENV PYTHONPATH=/workspace/deps | ||
|
||
CMD ["server.py", "--log-level=DEBUG"] |
Empty file.
11 changes: 11 additions & 0 deletions
11
robyn/scaffold/structured/no-db/devops/docker-compose.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
version: '3' | ||
services: | ||
|
||
service: | ||
image: service # build an image with this tag | ||
container_name: "service" | ||
env_file: | ||
- ../config.env | ||
network_mode: host | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
robyn | ||
pydantic~=2.7.4 | ||
pydantic-settings~=2.2.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from robyn.helpers import discover_routes | ||
from robyn import Robyn | ||
|
||
from conf import settings | ||
|
||
app: Robyn = discover_routes("api.handlers") | ||
# note: if you prefer to manuall refine routes, use your build_routes function instead | ||
|
||
|
||
if __name__ == "__main__": | ||
app.start(host="0.0.0.0", port=settings.service_port) |
Empty file.
Empty file.
3 changes: 3 additions & 0 deletions
3
robyn/scaffold/structured/sqlalchemy/adaptors/models/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .user import Base as user | ||
|
||
metadata = [user.metadata] |
36 changes: 36 additions & 0 deletions
36
robyn/scaffold/structured/sqlalchemy/adaptors/models/user.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from sqlalchemy import String, Integer, Boolean | ||
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column | ||
from pydantic import BaseModel | ||
|
||
|
||
class Base(DeclarativeBase): | ||
pass | ||
|
||
|
||
class User(Base): | ||
__tablename__ = "users" | ||
|
||
id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True) | ||
username: Mapped[str] = mapped_column(String, unique=True, index=True) | ||
hashed_password: Mapped[str] = mapped_column(String) | ||
is_active: Mapped[bool] = mapped_column(Boolean, default=True) | ||
is_superuser: Mapped[bool] = mapped_column(Boolean, default=False) | ||
|
||
|
||
class UserRead(BaseModel): | ||
id: int | ||
username: str | ||
is_active: bool | ||
is_superuser: bool | ||
|
||
class Config: | ||
orm_mode = True | ||
|
||
|
||
# Pydantic model for creating/updating a user | ||
class UserCreate(BaseModel): | ||
username: str | ||
password: str | ||
|
||
class Config: | ||
orm_mode = True |
14 changes: 14 additions & 0 deletions
14
robyn/scaffold/structured/sqlalchemy/adaptors/mutators/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from abc import ABC, abstractmethod | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class Mutator(ABC): | ||
@abstractmethod | ||
def create(self, model: BaseModel): ... | ||
|
||
@abstractmethod | ||
def update(self, **kwargs): ... | ||
|
||
@abstractmethod | ||
def delete(self, **kwargs): ... |
9 changes: 9 additions & 0 deletions
9
robyn/scaffold/structured/sqlalchemy/adaptors/selectors/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from abc import ABC, abstractmethod | ||
|
||
|
||
class Mutator(ABC): | ||
@abstractmethod | ||
def retrieve(self, **kwargs): ... | ||
|
||
@abstractmethod | ||
def list(self, **kwargs): ... |
5 changes: 5 additions & 0 deletions
5
robyn/scaffold/structured/sqlalchemy/adaptors/selectors/misc.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from sqlalchemy import text | ||
|
||
|
||
async def sample_selector(conn): | ||
await conn.execute(text("select * from sample;")) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we confining the two methods in a namespace?