Skip to content

Commit

Permalink
Merge pull request #392 from getlogbook/feature/3.13
Browse files Browse the repository at this point in the history
Python 3.13 support
  • Loading branch information
RazerM authored Oct 21, 2024
2 parents fc54008 + 44f5e7f commit 44136d7
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 8 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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:
Expand Down Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
6 changes: 4 additions & 2 deletions src/logbook/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand Down
8 changes: 8 additions & 0 deletions src/logbook/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_logging_times.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime, timedelta, tzinfo
from datetime import datetime, timedelta, timezone, tzinfo

import pytest

Expand All @@ -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

Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -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 =
Expand Down Expand Up @@ -32,3 +32,4 @@ python =
3.10: py310
3.11: py311, docs
3.12: py312
3.13: py313

0 comments on commit 44136d7

Please sign in to comment.