diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index db04671..b1cf91d 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -18,12 +18,12 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest] - python-version: ["3.8", "3.12"] + python-version: ["3.9", "3.12"] include: - os: windows-latest python-version: "3.9" - os: ubuntu-latest - python-version: "pypy-3.8" + python-version: "pypy-3.9" - os: ubuntu-latest python-version: "3.10" - os: macos-latest @@ -44,10 +44,12 @@ jobs: - uses: jupyterlab/maintainer-tools/.github/actions/report-coverage@v1 docs: - runs-on: windows-latest + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1 + with: + python_version: 3.12 - run: hatch run docs:build test_lint: @@ -82,7 +84,7 @@ jobs: - name: Base Setup uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1 with: - dependency_type: minimum + python_version: 3.9 - name: Install with minimum versions and optional deps run: | pip install -e .[test] diff --git a/jupyter_events/logger.py b/jupyter_events/logger.py index 8cc1fba..00de2dd 100644 --- a/jupyter_events/logger.py +++ b/jupyter_events/logger.py @@ -10,9 +10,10 @@ import typing as t import warnings from datetime import datetime, timezone +from importlib.metadata import version from jsonschema import ValidationError -from pythonjsonlogger import jsonlogger +from packaging.version import parse from traitlets import Dict, Instance, Set, default from traitlets.config import Config, LoggingConfigurable @@ -21,6 +22,13 @@ from .traits import Handlers from .validators import JUPYTER_EVENTS_CORE_VALIDATOR +# Check if the version is greater than 3.1.0 +version_info = version("python-json-logger") +if parse(version_info) >= parse("3.1.0"): + from pythonjsonlogger.json import JsonFormatter +else: + from pythonjsonlogger.jsonlogger import JsonFormatter # type: ignore[attr-defined] + # Increment this version when the metadata included with each event # changes. EVENTS_METADATA_VERSION = 1 @@ -171,7 +179,7 @@ def _handle_message_field(record: t.Any, **kwargs: t.Any) -> str: del record["message"] return json.dumps(record, **kwargs) - formatter = jsonlogger.JsonFormatter( # type:ignore [no-untyped-call] + formatter = JsonFormatter( json_serializer=_handle_message_field, ) handler.setFormatter(formatter) diff --git a/jupyter_events/schema.py b/jupyter_events/schema.py index 49420e1..8c6bf85 100644 --- a/jupyter_events/schema.py +++ b/jupyter_events/schema.py @@ -3,7 +3,7 @@ import json from pathlib import Path, PurePath -from typing import Any, Dict, Union +from typing import Any, Union from jsonschema import FormatChecker, validators from referencing import Registry @@ -30,7 +30,7 @@ class EventSchemaFileAbsent(Exception): """An error for an absent event schema file.""" -SchemaType = Union[Dict[str, Any], str, PurePath] +SchemaType = Union[dict[str, Any], str, PurePath] class EventSchema: diff --git a/pyproject.toml b/pyproject.toml index c07baca..d879aa8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "hatchling.build" name = "jupyter-events" description = "Jupyter Event System library" readme = "README.md" -requires-python = ">=3.8" +requires-python = ">=3.9" authors = [ { name = "Jupyter Development Team", email = "jupyter@googlegroups.com" }, ] @@ -52,9 +52,10 @@ jupyter-events = "jupyter_events.cli:main" [project.optional-dependencies] docs = [ + "sphinx>=8", "jupyterlite-sphinx", "myst_parser", - "pydata_sphinx_theme", + "pydata_sphinx_theme>=0.16", "sphinxcontrib-spelling", ] test = [ @@ -150,7 +151,7 @@ source = ["jupyter_events"] [tool.mypy] files = "jupyter_events" -python_version = "3.8" +python_version = "3.9" strict = true enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"] warn_unreachable = true @@ -181,6 +182,7 @@ extend-select = [ "EXE", # flake8-executable "PYI", # flake8-pyi "S", # flake8-bandit + "G001", # .format and co in logging methods ] ignore = [ "E501", # E501 Line too long (158 > 100 characters) diff --git a/tests/test_logger.py b/tests/test_logger.py index 8a0a499..28a8fc6 100644 --- a/tests/test_logger.py +++ b/tests/test_logger.py @@ -3,7 +3,6 @@ import io import json import logging -import sys from datetime import datetime, timedelta, timezone from unittest.mock import MagicMock @@ -166,8 +165,6 @@ def test_emit(): "__metadata_version__": 1, "something": "blah", } - if sys.version_info >= (3, 12): - expected["taskName"] = None assert event_capsule == expected @@ -214,8 +211,6 @@ def test_message_field(): "something": "blah", "message": "a message was seen", } - if sys.version_info >= (3, 12): - expected["taskName"] = None assert event_capsule == expected @@ -263,8 +258,6 @@ def test_nested_message_field(): "__metadata_version__": 1, "thing": {"message": "a nested message was seen"}, } - if sys.version_info >= (3, 12): - expected["taskName"] = None assert event_capsule == expected @@ -428,8 +421,6 @@ def test_unique_logger_instances(): "__metadata_version__": 1, "something": "blah", } - if sys.version_info >= (3, 12): - expected["taskName"] = None assert event_capsule0 == expected event_capsule1 = json.loads(output1.getvalue()) @@ -443,8 +434,6 @@ def test_unique_logger_instances(): "__metadata_version__": 1, "something": "blah", } - if sys.version_info >= (3, 12): - expected["taskName"] = None assert event_capsule1 == expected