From e4bbaf5567d15bec59499529ad404964ff8ae94b Mon Sep 17 00:00:00 2001 From: M Bussonnier Date: Tue, 17 Dec 2024 10:24:29 +0100 Subject: [PATCH] be explict about versions for later cleanup --- jupyter_events/logger.py | 13 +++++++++---- pyproject.toml | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/jupyter_events/logger.py b/jupyter_events/logger.py index d25ccc0..e1de4fc 100644 --- a/jupyter_events/logger.py +++ b/jupyter_events/logger.py @@ -10,13 +10,12 @@ import typing as t import warnings from datetime import datetime, timezone +from importlib.metadata import version from jsonschema import ValidationError +from packaging.version import parse -try: - from pythonjsonlogger.json import JsonFormatter -except ImportError: - from pythonjsonlogger.jsonlogger import JsonFormatter +# Check if the version is greater than 3.0.0 from traitlets import Dict, Instance, Set, default from traitlets.config import Config, LoggingConfigurable @@ -25,6 +24,12 @@ from .traits import Handlers from .validators import JUPYTER_EVENTS_CORE_VALIDATOR +version_info = version("pythonjsonlogger") +if parse(version_info) >= parse("3.1.0"): + from pythonjsonlogger.json import JsonFormatter +else: + from pythonjsonlogger.jsonlogger import JsonFormatter + # Increment this version when the metadata included with each event # changes. EVENTS_METADATA_VERSION = 1 diff --git a/pyproject.toml b/pyproject.toml index c07baca..e5281e9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -181,6 +181,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)