Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mnt py312 #289

Merged
merged 5 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .github/workflows/code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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 }}

Expand Down
51 changes: 15 additions & 36 deletions event_model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -35,7 +32,6 @@

import jsonschema
import numpy
from packaging import version
from typing_extensions import Literal

from .documents.datum import Datum
Expand Down Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions event_model/tests/test_em.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import json
import pickle
from distutils.version import LooseVersion

import jsonschema
import numpy
import pytest

import event_model

JSONSCHEMA_2 = LooseVersion(jsonschema.__version__) < LooseVersion("3.0.0")


def test_documents():
dn = event_model.DocumentNames
Expand Down Expand Up @@ -1030,7 +1026,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")
Expand Down
20 changes: 0 additions & 20 deletions event_model/tests/test_projections.py
Original file line number Diff line number Diff line change
@@ -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():
Expand All @@ -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
Expand All @@ -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 = [
{
Expand All @@ -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 = [
{
Expand All @@ -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 = [
{
Expand All @@ -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 = [
{
Expand Down
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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
Expand Down