From 41210d8f3762e8d17a0a48b017a026a4196c08f4 Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Sun, 24 May 2020 20:18:54 +0200 Subject: [PATCH] Port to FastAPI --- Dockerfile | 2 +- app/__init__.py | 18 +- app/templates/base.html | 2 +- app/templates/baseindex.html | 2 +- app/templates/group.html | 2 +- app/templates/groups.html | 2 +- app/templates/layout.html | 10 +- app/templates/navbar.html | 20 +- app/templates/outofdate.html | 6 +- app/templates/package.html | 2 +- app/templates/python2.html | 2 +- app/templates/queue.html | 2 +- app/templates/search.html | 4 +- app/web.py | 385 ++++++++++++++++++----------------- poetry.lock | 341 +++++++++++++++++++++++-------- pyproject.toml | 11 +- run.py | 5 +- tests/test_main.py | 65 ++++-- 18 files changed, 561 insertions(+), 320 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9d5674b..1f51240 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,5 +12,5 @@ COPY . /app WORKDIR /app RUN poetry install --no-dev -ENTRYPOINT ["poetry","run", "gunicorn", "-w1", "-b0.0.0.0:80", "app:app"] +ENTRYPOINT ["poetry","run", "uvicorn", "--host", "0.0.0.0", "--port", "80", "app:app"] EXPOSE 80 diff --git a/app/__init__.py b/app/__init__.py index 1905f8e..66a79c2 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -3,16 +3,18 @@ import os -from flask import Flask -from jinja2 import StrictUndefined +from fastapi import FastAPI -from .web import packages +from .web import webapp from .fetch import start_update_thread -app = Flask(__name__) -app.register_blueprint(packages) -app.jinja_env.undefined = StrictUndefined +app = FastAPI(openapi_url=None) +app.mount("/", webapp) -if not os.environ.get("NO_UPDATE_THREAD"): - start_update_thread() + +# https://github.com/tiangolo/fastapi/issues/1480 +@app.on_event("startup") +async def startup_event() -> None: + if not os.environ.get("NO_UPDATE_THREAD"): + start_update_thread() diff --git a/app/templates/base.html b/app/templates/base.html index de3cdf6..5b56dcc 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -33,7 +33,7 @@
Group(s):
{% for g in s.groups %} - {{ g }}{{ ", " if not loop.last else "" }} + {{ g }}{{ ", " if not loop.last else "" }} {% else %} - {% endfor %} diff --git a/app/templates/baseindex.html b/app/templates/baseindex.html index 5396b91..6b68943 100644 --- a/app/templates/baseindex.html +++ b/app/templates/baseindex.html @@ -19,7 +19,7 @@ {% for s in sources %} - {{ s.name }} + {{ s.name }} {{ s.version }} {{ s.desc }} diff --git a/app/templates/group.html b/app/templates/group.html index df0ef08..4eeda4f 100644 --- a/app/templates/group.html +++ b/app/templates/group.html @@ -4,7 +4,7 @@
-

Group: {{ name }}

+

Group: {{ name }}

Packages that are part of the group
diff --git a/app/templates/groups.html b/app/templates/groups.html index 13bc788..f2ecdfa 100644 --- a/app/templates/groups.html +++ b/app/templates/groups.html @@ -18,7 +18,7 @@ {% for g, count in groups|dictsort %} - {{ g }} + {{ g }} {{ count }} {% endfor %} diff --git a/app/templates/layout.html b/app/templates/layout.html index e3f0927..1fede6c 100644 --- a/app/templates/layout.html +++ b/app/templates/layout.html @@ -4,16 +4,16 @@ - - - + + + {% block title %}{% endblock %} - MSYS2 Packages
diff --git a/app/templates/package.html b/app/templates/package.html index c28ab5a..8f53c1a 100644 --- a/app/templates/package.html +++ b/app/templates/package.html @@ -20,7 +20,7 @@
Base Package:
-
{{ p.base }}
+
{{ p.base }}
Repo:
{{ package_name(p, p.repo) }}
diff --git a/app/templates/python2.html b/app/templates/python2.html index 97ce067..806d01b 100644 --- a/app/templates/python2.html +++ b/app/templates/python2.html @@ -19,7 +19,7 @@ {% for s, info in results %} - {{ s }} + {{ s }} {{ info[0] }} {{ '✓' if info[1] else ''}} diff --git a/app/templates/queue.html b/app/templates/queue.html index ae5848b..34791be 100644 --- a/app/templates/queue.html +++ b/app/templates/queue.html @@ -25,7 +25,7 @@ {% for (srcpkg, s, p) in updates %} {{ srcpkg.date }} - {{ s.name }} + {{ s.name }} {{ p.version }} → {{ srcpkg.build_version }} diff --git a/app/templates/search.html b/app/templates/search.html index eac24e0..a1af61e 100644 --- a/app/templates/search.html +++ b/app/templates/search.html @@ -6,7 +6,7 @@
-
+ Search in