From 28e5bdb0f2fc78097c63becca3e6397899dab4b9 Mon Sep 17 00:00:00 2001 From: Martin Hoyer Date: Tue, 27 Aug 2024 15:24:54 +0200 Subject: [PATCH] Migrate from RefResolver to referencing library --- .gitignore | 2 ++ fmf/utils.py | 8 +++++--- setup.py | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 8e8280a5..6dab277b 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,5 @@ docs/_build docs/spec docs/stories __pycache__ +venv +.venv diff --git a/fmf/utils.py b/fmf/utils.py index 4e70fb61..ec5f9d3e 100644 --- a/fmf/utils.py +++ b/fmf/utils.py @@ -14,6 +14,8 @@ import jsonschema from filelock import FileLock, Timeout +from referencing import Registry +from referencing.jsonschema import DRAFT4 from ruamel.yaml import YAML, scalarstring from ruamel.yaml.comments import CommentedMap @@ -934,12 +936,12 @@ def validate_data(data, schema, schema_store=None): """ schema_store = schema_store or {} try: - resolver = jsonschema.RefResolver.from_schema( - schema, store=schema_store) + registry = Registry().with_resource(schema_store, DRAFT4.create_resource() + ) except AttributeError as error: raise JsonSchemaError(f'Provided schema cannot be loaded: {error}') - validator = jsonschema.Draft4Validator(schema, resolver=resolver) + validator = jsonschema.Draft4Validator(schema, registry=registry) try: validator.validate(data) diff --git a/setup.py b/setup.py index da308297..296f3840 100755 --- a/setup.py +++ b/setup.py @@ -24,6 +24,7 @@ 'ruamel.yaml', 'filelock', 'jsonschema', + 'referencing', ] extras_require = { 'docs': ['sphinx==7.2.4', 'sphinx-rtd-theme==1.3.0'],