Commit d20f6f54 authored by Vincent Stehlé's avatar Vincent Stehlé
Browse files

parser: handle yaml version



The yaml module has the FullLoader class since version 5.1 only; handle
this gracefully at runtime.

This fixes the following error:

  AttributeError: module 'yaml' has no attribute 'FullLoader'
Reported-by: Zhifei Yang's avatarZhifei Yang <zhifei.yang@arm.com>
Signed-off-by: Vincent Stehlé's avatarVincent Stehlé <vincent.stehle@arm.com>
parent ce6ecaf4
......@@ -7,6 +7,7 @@ import argparse
import csv
import logging
import json
from packaging import version
try:
import yaml
......@@ -19,6 +20,12 @@ if 'yaml' in sys.modules:
except ImportError:
from yaml import Dumper
# Not all yaml versions have a Loader argument.
if version.parse(yaml.__version__) >= version.parse('5.1'):
yaml_load_args = {'Loader': yaml.FullLoader}
else:
yaml_load_args = {}
#based loosley on https://stackoverflow.com/a/4391978
# returns a filtered dict of dicts that meet some Key-value pair.
......@@ -301,7 +308,7 @@ def use_config(cross_check, filename):
logging.debug(f'Read {filename}')
with open(filename, 'r') as yamlfile:
conf = yaml.load(yamlfile, Loader=yaml.FullLoader)
conf = yaml.load(yamlfile, **yaml_load_args)
logging.debug('{} rule(s)'.format(len(conf)))
sanitize_yaml(conf)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment