From 4e0d2d14c9e611b41a3168e3b39178bece662075 Mon Sep 17 00:00:00 2001 From: soksanichenko Date: Fri, 11 Nov 2022 16:31:43 +0200 Subject: [PATCH] - Unify branch for both RHEL versions --- pungi/checks.py | 53 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/pungi/checks.py b/pungi/checks.py index 25a343fb..c4b39613 100644 --- a/pungi/checks.py +++ b/pungi/checks.py @@ -39,6 +39,7 @@ from __future__ import print_function import multiprocessing import os.path import platform +import distro import re import jsonschema @@ -450,22 +451,42 @@ def _extend_with_default_and_alias(validator_class, offline=False): def is_string_type(checker, instance): return isinstance(instance, six.string_types) - validator = jsonschema.validators.extend( - validator_class, - { - "properties": properties_validator, - "deprecated": error_on_deprecated, - "type": validate_regex_type, - "required": _validate_required, - "additionalProperties": _validate_additional_properties, - "anyOf": _validate_any_of, - }, - ) - validator.DEFAULT_TYPES.update({ - "array": (list, tuple), - "regex": six.string_types, - "url": six.string_types, - }) + # RHEL9 has newer version of package jsonschema + # which has another way of working with validators + if float(distro.linux_distribution()[1]) < 9: + validator = jsonschema.validators.extend( + validator_class, + { + "properties": properties_validator, + "deprecated": error_on_deprecated, + "type": validate_regex_type, + "required": _validate_required, + "additionalProperties": _validate_additional_properties, + "anyOf": _validate_any_of, + }, + ) + validator.DEFAULT_TYPES.update({ + "array": (list, tuple), + "regex": six.string_types, + "url": six.string_types, + }) + else: + type_checker = validator_class.TYPE_CHECKER.redefine_many( + {"array": is_array, "regex": is_string_type, "url": is_string_type} + ) + + validator = jsonschema.validators.extend( + validator_class, + { + "properties": properties_validator, + "deprecated": error_on_deprecated, + "type": validate_regex_type, + "required": _validate_required, + "additionalProperties": _validate_additional_properties, + "anyOf": _validate_any_of, + }, + type_checker=type_checker, + ) return validator