Skip to content

Commit

Permalink
Update Supported Python Versions (#2)
Browse files Browse the repository at this point in the history
This updates the supported versions of python including those run in the CI test suite.

- Python versions 3.7-3.13
  - Drops 3.6
- PYPY 3.7-3.10
- Adds MacOS and Windows to test matrix
- Add `taskName` to `RESERVED_ATTRS` (fixes: #3 )
  • Loading branch information
nhairs authored Mar 11, 2024
1 parent 3dd0257 commit 19bfb64
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 92 deletions.
43 changes: 0 additions & 43 deletions .github/workflows/build.yml

This file was deleted.

32 changes: 0 additions & 32 deletions .github/workflows/release.yml

This file was deleted.

47 changes: 47 additions & 0 deletions .github/workflows/test-suite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Test python-json-logger

on:
push:
branches:
- main

pull_request:
branches:
- main

jobs:
test:
name: "Python ${{matrix.python-version}} ${{ matrix.os }}"
runs-on: "${{ matrix.os }}"
strategy:
matrix:
python-version:
- "pypy-3.7"
- "pypy-3.8"
- "pypy-3.9"
- "pypy-3.10"
- "3.7"
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
os:
- ubuntu-latest
- windows-latest
- macos-latest

steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox tox-gh-actions
- name: Test with tox
run: tox
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setup(
name="python-json-logger",
version="2.0.7",
version="3.0.0.dev1",
url="http://github.com/madzak/python-json-logger",
license="BSD",
include_package_data=True,
Expand All @@ -21,7 +21,7 @@
package_data={"pythonjsonlogger": ["py.typed"]},
packages=find_packages("src", exclude="tests"),
# https://packaging.python.org/guides/distributing-packages-using-setuptools/#python-requires
python_requires=">=3.6",
python_requires=">=3.7",
test_suite="tests.tests",
classifiers=[
'Development Status :: 6 - Mature',
Expand All @@ -30,12 +30,13 @@
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Topic :: System :: Logging',
]
)
26 changes: 15 additions & 11 deletions src/pythonjsonlogger/jsonlogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
This library is provided to allow standard python logging
to output log data as JSON formatted strings
"""

import logging
import json
import re
import traceback
import importlib
from datetime import date, datetime, time, timezone
import sys
from typing import Any, Callable, Dict, List, Optional, Tuple, Union

from inspect import istraceback
Expand All @@ -16,7 +18,8 @@

# skip natural LogRecord attributes
# http://docs.python.org/library/logging.html#logrecord-attributes
RESERVED_ATTRS: Tuple[str, ...] = (
# Changed in 3.0.0, is now list[str] instead of tuple[str, ...]
RESERVED_ATTRS: List[str] = [
"args",
"asctime",
"created",
Expand All @@ -39,7 +42,11 @@
"stack_info",
"thread",
"threadName",
)
]

if sys.version_info >= (3, 12):
# taskName added in python 3.12
RESERVED_ATTRS.append("taskName")

OptionalCallableOrStr = Optional[Union[Callable, str]]

Expand All @@ -63,9 +70,7 @@ def merge_record_extra(
rename_fields = {}
for key, value in record.__dict__.items():
# this allows to have numeric keys
if key not in reserved and not (
hasattr(key, "startswith") and key.startswith("_")
):
if key not in reserved and not (hasattr(key, "startswith") and key.startswith("_")):
target[rename_fields.get(key, key)] = value
return target

Expand All @@ -79,10 +84,10 @@ def default(self, obj):
if isinstance(obj, (date, datetime, time)):
return self.format_datetime_obj(obj)

elif istraceback(obj):
if istraceback(obj):
return "".join(traceback.format_tb(obj)).strip()

elif type(obj) == Exception or isinstance(obj, Exception) or type(obj) == type:
if type(obj) == Exception or isinstance(obj, Exception) or type(obj) == type:
return str(obj)

try:
Expand Down Expand Up @@ -117,9 +122,9 @@ def __init__(
prefix: str = "",
rename_fields: Optional[dict] = None,
static_fields: Optional[dict] = None,
reserved_attrs: Tuple[str, ...] = RESERVED_ATTRS,
reserved_attrs: Union[Tuple[str, ...], List[str]] = RESERVED_ATTRS,
timestamp: Union[bool, str] = False,
**kwargs: Any
**kwargs: Any,
):
"""
:param json_default: a function for encoding non-standard objects
Expand Down Expand Up @@ -197,8 +202,7 @@ def parse(self) -> List[str]:

if self._fmt:
return formatter_style_pattern.findall(self._fmt)
else:
return []
return []

def add_fields(
self,
Expand Down
8 changes: 5 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
[tox]
requires = tox>=3
envlist = lint, type, pypy{38,39}, py{36,37,38,39,310,311}
envlist = lint, type, pypy{37,38,39,310}, py{37,38,39,310,311,312}

[gh-actions]
python =
pypy-3.7: pypy37
pypy-3.8: pypy38
pypy-3.9: pypy39
3.6: py36
pypy-3.10: pypy310
3.7: py37
3.8: py38
3.9: py39
3.10: py310
3.11: py311, type
3.11: py311
3.12: py312, type

[testenv]
description = run unit tests
Expand Down

0 comments on commit 19bfb64

Please sign in to comment.