Skip to content

Commit 6203a8f

Browse files
authored
fix: Remove os-dependent pieces of schema validation (#2357)
* Use pathlib to build the stem for the schema to use (version + type of schema). - c.f. python/cpython#65238
1 parent 5093668 commit 6203a8f

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/pyhf/schema/validator.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import numbers
2+
from pathlib import Path
23
from typing import Mapping, Union
34

45
import jsonschema
@@ -70,12 +71,15 @@ def validate(
7071

7172
version = version or variables.SCHEMA_VERSION
7273

73-
schema = load_schema(f'{version}/{schema_name}')
74+
schema = load_schema(str(Path(version).joinpath(schema_name)))
7475

75-
# note: trailing slash needed for RefResolver to resolve correctly
76+
# note: trailing slash needed for RefResolver to resolve correctly and by
77+
# design, pathlib strips trailing slashes. See ref below:
78+
# * https://bugs.python.org/issue21039
79+
# * https://github.com/python/cpython/issues/65238
7680
resolver = jsonschema.RefResolver(
77-
base_uri=f"file://{variables.schemas}/{version}/",
78-
referrer=f"{schema_name}",
81+
base_uri=f"{Path(variables.schemas).joinpath(version).as_uri()}/",
82+
referrer=schema_name,
7983
store=variables.SCHEMA_CACHE,
8084
)
8185

0 commit comments

Comments
 (0)