diff --git a/.github/workflows/code.yml b/.github/workflows/code.yml index ef74d363..08446c97 100644 --- a/.github/workflows/code.yml +++ b/.github/workflows/code.yml @@ -5,7 +5,7 @@ on: pull_request: env: # The target python version, which must match the Dockerfile version - CONTAINER_PYTHON: "3.11" + CONTAINER_PYTHON: "3.12" jobs: lint: @@ -32,8 +32,7 @@ jobs: fail-fast: false matrix: os: ["ubuntu-latest"] # can add windows-latest, macos-latest - python: ["3.9", "3.10", "3.11"] - jsonschema: [2, 3] + python: ["3.9", "3.10", "3.11", "3.12"] install: ["-e .[dev]"] # Make one version be non-editable to test both paths of version code @@ -59,7 +58,6 @@ jobs: uses: ./.github/actions/install_requirements with: python_version: ${{ matrix.python }} - jsonschema_version: ${{ matrix.jsonschema }} requirements_file: requirements-test-${{ matrix.os }}-${{matrix.python }}-${{ matrix.jsonschema }}.txt install_options: ${{ matrix.install }} diff --git a/event_model/__init__.py b/event_model/__init__.py index 3fec64a5..2abe7edc 100644 --- a/event_model/__init__.py +++ b/event_model/__init__.py @@ -7,15 +7,12 @@ import sys import threading import time as ttime -import types import uuid import warnings import weakref from collections import defaultdict, deque from dataclasses import dataclass from enum import Enum -from functools import partial -from importlib.metadata import metadata from importlib.metadata import version as importlib_version from typing import ( Any, @@ -35,7 +32,6 @@ import jsonschema import numpy -from packaging import version from typing_extensions import Literal from .documents.datum import Datum @@ -1806,43 +1802,26 @@ class MismatchedDataKeys(InvalidData): with ref.open() as f: schemas[name] = json.load(f) -# We pin jsonschema >=3.0.0 in requirements.txt but due to pip's dependency -# resolution it is easy to end up with an environment where that pin is not -# respected. Thus, we maintain best-effort support for 2.x. -if version.parse(metadata("jsonschema")["version"]) >= version.parse("3.0.0"): +def _is_array(checker, instance): + return ( + jsonschema.validators.Draft7Validator.TYPE_CHECKER.is_type(instance, "array") + or isinstance(instance, tuple) + or hasattr(instance, "__array__") + ) - def _is_array(checker, instance): - return ( - jsonschema.validators.Draft7Validator.TYPE_CHECKER.is_type( - instance, "array" - ) - or isinstance(instance, tuple) - or hasattr(instance, "__array__") - ) - _array_type_checker = jsonschema.validators.Draft7Validator.TYPE_CHECKER.redefine( - "array", _is_array - ) +_array_type_checker = jsonschema.validators.Draft7Validator.TYPE_CHECKER.redefine( + "array", _is_array +) - _Validator = jsonschema.validators.extend( - jsonschema.validators.Draft7Validator, type_checker=_array_type_checker - ) +_Validator = jsonschema.validators.extend( + jsonschema.validators.Draft7Validator, type_checker=_array_type_checker +) - schema_validators = { - name: _Validator(schema=schema) for name, schema in schemas.items() - } -else: - # Make objects that mock the one method on the jsonschema 3.x - # Draft7Validator API that we need. - schema_validators = { - name: types.SimpleNamespace( - validate=partial( - jsonschema.validate, schema=schema, types={"array": (list, tuple)} - ) - ) - for name, schema in schemas.items() - } +schema_validators = { + name: _Validator(schema=schema) for name, schema in schemas.items() +} @dataclass diff --git a/event_model/tests/test_em.py b/event_model/tests/test_em.py index 866810b7..45ead48e 100644 --- a/event_model/tests/test_em.py +++ b/event_model/tests/test_em.py @@ -1,16 +1,12 @@ import json import pickle -from distutils.version import LooseVersion -import jsonschema import numpy import pytest import event_model from event_model.documents.stream_datum import StreamRange -JSONSCHEMA_2 = LooseVersion(jsonschema.__version__) < LooseVersion("3.0.0") - def test_documents(): dn = event_model.DocumentNames @@ -1008,7 +1004,6 @@ def test_pickle_filler(): assert filler == deserialized -@pytest.mark.skipif(JSONSCHEMA_2, reason="requres jsonschema >= 3") def test_array_like(): "Accept any __array__-like as an array." dask_array = pytest.importorskip("dask.array") diff --git a/event_model/tests/test_projections.py b/event_model/tests/test_projections.py index 64587906..eed493ad 100644 --- a/event_model/tests/test_projections.py +++ b/event_model/tests/test_projections.py @@ -1,13 +1,8 @@ -from distutils.version import LooseVersion - -import jsonschema import pytest from jsonschema.exceptions import ValidationError import event_model -skip_json_validations = LooseVersion(jsonschema.__version__) < LooseVersion("3.0.0") - @pytest.fixture def start(): @@ -28,9 +23,6 @@ def test_projection_schema(start): event_model.schema_validators[event_model.DocumentNames.start].validate(start) -@pytest.mark.skipif( - skip_json_validations, reason="projection schema uses draft7 conditions" -) def test_bad_calc_field(start): bad_calc_projections = [ # calc requires the calc fields @@ -56,9 +48,6 @@ def test_bad_calc_field(start): event_model.schema_validators[event_model.DocumentNames.start].validate(start) -@pytest.mark.skipif( - skip_json_validations, reason="projection schema uses draft7 conditions" -) def test_bad_configuration_field(start): bad_configuration_projections = [ { @@ -85,9 +74,6 @@ def test_bad_configuration_field(start): event_model.schema_validators[event_model.DocumentNames.start].validate(start) -@pytest.mark.skipif( - skip_json_validations, reason="projection schema uses draft7 conditions" -) def test_bad_event_field(start): bad_event_projections = [ { @@ -111,9 +97,6 @@ def test_bad_event_field(start): event_model.schema_validators[event_model.DocumentNames.start].validate(start) -@pytest.mark.skipif( - skip_json_validations, reason="projection schema uses draft7 conditions" -) def test_bad_location_field(start): bad_event_projections = [ { @@ -137,9 +120,6 @@ def test_bad_location_field(start): event_model.schema_validators[event_model.DocumentNames.start].validate(start) -@pytest.mark.skipif( - skip_json_validations, reason="projection schema uses draft7 conditions" -) def test_bad_static_field(start): bad_event_projections = [ { diff --git a/pyproject.toml b/pyproject.toml index 7a7d8ca8..9bad3631 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,13 +11,13 @@ classifiers = [ "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", ] description = "Data model used by the bluesky ecosystem" dependencies = [ "importlib-resources", - "jsonschema", + "jsonschema>=3", "numpy", - "packaging", "typing_extensions" ] dynamic = ["version"] @@ -117,8 +117,8 @@ skipsdist=True # Don't create a virtualenv for the command, requires tox-direct plugin direct = True passenv = * -allowlist_externals = - pytest +allowlist_externals = + pytest pre-commit mypy sphinx-build