Skip to content

Commit 441b1a0

Browse files
authored
remove jsonschema version constrain (PolusAI#287)
* remove jsonschema version constrain * Use referencing library * Fix lint * Fix lint * update schema validatoin code
1 parent 61abb94 commit 441b1a0

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ dependencies = [
2222
# This 'graphviz' is equivalent to `conda install python-graphviz` or
2323
# `sudo apt install python3-graphviz` ONLY.
2424
"graphviz",
25-
"jsonschema<4.18", # temporarily downgrade due to severe performance regression
25+
"jsonschema",
2626
"pyyaml",
2727
"requests",
2828
"mergedeep",
@@ -42,7 +42,8 @@ dependencies = [
4242
"toil[cwl]",
4343
"fastapi",
4444
"python-jose",
45-
"uvicorn"
45+
"uvicorn",
46+
"referencing"
4647
]
4748

4849
[project.readme]

src/sophios/schemas/wic_schema.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66
import networkx as nx
77
import graphviz
8-
from jsonschema import RefResolver, Draft202012Validator
8+
from jsonschema import Draft202012Validator
9+
from referencing import Registry, Resource
10+
from referencing.jsonschema import DRAFT202012
911
import yaml
1012

1113
import sophios
@@ -680,7 +682,6 @@ def get_validator(tools_cwl: Tools, yml_stems: List[str], schema_store: Dict[str
680682

681683
schema = wic_main_schema(tools_cwl, yml_stems, schema_store, hypothesis)
682684
schema_store[schema['$id']] = schema
683-
schema_store['wic_tag'] = wic_tag_schema(hypothesis)
684685
if write_to_disk:
685686
with open('autogenerated/schemas/wic.json', mode='w', encoding='utf-8') as f:
686687
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
696697
# The $ref tag refers to URIs defined in $id tags, NOT relative paths on
697698
# the local filesystem! We need to create a global mapping between ids and schemas
698699
# i.e. schema_store.
699-
resolver = RefResolver.from_schema(schema, store=schema_store)
700+
schema_store_resource: Resource = Resource(contents=schema_store, specification=DRAFT202012) # type: ignore
701+
registry: Registry = Registry().with_resource(uri="wic_schema_store", resource=schema_store_resource)
702+
wic_tag_schema_resource: Resource = Resource(contents=wic_tag_schema(
703+
hypothesis), specification=DRAFT202012) # type: ignore
704+
registry = registry.with_resource(uri="wic_tag", resource=wic_tag_schema_resource)
700705
""" Use check_schema to 'first verify that the provided schema is
701706
itself valid, since not doing so can lead to less obvious error
702707
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
707712
# try temporarily commenting this line out to generate the schema anyway.
708713
# Then, in any yml file, the very first line should show a "schema stack trace"
709714
Draft202012Validator.check_schema(schema)
710-
validator = Draft202012Validator(schema, resolver=resolver)
715+
validator = Draft202012Validator(schema, registry=registry)
711716
return validator

0 commit comments

Comments
 (0)