Skip to content

Commit

Permalink
fix(backport): Remove os-dependent pieces of schema validation
Browse files Browse the repository at this point in the history
* 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. python/cpython#65238
  • Loading branch information
kratsg authored and matthewfeickert committed Oct 25, 2023
1 parent 9caaf1d commit afc9fc2
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/pyhf/schema/validator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numbers
from pathlib import Path
from typing import Mapping, Union

import jsonschema
Expand Down Expand Up @@ -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,
)

Expand Down

0 comments on commit afc9fc2

Please sign in to comment.