From d6934fcd3c8521be104f5ad28ba4a4c5968e3709 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Sat, 3 Jan 2026 15:45:32 +0100 Subject: [PATCH] Lint on PRs --- .github/workflows/test.yml | 26 ++++++++++++++++++++++++++ sendspin/discovery.py | 4 +++- sendspin/serve/__init__.py | 17 +++++++---------- sendspin/utils.py | 1 - 4 files changed, 36 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..21717dc --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,26 @@ +# This workflow will install Python dependencies and run linting +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: Test + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + lint: + runs-on: ubuntu-latest + + steps: + - name: Check out code from GitHub + uses: actions/checkout@v6.0.1 + - name: Install uv + uses: astral-sh/setup-uv@v6 + - name: Set up Python + run: uv python install 3.12 + - name: Install dependencies + run: uv sync --extra test + - name: Lint/test with pre-commit + run: SKIP=no-commit-to-branch uv run pre-commit run --all-files diff --git a/sendspin/discovery.py b/sendspin/discovery.py index 50f7c61..1620e3d 100644 --- a/sendspin/discovery.py +++ b/sendspin/discovery.py @@ -94,7 +94,9 @@ async def _process_service_info( self._first_result.set_result(url) def _schedule(self, zeroconf: AsyncZeroconf, service_type: str, name: str) -> None: - task = create_task(self._process_service_info(zeroconf, service_type, name), loop=self._loop) + task = create_task( + self._process_service_info(zeroconf, service_type, name), loop=self._loop + ) self.tasks.add(task) task.add_done_callback(self.tasks.discard) task.add_done_callback(lambda t: t.exception() if not t.cancelled() else None) diff --git a/sendspin/serve/__init__.py b/sendspin/serve/__init__.py index a2d5b27..8f4ad41 100644 --- a/sendspin/serve/__init__.py +++ b/sendspin/serve/__init__.py @@ -45,7 +45,8 @@ def get_local_ip() -> str: try: with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s: s.connect(("8.8.8.8", 80)) - return s.getsockname()[0] + ip: str = s.getsockname()[0] + return ip except Exception: return "localhost" @@ -59,7 +60,7 @@ class ServeConfig: name: str = "Sendspin Server" -def _windows_exception_handler(loop: asyncio.AbstractEventLoop, context: dict) -> None: +def _windows_exception_handler(loop: asyncio.AbstractEventLoop, context: dict[str, object]) -> None: """Suppress ConnectionResetError on Windows during socket shutdown. On Windows, the ProactorEventLoop raises ConnectionResetError (WinError 10054) @@ -93,7 +94,7 @@ async def run_server(config: ServeConfig) -> int: client_connected = asyncio.Event() active_group: SendspinGroup | None = None - play_media_task: asyncio.Task[None] | None = None + play_media_task: asyncio.Task[int] | None = None shutdown_requested = False def handle_sigint() -> None: @@ -175,13 +176,10 @@ async def on_server_event(server: SendspinServer, event: SendspinEvent) -> None: # Wait for a client to connect if not active_group: client_connected.clear() - try: - await client_connected.wait() - except asyncio.CancelledError: - raise + await client_connected.wait() if shutdown_requested: - break + break # type: ignore[unreachable] assert active_group is not None @@ -195,8 +193,7 @@ async def on_server_event(server: SendspinServer, event: SendspinEvent) -> None: play_media_task = create_task(active_group.play_media(media_stream)) await play_media_task except asyncio.CancelledError: - if shutdown_requested: - break + pass except Exception as e: print(f"Playback error: {e}") logger.debug("Playback error", exc_info=True) diff --git a/sendspin/utils.py b/sendspin/utils.py index fb96533..e38b131 100644 --- a/sendspin/utils.py +++ b/sendspin/utils.py @@ -3,7 +3,6 @@ from __future__ import annotations import asyncio -import inspect import sys from collections.abc import Coroutine from typing import TypeVar