From 49ffa0c0a6b00b2d8afbf2a03f7bcf2db7466b6c Mon Sep 17 00:00:00 2001 From: Matthew Feickert Date: Wed, 25 Oct 2023 01:08:18 -0500 Subject: [PATCH] fix(backport): Remove os-dependent pieces of schema validation (#2361) * 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 Co-authored-by: Giordon Stark --- 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, )