diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c0a89e5..f5dc283 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -27,7 +27,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] steps: - uses: "actions/checkout@v4" @@ -54,7 +54,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] arch: ["x86", "x64"] env: @@ -84,7 +84,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] steps: - uses: "actions/checkout@v4" diff --git a/pyproject.toml b/pyproject.toml index 49bb0ad..1f038c3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,6 +21,7 @@ classifiers = [ "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", ] requires-python = ">=3.8" dynamic = ["version"] diff --git a/src/logbook/compat.py b/src/logbook/compat.py index c79fef1..6f2cbea 100644 --- a/src/logbook/compat.py +++ b/src/logbook/compat.py @@ -12,10 +12,12 @@ import sys import warnings from collections.abc import Mapping -from datetime import date, datetime, timezone +from datetime import timezone import logbook +from .helpers import datetime_utcfromtimestamp + def redirect_logging(set_root_logger_level=True): """Permanently redirects logging to the stdlib. This also @@ -140,7 +142,7 @@ def convert_time(self, timestamp): """Converts the UNIX timestamp of the old record into a datetime object as used by logbook. """ - return datetime.utcfromtimestamp(timestamp) + return datetime_utcfromtimestamp(timestamp) def convert_record(self, old_record): """Converts an old logging record into a logbook log record.""" diff --git a/src/logbook/helpers.py b/src/logbook/helpers.py index eb58304..b9e659b 100644 --- a/src/logbook/helpers.py +++ b/src/logbook/helpers.py @@ -153,8 +153,16 @@ def datetime_utcnow(): """ return datetime.now(timezone.utc).replace(tzinfo=None) + def datetime_utcfromtimestamp(timestamp): + """datetime.utcfromtimesetamp() but doesn't emit a deprecation warning. + + Will be fixed by https://github.com/getlogbook/logbook/issues/353 + """ + return datetime.fromtimestamp(timestamp, timezone.utc).replace(tzinfo=None) + else: datetime_utcnow = datetime.utcnow + datetime_utcfromtimestamp = datetime.utcfromtimestamp def format_iso8601(d=None): diff --git a/tests/test_logging_times.py b/tests/test_logging_times.py index a27bf06..46da2c9 100644 --- a/tests/test_logging_times.py +++ b/tests/test_logging_times.py @@ -1,4 +1,4 @@ -from datetime import datetime, timedelta, tzinfo +from datetime import datetime, timedelta, timezone, tzinfo import pytest @@ -25,7 +25,7 @@ def test_timedate_format(activation_strategy, logger): # get the expected difference between local and utc time t1 = datetime.now() - t2 = datetime.utcnow() + t2 = datetime.now(timezone.utc).replace(tzinfo=None) tz_minutes_diff = (t1 - t2).total_seconds() / 60.0 diff --git a/tox.ini b/tox.ini index 499ed52..8d5108a 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py{38,39,310,311,312}{,-nospeedups},pypy,docs +envlist = py{38,39,310,311,312,313}{,-nospeedups},pypy,docs [testenv] extras = @@ -32,3 +32,4 @@ python = 3.10: py310 3.11: py311, docs 3.12: py312 + 3.13: py313