From 449d8b4315eecce54306a9af760e0da65e454380 Mon Sep 17 00:00:00 2001 From: Clement Tsang <34804052+ClementTsang@users.noreply.github.com> Date: Mon, 29 Jul 2024 23:11:40 +0000 Subject: [PATCH] ci: update and fix schema validation script (#1509) * ci: update and fix schema validation script * fix issue with tomllib.load --- scripts/schema/requirements.txt | 3 +-- scripts/schema/validator.py | 10 +++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/scripts/schema/requirements.txt b/scripts/schema/requirements.txt index 1db290b1..b8703629 100644 --- a/scripts/schema/requirements.txt +++ b/scripts/schema/requirements.txt @@ -1,2 +1 @@ -jsonschema-rs == 0.17.1 -toml == 0.10.2 \ No newline at end of file +jsonschema-rs == 0.18.0 diff --git a/scripts/schema/validator.py b/scripts/schema/validator.py index 7a2902d1..94060f6e 100644 --- a/scripts/schema/validator.py +++ b/scripts/schema/validator.py @@ -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)