From 72926a6bfbb31eee9d93ec61bffa682854cde7d5 Mon Sep 17 00:00:00 2001 From: burnysc2 Date: Sat, 16 Nov 2024 23:59:11 +0100 Subject: [PATCH] Fix earthfile for twitch announcer --- ansible/service_authelia/authelia_setup.yml | 1 + fastapi_server/Earthfile | 1 + fastapi_server/uv.lock | 24 -------------- twitch_stream_announcer/.pyre_configuration | 2 +- twitch_stream_announcer/Earthfile | 32 +++++++++---------- .../src/stream_announcer.py | 5 ++- 6 files changed, 22 insertions(+), 43 deletions(-) diff --git a/ansible/service_authelia/authelia_setup.yml b/ansible/service_authelia/authelia_setup.yml index b121dafb..77fb4fdf 100644 --- a/ansible/service_authelia/authelia_setup.yml +++ b/ansible/service_authelia/authelia_setup.yml @@ -45,6 +45,7 @@ project_src: /home/{{ USERNAME }} # Reload config files state: stopped + ignore_errors: true - name: Run `docker-compose up` again community.docker.docker_compose_v2: diff --git a/fastapi_server/Earthfile b/fastapi_server/Earthfile index f396a4f8..cdbd5b29 100644 --- a/fastapi_server/Earthfile +++ b/fastapi_server/Earthfile @@ -16,6 +16,7 @@ format: LOCALLY # Requirements: # pip install uv + # uv sync # Convert single to double quotes RUN uv run ruff check . --select Q --fix diff --git a/fastapi_server/uv.lock b/fastapi_server/uv.lock index cc22035b..16ac22df 100644 --- a/fastapi_server/uv.lock +++ b/fastapi_server/uv.lock @@ -1037,15 +1037,6 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/88/ef/eb23f262cca3c0c4eb7ab1933c3b1f03d021f2c48f54763065b6f0e321be/packaging-24.2-py3-none-any.whl", hash = "sha256:09abb1bccd265c01f4a3aa3f7a7db064b36514d2cba19a2f694fe6150451a759", size = 65451 }, ] -[[package]] -name = "platformdirs" -version = "4.3.6" -source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/13/fc/128cc9cb8f03208bdbf93d3aa862e16d376844a14f9a0ce5cf4507372de4/platformdirs-4.3.6.tar.gz", hash = "sha256:357fb2acbc885b0419afd3ce3ed34564c13c9b95c89360cd9563f73aa5e2b907", size = 21302 } -wheels = [ - { url = "https://files.pythonhosted.org/packages/3c/a6/bc1012356d8ece4d66dd75c4b9fc6c1f6650ddd5991e421177d9f8f671be/platformdirs-4.3.6-py3-none-any.whl", hash = "sha256:73e575e1408ab8103900836b97580d5307456908a03e92031bab39e4554cc3fb", size = 18439 }, -] - [[package]] name = "pluggy" version = "1.5.0" @@ -1699,7 +1690,6 @@ dev = [ { name = "pytest-random-order" }, { name = "ruff" }, { name = "toml" }, - { name = "yapf" }, ] [package.metadata] @@ -1736,7 +1726,6 @@ dev = [ { name = "pytest-random-order", specifier = ">=1.1.1" }, { name = "ruff", specifier = ">=0.7.3" }, { name = "toml", specifier = ">=0.10.2" }, - { name = "yapf", specifier = ">=0.43.0" }, ] [[package]] @@ -2070,19 +2059,6 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/78/58/e860788190eba3bcce367f74d29c4675466ce8dddfba85f7827588416f01/wsproto-1.2.0-py3-none-any.whl", hash = "sha256:b9acddd652b585d75b20477888c56642fdade28bdfd3579aa24a4d2c037dd736", size = 24226 }, ] -[[package]] -name = "yapf" -version = "0.43.0" -source = { registry = "https://pypi.org/simple" } -dependencies = [ - { name = "platformdirs" }, - { name = "tomli", marker = "python_full_version < '3.11'" }, -] -sdist = { url = "https://files.pythonhosted.org/packages/23/97/b6f296d1e9cc1ec25c7604178b48532fa5901f721bcf1b8d8148b13e5588/yapf-0.43.0.tar.gz", hash = "sha256:00d3aa24bfedff9420b2e0d5d9f5ab6d9d4268e72afbf59bb3fa542781d5218e", size = 254907 } -wheels = [ - { url = "https://files.pythonhosted.org/packages/37/81/6acd6601f61e31cfb8729d3da6d5df966f80f374b78eff83760714487338/yapf-0.43.0-py3-none-any.whl", hash = "sha256:224faffbc39c428cb095818cf6ef5511fdab6f7430a10783fdfb292ccf2852ca", size = 256158 }, -] - [[package]] name = "yarl" version = "1.17.1" diff --git a/twitch_stream_announcer/.pyre_configuration b/twitch_stream_announcer/.pyre_configuration index 7c512daa..c6b40891 100644 --- a/twitch_stream_announcer/.pyre_configuration +++ b/twitch_stream_announcer/.pyre_configuration @@ -1,6 +1,6 @@ { "site_package_search_strategy": "pep561", "source_directories": [ - "." + "src" ] } diff --git a/twitch_stream_announcer/Earthfile b/twitch_stream_announcer/Earthfile index 2cf14fbb..a2ec292d 100644 --- a/twitch_stream_announcer/Earthfile +++ b/twitch_stream_announcer/Earthfile @@ -1,51 +1,49 @@ VERSION 0.6 # earthly +all --PYTHONVERSION=3.12 ARG PYTHONVERSION=3.12 -FROM python:${PYTHONVERSION}-slim +FROM ghcr.io/astral-sh/uv:python${PYTHONVERSION}-bookworm-slim WORKDIR /root/stream_announcer install-dev: - RUN apt -y update - RUN pip install poetry --no-cache-dir - COPY poetry.lock pyproject.toml ./ - RUN poetry install - COPY src /root/stream_announcer/src + COPY uv.lock pyproject.toml ./ + RUN uv sync --frozen --no-cache --no-install-project + COPY src /root/fastapi_server/src format: # Run on host system instead of inside a container LOCALLY # Requirements: - # pip install poetry - # poetry install - + # pip install uv + # uv sync + # Convert single to double quotes - RUN poetry run ruff check . --select Q --fix + RUN uv run ruff check . --select Q --fix # Remove unused imports - RUN poetry run ruff check . --select F --fix + RUN uv run ruff check . --select F --fix # Sort imports - RUN poetry run ruff check . --select I --fix + RUN uv run ruff check . --select I --fix # Format code - RUN poetry run yapf -ir . + RUN uv run ruff format . # Check if files are correctly formatted format-check: FROM +install-dev - RUN poetry run yapf -dr . + RUN uv run ruff format . --check --diff # Ignore errors via "# noqa: F841" lint: FROM +install-dev - RUN poetry run ruff check . + RUN uv run ruff check . # Ignore errors via "# pyre-fixme[11]" pyre: FROM +install-dev COPY .pyre_configuration /root/stream_announcer/.pyre_configuration - RUN poetry run pyre + RUN uv run pyre # pytest: # FROM +install-dev -# RUN poetry run pytest test +# RUN uv run pytest test pre-commit: BUILD +format-check diff --git a/twitch_stream_announcer/src/stream_announcer.py b/twitch_stream_announcer/src/stream_announcer.py index 65b41876..3995b7b8 100644 --- a/twitch_stream_announcer/src/stream_announcer.py +++ b/twitch_stream_announcer/src/stream_announcer.py @@ -50,7 +50,10 @@ async def check_twitch(chunked_data: list[dict[str, OrderedDict]]): ) session = aiohttp.ClientSession() all_previously_online_streams: list[str] = [ - db_entry["twitch_name"] for chunk in chunked_data for db_entries in chunk.values() for db_entry in db_entries + db_entry["twitch_name"] + for chunk in chunked_data + for db_entries in chunk.values() + for db_entry in db_entries if db_entry.get("status") == "online" ] all_online_streams: list[str] = []