scripts: hwmv2: cache pykwalify validators
speed up the various list_*.py scripts by means of caching the pykwalify core object so that schemas don't get unnecessarily processed multiple times. Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
This commit is contained in:
parent
24b4ce189f
commit
061cbb7bc0
2 changed files with 12 additions and 4 deletions
|
@ -24,6 +24,8 @@ BOARD_SCHEMA_PATH = str(Path(__file__).parent / 'schemas' / 'board-schema.yml')
|
|||
with open(BOARD_SCHEMA_PATH, 'r') as f:
|
||||
board_schema = yaml.load(f.read(), Loader=SafeLoader)
|
||||
|
||||
BOARD_VALIDATOR = pykwalify.core.Core(schema_data=board_schema, source_data={})
|
||||
|
||||
BOARD_YML = 'board.yml'
|
||||
|
||||
#
|
||||
|
@ -230,7 +232,8 @@ def load_v2_boards(board_name, board_yml, systems):
|
|||
b = yaml.load(f.read(), Loader=SafeLoader)
|
||||
|
||||
try:
|
||||
pykwalify.core.Core(source_data=b, schema_data=board_schema).validate()
|
||||
BOARD_VALIDATOR.source = b
|
||||
BOARD_VALIDATOR.validate()
|
||||
except pykwalify.errors.SchemaError as e:
|
||||
sys.exit('ERROR: Malformed "build" section in file: {}\n{}'
|
||||
.format(board_yml.as_posix(), e))
|
||||
|
|
|
@ -22,10 +22,14 @@ SOC_SCHEMA_PATH = str(Path(__file__).parent / 'schemas' / 'soc-schema.yml')
|
|||
with open(SOC_SCHEMA_PATH, 'r') as f:
|
||||
soc_schema = yaml.load(f.read(), Loader=SafeLoader)
|
||||
|
||||
SOC_VALIDATOR = pykwalify.core.Core(schema_data=soc_schema, source_data={})
|
||||
|
||||
ARCH_SCHEMA_PATH = str(Path(__file__).parent / 'schemas' / 'arch-schema.yml')
|
||||
with open(ARCH_SCHEMA_PATH, 'r') as f:
|
||||
arch_schema = yaml.load(f.read(), Loader=SafeLoader)
|
||||
|
||||
ARCH_VALIDATOR = pykwalify.core.Core(schema_data=arch_schema, source_data={})
|
||||
|
||||
SOC_YML = 'soc.yml'
|
||||
ARCHS_YML_PATH = PurePath('arch/archs.yml')
|
||||
|
||||
|
@ -42,8 +46,8 @@ class Systems:
|
|||
|
||||
try:
|
||||
data = yaml.load(soc_yaml, Loader=SafeLoader)
|
||||
pykwalify.core.Core(source_data=data,
|
||||
schema_data=soc_schema).validate()
|
||||
SOC_VALIDATOR.source = data
|
||||
SOC_VALIDATOR.validate()
|
||||
except (yaml.YAMLError, pykwalify.errors.SchemaError) as e:
|
||||
sys.exit(f'ERROR: Malformed yaml {soc_yaml.as_posix()}', e)
|
||||
|
||||
|
@ -214,7 +218,8 @@ def find_v2_archs(args):
|
|||
archs = yaml.load(f.read(), Loader=SafeLoader)
|
||||
|
||||
try:
|
||||
pykwalify.core.Core(source_data=archs, schema_data=arch_schema).validate()
|
||||
ARCH_VALIDATOR.source = archs
|
||||
ARCH_VALIDATOR.validate()
|
||||
except pykwalify.errors.SchemaError as e:
|
||||
sys.exit('ERROR: Malformed "build" section in file: {}\n{}'
|
||||
.format(archs_yml.as_posix(), e))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue