Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
1"""2Load all the JSON Schema specification's official schemas.3"""4 5import json6 7try:8    from importlib.resources import files9except ImportError:10    from importlib_resources import (  # type: ignore[import-not-found, no-redef]11        files,12    )13 14from referencing import Resource15 16 17def _schemas():18    """19    All schemas we ship.20    """21    # importlib.resources.abc.Traversal doesn't have nice ways to do this that22    # I'm aware of...23    #24    # It can't recurse arbitrarily, e.g. no ``.glob()``.25    #26    # So this takes some liberties given the real layout of what we ship27    # (only 2 levels of nesting, no directories within the second level).28 29    for version in files(__package__).joinpath("schemas").iterdir():30        if version.name.startswith("."):31            continue32        for child in version.iterdir():33            children = [child] if child.is_file() else child.iterdir()34            for path in children:35                if path.name.startswith("."):36                    continue37                contents = json.loads(path.read_text(encoding="utf-8"))38                yield Resource.from_contents(contents)39 
codekingpro/portable-devtools · Team Ai