From 9ff09c928dd1cd31c72e90d42ccbb773eba1e0de Mon Sep 17 00:00:00 2001 From: Stefan Tatschner Date: Fri, 8 Dec 2023 13:19:17 +0100 Subject: [PATCH 1/4] flake.lock: Update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Flake lock file updates: • Updated input 'nixpkgs': 'github:nixos/nixpkgs/b56f06f3e8c6f48973a43765f4b02c756ba30da4' (2023-10-02) → 'github:nixos/nixpkgs/6a6d3373898c5fbd3ab8626e965f8b80cc932bb4' (2023-12-08) --- flake.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flake.lock b/flake.lock index 05ab3d477..3229b00b0 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1696227680, - "narHash": "sha256-G6Lt2qzQGl3NrI3WS4aJ40eMZRxgnhrbblnftBM3aGM=", + "lastModified": 1702037461, + "narHash": "sha256-5G9qC12Fwe4f/zTeP6xAJJ8vJ9H7Vc1nodvMTeu2X/s=", "owner": "nixos", "repo": "nixpkgs", - "rev": "b56f06f3e8c6f48973a43765f4b02c756ba30da4", + "rev": "6a6d3373898c5fbd3ab8626e965f8b80cc932bb4", "type": "github" }, "original": { From 2e748a9eff256b019da34b264e71dcd023743904 Mon Sep 17 00:00:00 2001 From: Stefan Tatschner Date: Fri, 8 Dec 2023 14:03:58 +0100 Subject: [PATCH 2/4] chore: Add python 3.12 to flake.nix --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index e329d1d3f..55b4e5439 100644 --- a/flake.nix +++ b/flake.nix @@ -14,8 +14,8 @@ devShell.x86_64-linux = pkgs.mkShell { buildInputs = with pkgs; [ poetry - python310 python311 + python312 ]; shellHook = '' LD_LIBRARY_PATH=${pkgs.lib.makeLibraryPath [stdenv.cc.cc]} From a3ed8ec30c35e95cd1d0b2c5d3ebd1e9737fc8a2 Mon Sep 17 00:00:00 2001 From: Stefan Tatschner Date: Fri, 8 Dec 2023 14:04:40 +0100 Subject: [PATCH 3/4] chore: Fix deprecation warning --- src/gallia/log.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/gallia/log.py b/src/gallia/log.py index 52ea44582..74ea02739 100644 --- a/src/gallia/log.py +++ b/src/gallia/log.py @@ -5,6 +5,7 @@ from __future__ import annotations import atexit +import datetime import gzip import io import logging @@ -17,7 +18,6 @@ import traceback from collections.abc import Iterator from dataclasses import dataclass -from datetime import datetime from enum import Enum, IntEnum, unique from logging.handlers import QueueHandler, QueueListener from pathlib import Path @@ -32,7 +32,7 @@ from logging import _ExcInfoType -tz = datetime.utcnow().astimezone().tzinfo +tz = datetime.datetime.now(datetime.UTC).tzinfo @unique @@ -380,7 +380,7 @@ def _colorize_msg(data: str, levelno: int) -> tuple[str, int]: def _format_record( # noqa: PLR0913 - dt: datetime, + dt: datetime.datetime, name: str, data: str, levelno: int, @@ -427,7 +427,7 @@ class PenlogRecord: module: str host: str data: str - datetime: datetime + datetime: datetime.datetime # FIXME: Enums are slow. priority: PenlogPriority tags: list[str] | None = None @@ -475,12 +475,12 @@ def parse_json(cls, data: bytes) -> Self: match record: case _PenlogRecordV1(): try: - dt = datetime.fromisoformat(record.timestamp) + dt = datetime.datetime.fromisoformat(record.timestamp) except ValueError: # Workaround for broken ISO strings. Go produced broken strings. :) # We have some old logfiles with this shortcoming. datestr, _ = record.timestamp.split(".", 2) - dt = datetime.strptime(datestr, "%Y-%m-%dT%H:%M:%S") + dt = datetime.datetime.strptime(datestr, "%Y-%m-%dT%H:%M:%S") if record.tags is not None: tags = record.tags @@ -505,7 +505,7 @@ def parse_json(cls, data: bytes) -> Self: module=record.module, host=record.host, data=record.data, - datetime=datetime.fromisoformat(record.datetime), + datetime=datetime.datetime.fromisoformat(record.datetime), priority=PenlogPriority(record.priority), tags=record.tags, line=record.line, @@ -726,7 +726,7 @@ def format(self, record: logging.LogRecord) -> str: host=self.hostname, data=record.getMessage(), priority=PenlogPriority.from_level(record.levelno).value, - datetime=datetime.fromtimestamp(record.created, tz=tz).isoformat(), + datetime=datetime.datetime.fromtimestamp(record.created, tz=tz).isoformat(), line=f"{record.pathname}:{record.lineno}", stacktrace=stacktrace, tags=tags, @@ -760,7 +760,7 @@ def format( ) return _format_record( - dt=datetime.fromtimestamp(record.created), + dt=datetime.datetime.fromtimestamp(record.created), name=record.name, data=record.getMessage(), levelno=record.levelno, From 6271e567039158e075bcee6dbc895122bb195391 Mon Sep 17 00:00:00 2001 From: Stefan Tatschner Date: Fri, 8 Dec 2023 14:05:17 +0100 Subject: [PATCH 4/4] fix(tests): Fix hanging tests There is a Python bug with .wait_closed(); just remove this invocation. * https://github.com/python/cpython/issues/104344 * https://github.com/python/cpython/issues/109538 --- tests/test_transports.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/test_transports.py b/tests/test_transports.py index 891cdac18..eb6278877 100644 --- a/tests/test_transports.py +++ b/tests/test_transports.py @@ -38,9 +38,8 @@ async def listen(self, target: TargetURI) -> None: async def accept(self) -> TCPTransport: return await self.queue.get() - async def close(self) -> None: + def close(self) -> None: self.server.close() - await self.server.wait_closed() async def _echo_test( @@ -66,7 +65,7 @@ async def tcp_server() -> AsyncIterator[TCPServer]: tcp_server = TCPServer() await tcp_server.listen(listen_target) yield tcp_server - await tcp_server.close() + tcp_server.close() @pytest.mark.asyncio @@ -127,7 +126,7 @@ async def test_tcp_linesep_request(tcp_server: TCPServer) -> None: @pytest.mark.asyncio async def test_tcp_timeout(tcp_server: TCPServer) -> None: client = await TCPLinesTransport.connect(TargetURI("tcp-lines://127.0.0.1:1234")) - _ = await tcp_server.accept() + await tcp_server.accept() with pytest.raises(asyncio.TimeoutError): await client.request(b"hello", timeout=0.5)