Skip to content

Commit

Permalink
Add support for Lilya (#977)
Browse files Browse the repository at this point in the history
* Add support for Lilya

* Fix event handlers

* Fix linting and formating

* Fix linting and formating with updated requirements

* Update README.md
  • Loading branch information
tarsil committed Apr 6, 2024
1 parent 363d683 commit 919983a
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Let Piccolo scaffold you an ASGI web app, using Piccolo as the ORM:
piccolo asgi new
```

[Starlette](https://www.starlette.io/), [FastAPI](https://fastapi.tiangolo.com/), [BlackSheep](https://www.neoteroi.dev/blacksheep/), [Litestar](https://litestar.dev/) and [Esmerald](https://esmerald.dev/) are currently supported.
[Starlette](https://www.starlette.io/), [FastAPI](https://fastapi.tiangolo.com/), [BlackSheep](https://www.neoteroi.dev/blacksheep/), [Litestar](https://litestar.dev/), [Esmerald](https://esmerald.dev/) and [Lilya](https://lilya.dev) are currently supported.

## Are you a Django user?

Expand Down
2 changes: 1 addition & 1 deletion docs/src/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Give me an ASGI web app!
piccolo asgi new
FastAPI, Starlette, BlackSheep, Litestar and Esmerald are currently supported,
FastAPI, Starlette, BlackSheep, Litestar, Esmerald and Lilya are currently supported,
with more coming soon.

-------------------------------------------------------------------------------
Expand Down
5 changes: 3 additions & 2 deletions docs/src/piccolo/asgi/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ Routing frameworks

Currently, `Starlette <https://www.starlette.io/>`_, `FastAPI <https://fastapi.tiangolo.com/>`_,
`BlackSheep <https://www.neoteroi.dev/blacksheep/>`_,
`Litestar <https://litestar.dev/>`_ and `Esmerald <https://esmerald.dev/>`_ are supported.
`Litestar <https://litestar.dev/>`_, `Esmerald <https://esmerald.dev/>`_ and
`Lilya <https://lilya.dev/>`_ are supported.

Other great ASGI routing frameworks exist, and may be supported in the future
(`Quart <https://pgjones.gitlab.io/quart/>`_ ,
Expand All @@ -32,7 +33,7 @@ Other great ASGI routing frameworks exist, and may be supported in the future
Which to use?
=============

All are great choices. FastAPI and Esmerald are built on top of Starlette, so they're
All are great choices. FastAPI is built on top of Starlette and Esmerald is built on top of Lilya, so they're
very similar. FastAPI, BlackSheep and Esmerald are great if you want to document a REST
API, as they have built-in OpenAPI support.

Expand Down
1 change: 1 addition & 0 deletions piccolo/apps/asgi/commands/new.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"blacksheep": ["blacksheep"],
"litestar": ["litestar"],
"esmerald": ["esmerald"],
"lilya": ["lilya"],
}
ROUTERS = list(ROUTER_DEPENDENCIES.keys())

Expand Down
45 changes: 45 additions & 0 deletions piccolo/apps/asgi/commands/templates/app/_lilya_app.py.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from piccolo_admin.endpoints import create_admin
from piccolo_api.crud.endpoints import PiccoloCRUD
from piccolo.engine import engine_finder
from lilya.routing import Path, Include
from lilya.apps import Lilya
from lilya.staticfiles import StaticFiles

from home.endpoints import HomeController
from home.piccolo_app import APP_CONFIG
from home.tables import Task


app = Lilya(
routes=[
Path("/", HomeController),
Include(
"/admin/",
create_admin(
tables=APP_CONFIG.table_classes,
# Required when running under HTTPS:
# allowed_hosts=['my_site.com']
)
),
Include("/static/", StaticFiles(directory="static")),
Include("/tasks/", PiccoloCRUD(table=Task))
],
)


@app.on_event("on_startup")
async def open_database_connection_pool():
try:
engine = engine_finder()
await engine.start_connection_pool()
except Exception:
print("Unable to connect to the database")


@app.on_event("on_shutdown")
async def close_database_connection_pool():
try:
engine = engine_finder()
await engine.close_connection_pool()
except Exception:
print("Unable to connect to the database")
2 changes: 2 additions & 0 deletions piccolo/apps/asgi/commands/templates/app/app.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
{% include '_litestar_app.py.jinja' %}
{% elif router == 'esmerald' %}
{% include '_esmerald_app.py.jinja' %}
{% elif router == 'lilya' %}
{% include '_lilya_app.py.jinja' %}
{% endif %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import os

import jinja2
from lilya.controllers import Controller
from lilya.responses import HTMLResponse


ENVIRONMENT = jinja2.Environment(
loader=jinja2.FileSystemLoader(
searchpath=os.path.join(os.path.dirname(__file__), "templates")
)
)


class HomeController(Controller):
async def get(self, request):
template = ENVIRONMENT.get_template("home.html.jinja")

content = template.render(title="Piccolo + ASGI",)

return HTMLResponse(content)
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
{% include '_litestar_endpoints.py.jinja' %}
{% elif router == 'esmerald' %}
{% include '_esmerald_endpoints.py.jinja' %}
{% elif router == 'lilya' %}
{% include '_lilya_endpoints.py.jinja' %}
{% endif %}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@
<li><a href="/admin/">Admin</a></li>
<li><a href="/docs/swagger">Swagger API</a></li>
</ul>
<h3>Lilya</h3>
<ul>
<li><a href="/admin/">Admin</a></li>
<li><a href="/tasks/">JSON endpoint</a></li>
</ul>
</section>
</div>
{% endblock content %}
1 change: 0 additions & 1 deletion tests/columns/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ def test_get_dimensions(self):


class TestGetInnerValueType(TestCase):

def test_get_inner_value_type(self):
"""
Make sure that `_get_inner_value_type` returns the correct base type.
Expand Down

0 comments on commit 919983a

Please sign in to comment.