Skip to content

Commit

Permalink
initial commit to try referencing library
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzebsiddiqui committed Jun 28, 2024
1 parent 1ba8f7c commit 3d8d58b
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion buildtest/schemas/defaults.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os

from jsonschema import Draft7Validator, RefResolver
from referencing import Registry, Resource
from referencing.jsonschema import DRAFT7

from buildtest.schemas.utils import load_schema

Expand Down Expand Up @@ -71,9 +73,39 @@
]["recipe"],
}

# Create a Registry object
initial_registry = Registry()

"""
resolver = RefResolver.from_schema(
schema_table["definitions.schema.json"]["recipe"], store=schema_store
)
"""
schemas = [
"global.schema.json",
"script.schema.json",
"spack.schema.json",
"definitions.schema.json",
"settings.schema.json",
]
for schema_file in schemas:
loaded = load_schema(os.path.join(here, schema_file))
resource = Resource.from_contents(loaded)
registry = resource @ initial_registry
# registry.with_resource(uri=schema_file, resource=Resource.from_contents(loaded))

print(initial_registry.contents)
import sys

sys.exit(0)
# Register your schemas with the registry
for schema_name in schema_table.keys():
print("XXX", schema_name)
resource = Resource.from_contents(schema_table[schema_name]["recipe"])
registry = resource @ registry

# registry.with_resource(uri=schema_name, resource=schema_table[schema_name]["recipe"])
print(base_registry)


def custom_validator(recipe, schema):
Expand All @@ -98,5 +130,6 @@ def custom_validator(recipe, schema):
assert isinstance(recipe, dict)
assert isinstance(schema, dict)

validator = Draft7Validator(schema, resolver=resolver)
validator = Draft7Validator(schema, resolver=registry.resolver)

validator.validate(recipe)

0 comments on commit 3d8d58b

Please sign in to comment.