From a54b6935a11c88657d130df35b4f354ad1e790ad Mon Sep 17 00:00:00 2001 From: Leonidas Spyropoulos Date: Sat, 3 Aug 2024 08:15:56 +0100 Subject: [PATCH] housekeep: reformat files with pre-hooks Signed-off-by: Leonidas Spyropoulos --- aurweb/cache.py | 2 +- aurweb/routers/rss.py | 4 +- aurweb/spawn.py | 86 +++++++++---------- ...a_add_indicies_on_packagebases_for_rss_.py | 17 ++-- 4 files changed, 55 insertions(+), 54 deletions(-) diff --git a/aurweb/cache.py b/aurweb/cache.py index 41ecf7ff..477f6780 100644 --- a/aurweb/cache.py +++ b/aurweb/cache.py @@ -1,7 +1,7 @@ import pickle +from typing import Any, Callable from sqlalchemy import orm -from typing import Callable, Any from aurweb import config from aurweb.aur_redis import redis_connection diff --git a/aurweb/routers/rss.py b/aurweb/routers/rss.py index 97c1494c..180cbb23 100644 --- a/aurweb/routers/rss.py +++ b/aurweb/routers/rss.py @@ -81,7 +81,9 @@ async def rss_modified(request: Request): # we use redis for caching the results of the feedgen cache_expire = config.getint("cache", "expiry_time_rss", 300) - feed = lambda_cache("rss_modified", lambda: make_rss_feed(request, packages), cache_expire) + feed = lambda_cache( + "rss_modified", lambda: make_rss_feed(request, packages), cache_expire + ) response = Response(feed, media_type="application/rss+xml") return response diff --git a/aurweb/spawn.py b/aurweb/spawn.py index 188ffb43..cfad54e1 100644 --- a/aurweb/spawn.py +++ b/aurweb/spawn.py @@ -51,46 +51,46 @@ def generate_nginx_config(): fastapi_bind = aurweb.config.get("fastapi", "bind_address") fastapi_host = fastapi_bind.split(":")[0] config_path = os.path.join(temporary_dir, "nginx.conf") - config = open(config_path, "w") - # We double nginx's braces because they conflict with Python's f-strings. - config.write( - f""" - events {{}} - daemon off; - error_log /dev/stderr info; - pid {os.path.join(temporary_dir, "nginx.pid")}; - http {{ - access_log /dev/stdout; - client_body_temp_path {os.path.join(temporary_dir, "client_body")}; - proxy_temp_path {os.path.join(temporary_dir, "proxy")}; - fastcgi_temp_path {os.path.join(temporary_dir, "fastcgi")}1 2; - uwsgi_temp_path {os.path.join(temporary_dir, "uwsgi")}; - scgi_temp_path {os.path.join(temporary_dir, "scgi")}; - server {{ - listen {fastapi_host}:{FASTAPI_NGINX_PORT}; - location / {{ - try_files $uri @proxy_to_app; - }} - location @proxy_to_app {{ - proxy_set_header Host $http_host; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - proxy_redirect off; - proxy_buffering off; - proxy_pass http://{fastapi_bind}; + with open(config_path, "w") as config: + # We double nginx's braces because they conflict with Python's f-strings. + config.write( + f""" + events {{}} + daemon off; + error_log /dev/stderr info; + pid {os.path.join(temporary_dir, "nginx.pid")}; + http {{ + access_log /dev/stdout; + client_body_temp_path {os.path.join(temporary_dir, "client_body")}; + proxy_temp_path {os.path.join(temporary_dir, "proxy")}; + fastcgi_temp_path {os.path.join(temporary_dir, "fastcgi")}1 2; + uwsgi_temp_path {os.path.join(temporary_dir, "uwsgi")}; + scgi_temp_path {os.path.join(temporary_dir, "scgi")}; + server {{ + listen {fastapi_host}:{FASTAPI_NGINX_PORT}; + location / {{ + try_files $uri @proxy_to_app; + }} + location @proxy_to_app {{ + proxy_set_header Host $http_host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_redirect off; + proxy_buffering off; + proxy_pass http://{fastapi_bind}; + }} }} }} - }} - """ - ) + """ + ) return config_path -def spawn_child(args): +def spawn_child(_args): """Open a subprocess and add it to the global state.""" if verbosity >= 1: - print(f":: Spawning {args}", file=sys.stderr) - children.append(subprocess.Popen(args)) + print(f":: Spawning {_args}", file=sys.stderr) + children.append(subprocess.Popen(_args)) def start(): @@ -171,17 +171,17 @@ def start(): ) -def _kill_children( - children: Iterable, exceptions: list[Exception] = [] -) -> list[Exception]: +def _kill_children(_children: Iterable, exceptions=None) -> list[Exception]: """ Kill each process found in `children`. - :param children: Iterable of child processes + :param _children: Iterable of child processes :param exceptions: Exception memo :return: `exceptions` """ - for p in children: + if exceptions is None: + exceptions = [] + for p in _children: try: p.terminate() if verbosity >= 1: @@ -191,17 +191,17 @@ def _kill_children( return exceptions -def _wait_for_children( - children: Iterable, exceptions: list[Exception] = [] -) -> list[Exception]: +def _wait_for_children(_children: Iterable, exceptions=None) -> list[Exception]: """ Wait for each process to end found in `children`. - :param children: Iterable of child processes + :param _children: Iterable of child processes :param exceptions: Exception memo :return: `exceptions` """ - for p in children: + if exceptions is None: + exceptions = [] + for p in _children: try: rc = p.wait() if rc != 0 and rc != -15: diff --git a/migrations/versions/38e5b9982eea_add_indicies_on_packagebases_for_rss_.py b/migrations/versions/38e5b9982eea_add_indicies_on_packagebases_for_rss_.py index c73f4535..e6d5f275 100644 --- a/migrations/versions/38e5b9982eea_add_indicies_on_packagebases_for_rss_.py +++ b/migrations/versions/38e5b9982eea_add_indicies_on_packagebases_for_rss_.py @@ -1,30 +1,29 @@ -"""add indicies on PackageBases for RSS order by +"""add indices on PackageBases for RSS order by Revision ID: 38e5b9982eea Revises: 7d65d35fae45 Create Date: 2024-08-03 01:35:39.104283 """ + from alembic import op -import sqlalchemy as sa -from sqlalchemy.dialects import mysql # revision identifiers, used by Alembic. -revision = '38e5b9982eea' -down_revision = '7d65d35fae45' +revision = "38e5b9982eea" +down_revision = "7d65d35fae45" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.create_index('BasesModifiedTS', 'PackageBases', ['ModifiedTS'], unique=False) - op.create_index('BasesSubmittedTS', 'PackageBases', ['SubmittedTS'], unique=False) + op.create_index("BasesModifiedTS", "PackageBases", ["ModifiedTS"], unique=False) + op.create_index("BasesSubmittedTS", "PackageBases", ["SubmittedTS"], unique=False) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.drop_index('BasesSubmittedTS', table_name='PackageBases') - op.drop_index('BasesModifiedTS', table_name='PackageBases') + op.drop_index("BasesSubmittedTS", table_name="PackageBases") + op.drop_index("BasesModifiedTS", table_name="PackageBases") # ### end Alembic commands ###