From 7a02abe501ed3f8bed9d0850bc2788f2dfe8e8a1 Mon Sep 17 00:00:00 2001 From: Umer Shahid Date: Wed, 13 Nov 2024 13:59:53 +0500 Subject: [PATCH] Resolved the bug in ISAC -> local variable 'yaml' referenced before assignment (#556) * Resolved the bug in ISAC -> local variable 'yaml' referenced before assignment * Removed the redundent files of riscof_work --- requirements.txt | 2 +- riscv-isac/riscv_isac/utils.py | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) mode change 100644 => 100755 requirements.txt diff --git a/requirements.txt b/requirements.txt old mode 100644 new mode 100755 index 8961b1b99..40b8fe2b0 --- a/requirements.txt +++ b/requirements.txt @@ -34,7 +34,7 @@ PyYAML>=5.1.1 requests>=2.22.0 restructuredtext-lint>=1.3.0 riscv_isac>=0.14.0 -ruamel.yaml>=0.16.0 +ruamel.yaml>=0.18.0 six>=1.12.0 smmap2>=2.0.5 snowballstemmer>=1.2.1 diff --git a/riscv-isac/riscv_isac/utils.py b/riscv-isac/riscv_isac/utils.py index 1817f5b13..bfa652954 100644 --- a/riscv-isac/riscv_isac/utils.py +++ b/riscv-isac/riscv_isac/utils.py @@ -52,19 +52,28 @@ def get_value_at_location(elf_path, location, bytes): return int.from_bytes(value, byteorder='little', signed=False) return None -def dump_yaml(foo, outfile = None, indent = None, block_seq_indent = None): +def dump_yaml(foo, outfile=None, indent=None, block_seq_indent=None): """ Dump yaml to outfile. If outfile is None, dump to string. If indent or - block_seq_indent is set, create a new yaml object with suchconfig. + block_seq_indent is set, create a new yaml object with such config. """ - if indent is not None or block_seq_indent is not None: - yaml = create_yaml(indent=indent, block_seq_indent=block_seq_indent) + # Create a default yaml object if no custom settings are provided + yaml = create_yaml() if indent is None and block_seq_indent is None else create_yaml(indent=indent, block_seq_indent=block_seq_indent) + if outfile is None: buf = io.StringIO() yaml.dump(foo, buf) return buf.getvalue() return yaml.dump(foo, outfile) +def create_yaml(indent=None, block_seq_indent=None): + yaml = ruamel.yaml.YAML() + if indent is not None: + yaml.indent = indent + if block_seq_indent is not None: + yaml.block_seq_indent = block_seq_indent + return yaml + def load_yaml_file(foo): try: with open(foo, "r") as file: