ci: update and fix schema validation script (#1509)

* ci: update and fix schema validation script

* fix issue with tomllib.load
This commit is contained in:
Clement Tsang 2024-07-29 23:11:40 +00:00 committed by GitHub
parent 28972a1e64
commit 449d8b4315
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 7 deletions

View file

@ -1,2 +1 @@
jsonschema-rs == 0.17.1
toml == 0.10.2
jsonschema-rs == 0.18.0

View file

@ -3,7 +3,7 @@
# A simple script to validate that a schema is valid for a file.
import argparse
import toml
import tomllib
import jsonschema_rs
import re
import traceback
@ -38,7 +38,7 @@ def main():
should_fail = args.should_fail
uncomment = args.uncomment
with open(file) as f, open(schema) as s:
with open(file, "rb") as f, open(schema) as s:
try:
validator = jsonschema_rs.JSONSchema.from_str(s.read())
except:
@ -46,16 +46,16 @@ def main():
exit()
if uncomment:
read_file = f.read()
read_file = f.read().decode("utf-8")
read_file = re.sub(r"^#([a-zA-Z\[])", r"\1", read_file, flags=re.MULTILINE)
read_file = re.sub(
r"^#(\s\s+)([a-zA-Z\[])", r"\2", read_file, flags=re.MULTILINE
)
print(f"uncommented file: \n{read_file}")
toml_str = toml.loads(read_file)
toml_str = tomllib.loads(read_file)
else:
toml_str = toml.load(f)
toml_str = tomllib.load(f)
try:
validator.validate(toml_str)