From 0abf937b0eeafa96e2cbdce0c47c350a88789d5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Tue, 9 Aug 2022 15:10:38 +0200 Subject: [PATCH] Fix compatibility with jsonschema >= 4.0.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fedora Rawhide (to be 37) packages jsonschema 4.9.0 at the moment, so we can no longer get by with limiting the requirements. This patch makes the validation work with both old and new version. Fixes: rhbz#2113607 Signed-off-by: Lubomír Sedlář --- pungi/checks.py | 12 +++++++++++- requirements.txt | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/pungi/checks.py b/pungi/checks.py index bc5d908f..6d4465ed 100644 --- a/pungi/checks.py +++ b/pungi/checks.py @@ -229,7 +229,6 @@ def validate(config, offline=False, schema=None): ) validator = DefaultValidator( schema, - {"array": (tuple, list), "regex": six.string_types, "url": six.string_types}, ) errors = [] warnings = [] @@ -445,6 +444,16 @@ def _extend_with_default_and_alias(validator_class, offline=False): context=all_errors, ) + def is_array(checker, instance): + return isinstance(instance, (tuple, list)) + + def is_string_type(checker, instance): + return isinstance(instance, six.string_types) + + type_checker = validator_class.TYPE_CHECKER.redefine_many( + {"array": is_array, "regex": is_string_type, "url": is_string_type} + ) + return jsonschema.validators.extend( validator_class, { @@ -455,6 +464,7 @@ def _extend_with_default_and_alias(validator_class, offline=False): "additionalProperties": _validate_additional_properties, "anyOf": _validate_any_of, }, + type_checker=type_checker, ) diff --git a/requirements.txt b/requirements.txt index 4eba1ca4..ee73d0c3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ dict.sorted dogpile.cache fedmsg funcsigs -jsonschema < 4.0.0 +jsonschema kobo koji lxml