Skip to content

Commit

Permalink
Update ASGI requirements (#911)
Browse files Browse the repository at this point in the history
* remove `jinja2`

Piccolo has `jinja2` as a direct dependency, so this shouldn't be needed.

* remove `requeste`

I think this was needed for Starlette at some point, but it has since transitioned to `httpx`, so I don't think it's needed any more.

* move `piccolo_admin` to `ROUTER_DEPENDENCIES`

We don't use it for `esmerald` so don't include it by default for all routers.

* no longer omit `piccolo_admin` for `esmerald`

* add `piccolo_admin` to `_esmerald_app.py.jinja`
  • Loading branch information
dantownsend committed Jan 23, 2024
1 parent 1b0c521 commit 6ec06e7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
6 changes: 5 additions & 1 deletion piccolo/apps/asgi/commands/new.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@

TEMPLATE_DIR = os.path.join(os.path.dirname(__file__), "templates/app/")
SERVERS = ["uvicorn", "Hypercorn"]
ROUTERS = ["starlette", "fastapi", "blacksheep", "litestar", "esmerald"]
ROUTER_DEPENDENCIES = {
"starlette": ["starlette"],
"fastapi": ["fastapi>=0.100.0"],
"blacksheep": ["blacksheep"],
"litestar": ["litestar"],
"esmerald": ["esmerald"],
}
ROUTERS = list(ROUTER_DEPENDENCIES.keys())


def print_instruction(message: str):
Expand Down
11 changes: 10 additions & 1 deletion piccolo/apps/asgi/commands/templates/app/_esmerald_app.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ from pathlib import Path

from piccolo.utils.pydantic import create_pydantic_model
from piccolo.engine import engine_finder
from piccolo_admin.endpoints import create_admin

from esmerald import (
Esmerald,
Expand Down Expand Up @@ -92,7 +93,15 @@ class TaskAPIView(APIView):
app = Esmerald(
routes=[
Gateway("/", handler=home),
Gateway("/tasks", handler=TaskAPIView)
Gateway("/tasks", handler=TaskAPIView),
Include(
"/admin/",
create_admin(
tables=APP_CONFIG.table_classes,
# Required when running under HTTPS:
# allowed_hosts=['my_site.com']
),
),
],
static_files_config=StaticFilesConfig(path="/static", directory=Path("static")),
on_startup=[open_database_connection_pool],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@
{{ router_dependency }}
{% endfor -%}
{{ server }}
jinja2
piccolo[postgres]
piccolo_admin
requests
piccolo[postgres]>=1.0.0
piccolo_admin>=1.0.0

0 comments on commit 6ec06e7

Please sign in to comment.