From afc9fc2643d2bac8c5541895466c5f7cb8436c11 Mon Sep 17 00:00:00 2001 From: Giordon Stark Date: Tue, 24 Oct 2023 15:35:17 -0700 Subject: [PATCH] fix(backport): Remove os-dependent pieces of schema validation * Backport PR https://github.com/scikit-hep/pyhf/pull/ 2357 * Use pathlib to build the stem for the schema to use (version + type of schema). - c.f. https://github.com/python/cpython/issues/65238 --- src/pyhf/schema/validator.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/pyhf/schema/validator.py b/src/pyhf/schema/validator.py index 1fbc36c686..2540a3d002 100644 --- a/src/pyhf/schema/validator.py +++ b/src/pyhf/schema/validator.py @@ -1,4 +1,5 @@ import numbers +from pathlib import Path from typing import Mapping, Union import jsonschema @@ -70,12 +71,15 @@ def validate( version = version or variables.SCHEMA_VERSION - schema = load_schema(f'{version}/{schema_name}') + schema = load_schema(str(Path(version).joinpath(schema_name))) - # note: trailing slash needed for RefResolver to resolve correctly + # note: trailing slash needed for RefResolver to resolve correctly and by + # design, pathlib strips trailing slashes. See ref below: + # * https://bugs.python.org/issue21039 + # * https://github.com/python/cpython/issues/65238 resolver = jsonschema.RefResolver( - base_uri=f"file://{variables.schemas}/{version}/", - referrer=f"{schema_name}", + base_uri=f"{Path(variables.schemas).joinpath(version).as_uri()}/", + referrer=schema_name, store=variables.SCHEMA_CACHE, )