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 jsonschema-rs == 0.18.0
toml == 0.10.2

View File

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