Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3.13 support #392

Merged
merged 4 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading