Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/jsonschema_specifications/_core.py: 100%
13 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-08 06:51 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-08 06:51 +0000
1"""
2Load all the JSON Schema specification's official schemas.
3"""
5import json
7try:
8 from importlib.resources import files
9except ImportError:
10 from importlib_resources import files # type: ignore
12from referencing import Resource
15def _schemas():
16 """
17 All schemas we ship.
18 """
19 # importlib.resources.abc.Traversal doesn't have nice ways to do this that
20 # I'm aware of...
21 #
22 # It can't recurse arbitrarily, e.g. no ``.glob()``.
23 #
24 # So this takes some liberties given the real layout of what we ship
25 # (only 2 levels of nesting, no directories within the second level).
27 for version in files(__package__).joinpath("schemas").iterdir():
28 for child in version.iterdir():
29 children = [child] if child.is_file() else child.iterdir()
30 for path in children:
31 contents = json.loads(path.read_text(encoding="utf-8"))
32 yield Resource.from_contents(contents)