From 441b1a06364b9274d483d250db3c95feb7e49387 Mon Sep 17 00:00:00 2001 From: Sameeul Bashir Samee Date: Tue, 12 Nov 2024 13:35:07 -0500 Subject: [PATCH] remove jsonschema version constrain (#287) * remove jsonschema version constrain * Use referencing library * Fix lint * Fix lint * update schema validatoin code --- pyproject.toml | 5 +++-- src/sophios/schemas/wic_schema.py | 13 +++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d9df3db9..f9a20db6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,7 +22,7 @@ dependencies = [ # This 'graphviz' is equivalent to `conda install python-graphviz` or # `sudo apt install python3-graphviz` ONLY. "graphviz", - "jsonschema<4.18", # temporarily downgrade due to severe performance regression + "jsonschema", "pyyaml", "requests", "mergedeep", @@ -42,7 +42,8 @@ dependencies = [ "toil[cwl]", "fastapi", "python-jose", - "uvicorn" + "uvicorn", + "referencing" ] [project.readme] diff --git a/src/sophios/schemas/wic_schema.py b/src/sophios/schemas/wic_schema.py index d5d07db4..e4dcd551 100644 --- a/src/sophios/schemas/wic_schema.py +++ b/src/sophios/schemas/wic_schema.py @@ -5,7 +5,9 @@ import networkx as nx import graphviz -from jsonschema import RefResolver, Draft202012Validator +from jsonschema import Draft202012Validator +from referencing import Registry, Resource +from referencing.jsonschema import DRAFT202012 import yaml import sophios @@ -680,7 +682,6 @@ def get_validator(tools_cwl: Tools, yml_stems: List[str], schema_store: Dict[str schema = wic_main_schema(tools_cwl, yml_stems, schema_store, hypothesis) schema_store[schema['$id']] = schema - schema_store['wic_tag'] = wic_tag_schema(hypothesis) if write_to_disk: with open('autogenerated/schemas/wic.json', mode='w', encoding='utf-8') as f: f.write(json.dumps(schema, indent=2)) @@ -696,7 +697,11 @@ def get_validator(tools_cwl: Tools, yml_stems: List[str], schema_store: Dict[str # The $ref tag refers to URIs defined in $id tags, NOT relative paths on # the local filesystem! We need to create a global mapping between ids and schemas # i.e. schema_store. - resolver = RefResolver.from_schema(schema, store=schema_store) + schema_store_resource: Resource = Resource(contents=schema_store, specification=DRAFT202012) # type: ignore + registry: Registry = Registry().with_resource(uri="wic_schema_store", resource=schema_store_resource) + wic_tag_schema_resource: Resource = Resource(contents=wic_tag_schema( + hypothesis), specification=DRAFT202012) # type: ignore + registry = registry.with_resource(uri="wic_tag", resource=wic_tag_schema_resource) """ Use check_schema to 'first verify that the provided schema is itself valid, since not doing so can lead to less obvious error messages and fail in less obvious or consistent ways.' @@ -707,5 +712,5 @@ def get_validator(tools_cwl: Tools, yml_stems: List[str], schema_store: Dict[str # try temporarily commenting this line out to generate the schema anyway. # Then, in any yml file, the very first line should show a "schema stack trace" Draft202012Validator.check_schema(schema) - validator = Draft202012Validator(schema, resolver=resolver) + validator = Draft202012Validator(schema, registry=registry) return validator