Skip to content

Commit 57e8909

Browse files
committed
fix RefResolver with latest versions of jsonschema (relates to python-jsonschema/jsonschema#1049)
1 parent bcdf134 commit 57e8909

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ Fixes:
1818
------
1919
- Fix broken Docker build of ``weaver-worker`` image due to unresolved ``docker-ce-cli`` package.
2020
Installation is updated according to the reference documentation (https://docs.docker.com/engine/install/debian/).
21+
- Fix incorrect stream reader type (``bytes`` instead of ``str``) for some handlers in ``open_module_resource_file``.
22+
- Fix invalid ``jsonschema.validators.RefResolver`` reference in ``jsonschema>=4.18.0`` caused by refactor
23+
(see https://github.com/python-jsonschema/jsonschema/blob/main/CHANGELOG.rst#v4180
24+
and `python-jsonschema/jsonschema#1049 <https://github.com/python-jsonschema/jsonschema/pull/1049>`_).
2125

2226
.. _changes_4.30.0:
2327

weaver/utils.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import functools
55
import importlib.util
66
import inspect
7+
import io
78
import logging
89
import os
910
import posixpath
@@ -33,7 +34,6 @@
3334
from botocore.config import Config as S3Config
3435
from bs4 import BeautifulSoup
3536
from celery.app import Celery
36-
from jsonschema.validators import RefResolver as JsonSchemaRefResolver
3737
from mypy_boto3_s3.literals import RegionName
3838
from pyramid.config import Configurator
3939
from pyramid.exceptions import ConfigurationError
@@ -67,6 +67,11 @@
6767
from weaver.warning import TimeZoneInfoAlreadySetWarning
6868
from weaver.xml_util import HTML_TREE_BUILDER, XML
6969

70+
try: # refactor in jsonschema==4.18.0
71+
from jsonschema.validators import _RefResolver as JsonSchemaRefResolver # pylint: disable=E0611
72+
except ImportError:
73+
from jsonschema.validators import RefResolver as JsonSchemaRefResolver # pylint: disable=E0611
74+
7075
if TYPE_CHECKING:
7176
import importlib.abc
7277
from types import FrameType, ModuleType
@@ -1055,7 +1060,7 @@ def import_target(target, default_root=None):
10551060

10561061

10571062
def open_module_resource_file(module, file_path):
1058-
# type: (Union[str, ModuleType], str) -> IO[bytes]
1063+
# type: (Union[str, ModuleType], str) -> IO[str]
10591064
"""
10601065
Opens a resource (data file) from an installed module.
10611066
@@ -1070,7 +1075,8 @@ def open_module_resource_file(module, file_path):
10701075
reader = loader.get_resource_reader() # type: importlib.abc.ResourceReader # noqa
10711076
except AttributeError:
10721077
reader = loader # noqa
1073-
return reader.open_resource(file_path)
1078+
buffer = reader.open_resource(file_path)
1079+
return io.TextIOWrapper(buffer, encoding="utf-8")
10741080
except AttributeError:
10751081
path = os.path.join(module.__path__[0], file_path)
10761082
return open(path, mode="r", encoding="utf-8")

0 commit comments

Comments
 (0)