forked from pool/python-jupyter-events
210 lines
7.3 KiB
Diff
210 lines
7.3 KiB
Diff
|
From d7c265b3362d68a4796f08f852745a3fd300d9ca Mon Sep 17 00:00:00 2001
|
||
|
From: Carlos Herrero <26092748+hbcarlos@users.noreply.github.com>
|
||
|
Date: Wed, 12 Jul 2023 17:58:15 +0200
|
||
|
Subject: [PATCH 01/15] Migrate RefResolver to referencing.Registry
|
||
|
|
||
|
---
|
||
|
jupyter_events/schema.py | 11 ++++++-----
|
||
|
jupyter_events/validators.py | 16 +++++++++++-----
|
||
|
pyproject.toml | 1 +
|
||
|
3 files changed, 18 insertions(+), 10 deletions(-)
|
||
|
|
||
|
Index: jupyter_events-0.6.3/jupyter_events/schema.py
|
||
|
===================================================================
|
||
|
--- jupyter_events-0.6.3.orig/jupyter_events/schema.py
|
||
|
+++ jupyter_events-0.6.3/jupyter_events/schema.py
|
||
|
@@ -3,7 +3,9 @@ import json
|
||
|
from pathlib import Path, PurePath
|
||
|
from typing import Optional, Type, Union
|
||
|
|
||
|
-from jsonschema import FormatChecker, RefResolver, validators
|
||
|
+from jsonschema import FormatChecker, validators
|
||
|
+from referencing import Registry
|
||
|
+from referencing.jsonschema import DRAFT7
|
||
|
|
||
|
try:
|
||
|
from jsonschema.protocols import Validator
|
||
|
@@ -55,8 +57,8 @@ class EventSchema:
|
||
|
any schema registered here follows the expected form
|
||
|
of Jupyter Events.
|
||
|
|
||
|
- resolver:
|
||
|
- RefResolver for nested JSON schema references.
|
||
|
+ registry:
|
||
|
+ Registry for nested JSON schema references.
|
||
|
"""
|
||
|
|
||
|
def __init__(
|
||
|
@@ -64,14 +66,18 @@ class EventSchema:
|
||
|
schema: SchemaType,
|
||
|
validator_class: Type[Validator] = validators.Draft7Validator, # type:ignore[assignment]
|
||
|
format_checker: FormatChecker = draft7_format_checker,
|
||
|
- resolver: Optional[RefResolver] = None,
|
||
|
+ registry: Optional[Registry] = None,
|
||
|
):
|
||
|
"""Initialize an event schema."""
|
||
|
_schema = self._load_schema(schema)
|
||
|
# Validate the schema against Jupyter Events metaschema.
|
||
|
validate_schema(_schema)
|
||
|
+
|
||
|
+ if registry is None:
|
||
|
+ registry = DRAFT7.create_resource(_schema) @ Registry()
|
||
|
+
|
||
|
# Create a validator for this schema
|
||
|
- self._validator = validator_class(_schema, resolver=resolver, format_checker=format_checker)
|
||
|
+ self._validator = validator_class(_schema, registry=registry, format_checker=format_checker) # type: ignore
|
||
|
self._schema = _schema
|
||
|
|
||
|
def __repr__(self):
|
||
|
Index: jupyter_events-0.6.3/jupyter_events/validators.py
|
||
|
===================================================================
|
||
|
--- jupyter_events-0.6.3.orig/jupyter_events/validators.py
|
||
|
+++ jupyter_events-0.6.3/jupyter_events/validators.py
|
||
|
@@ -2,7 +2,9 @@
|
||
|
import pathlib
|
||
|
|
||
|
import jsonschema
|
||
|
-from jsonschema import Draft7Validator, RefResolver, ValidationError
|
||
|
+from jsonschema import Draft7Validator, ValidationError
|
||
|
+from referencing import Registry
|
||
|
+from referencing.jsonschema import DRAFT7
|
||
|
|
||
|
draft7_format_checker = (
|
||
|
Draft7Validator.FORMAT_CHECKER
|
||
|
@@ -29,19 +31,21 @@ SCHEMA_STORE = {
|
||
|
EVENT_CORE_SCHEMA["$id"]: EVENT_CORE_SCHEMA,
|
||
|
}
|
||
|
|
||
|
-METASCHEMA_RESOLVER = RefResolver(
|
||
|
- base_uri=EVENT_METASCHEMA["$id"], referrer=EVENT_METASCHEMA, store=SCHEMA_STORE
|
||
|
-)
|
||
|
+resources = [
|
||
|
+ DRAFT7.create_resource(each)
|
||
|
+ for each in (EVENT_METASCHEMA, PROPERTY_METASCHEMA, EVENT_CORE_SCHEMA)
|
||
|
+]
|
||
|
+METASCHEMA_REGISTRY: Registry = resources @ Registry()
|
||
|
|
||
|
-JUPYTER_EVENTS_SCHEMA_VALIDATOR = Draft7Validator(
|
||
|
+JUPYTER_EVENTS_SCHEMA_VALIDATOR = Draft7Validator( # type: ignore
|
||
|
schema=EVENT_METASCHEMA,
|
||
|
- resolver=METASCHEMA_RESOLVER,
|
||
|
+ registry=METASCHEMA_REGISTRY,
|
||
|
format_checker=draft7_format_checker,
|
||
|
)
|
||
|
|
||
|
-JUPYTER_EVENTS_CORE_VALIDATOR = Draft7Validator(
|
||
|
+JUPYTER_EVENTS_CORE_VALIDATOR = Draft7Validator( # type: ignore
|
||
|
schema=EVENT_CORE_SCHEMA,
|
||
|
- resolver=METASCHEMA_RESOLVER,
|
||
|
+ registry=METASCHEMA_REGISTRY,
|
||
|
format_checker=draft7_format_checker,
|
||
|
)
|
||
|
|
||
|
Index: jupyter_events-0.6.3/pyproject.toml
|
||
|
===================================================================
|
||
|
--- jupyter_events-0.6.3.orig/pyproject.toml
|
||
|
+++ jupyter_events-0.6.3/pyproject.toml
|
||
|
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
|
||
|
name = "jupyter-events"
|
||
|
description = "Jupyter Event System library"
|
||
|
readme = "README.md"
|
||
|
-requires-python = ">=3.7"
|
||
|
+requires-python = ">=3.8"
|
||
|
authors = [
|
||
|
{ name = "Jupyter Development Team", email = "jupyter@googlegroups.com" },
|
||
|
]
|
||
|
@@ -23,7 +23,8 @@ classifiers = [
|
||
|
"Programming Language :: Python :: 3",
|
||
|
]
|
||
|
dependencies = [
|
||
|
- "jsonschema[format-nongpl,format_nongpl]>=3.2.0",
|
||
|
+ "referencing",
|
||
|
+ "jsonschema[format-nongpl,format_nongpl]>=4.18.0",
|
||
|
"python-json-logger>=2.0.4",
|
||
|
"pyyaml>=5.3",
|
||
|
"traitlets>=5.3",
|
||
|
Index: jupyter_events-0.6.3/.github/workflows/python-tests.yml
|
||
|
===================================================================
|
||
|
--- jupyter_events-0.6.3.orig/.github/workflows/python-tests.yml
|
||
|
+++ jupyter_events-0.6.3/.github/workflows/python-tests.yml
|
||
|
@@ -18,7 +18,7 @@ jobs:
|
||
|
fail-fast: false
|
||
|
matrix:
|
||
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||
|
- python-version: ["3.7", "3.11"]
|
||
|
+ python-version: ["3.8", "3.12"]
|
||
|
include:
|
||
|
- os: windows-latest
|
||
|
python-version: "3.9"
|
||
|
@@ -27,7 +27,7 @@ jobs:
|
||
|
- os: ubuntu-latest
|
||
|
python-version: "3.10"
|
||
|
- os: macos-latest
|
||
|
- python-version: "3.8"
|
||
|
+ python-version: "3.11"
|
||
|
steps:
|
||
|
- uses: actions/checkout@v3
|
||
|
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
|
||
|
Index: jupyter_events-0.6.3/tests/test_logger.py
|
||
|
===================================================================
|
||
|
--- jupyter_events-0.6.3.orig/tests/test_logger.py
|
||
|
+++ jupyter_events-0.6.3/tests/test_logger.py
|
||
|
@@ -1,6 +1,7 @@
|
||
|
import io
|
||
|
import json
|
||
|
import logging
|
||
|
+import sys
|
||
|
from datetime import datetime, timedelta
|
||
|
from unittest.mock import MagicMock
|
||
|
|
||
|
@@ -158,12 +159,15 @@ def test_emit():
|
||
|
assert "__timestamp__" in event_capsule
|
||
|
# Remove timestamp from capsule when checking equality, since it is gonna vary
|
||
|
del event_capsule["__timestamp__"]
|
||
|
- assert event_capsule == {
|
||
|
+ expected = {
|
||
|
"__schema__": "http://test/test",
|
||
|
"__schema_version__": 1,
|
||
|
"__metadata_version__": 1,
|
||
|
"something": "blah",
|
||
|
}
|
||
|
+ if sys.version_info >= (3, 12):
|
||
|
+ expected["taskName"] = None
|
||
|
+ assert event_capsule == expected
|
||
|
|
||
|
|
||
|
def test_register_event_schema(tmp_path):
|
||
|
@@ -320,24 +324,30 @@ def test_unique_logger_instances():
|
||
|
assert "__timestamp__" in event_capsule0
|
||
|
# Remove timestamp from capsule when checking equality, since it is gonna vary
|
||
|
del event_capsule0["__timestamp__"]
|
||
|
- assert event_capsule0 == {
|
||
|
+ expected = {
|
||
|
"__schema__": "http://test/test0",
|
||
|
"__schema_version__": 1,
|
||
|
"__metadata_version__": 1,
|
||
|
"something": "blah",
|
||
|
}
|
||
|
+ if sys.version_info >= (3, 12):
|
||
|
+ expected["taskName"] = None
|
||
|
+ assert event_capsule0 == expected
|
||
|
|
||
|
event_capsule1 = json.loads(output1.getvalue())
|
||
|
|
||
|
assert "__timestamp__" in event_capsule1
|
||
|
# Remove timestamp from capsule when checking equality, since it is gonna vary
|
||
|
del event_capsule1["__timestamp__"]
|
||
|
- assert event_capsule1 == {
|
||
|
+ expected = {
|
||
|
"__schema__": "http://test/test1",
|
||
|
"__schema_version__": 1,
|
||
|
"__metadata_version__": 1,
|
||
|
"something": "blah",
|
||
|
}
|
||
|
+ if sys.version_info >= (3, 12):
|
||
|
+ expected["taskName"] = None
|
||
|
+ assert event_capsule1 == expected
|
||
|
|
||
|
|
||
|
def test_register_duplicate_schemas():
|