Skip to content

Commit eeaeb03

Browse files
committed
[ISAC]: dump_yaml return string if outfile is None
- replace deprecated `ruamel.yaml.round_trip_dump` with `utils.dump_yaml` - optimize dump_yaml in util to support dumping to string Signed-off-by: MingZhu Yan <[email protected]>
1 parent a4db7a6 commit eeaeb03

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

riscv-isac/riscv_isac/coverage.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ def __add__(self, o):
675675

676676
def pretty_print_yaml(yaml):
677677
res = ''''''
678-
for line in ruamel.yaml.round_trip_dump(yaml, indent=5, block_seq_indent=3).splitlines(True):
678+
for line in utils.dump_yaml(yaml).splitlines(True):
679679
res += line
680680
return res
681681

@@ -1662,7 +1662,7 @@ def compute(trace_file, test_name, cgf, parser_name, decoder_name, detailed, xle
16621662
rpt_str = gen_report(rcgf, detailed)
16631663
logger.info('Writing out updated cgf : ' + test_name + '.cgf')
16641664
dump_file = open(test_name+'.cgf', 'w')
1665-
dump_file.write(ruamel.yaml.round_trip_dump(rcgf, indent=5, block_seq_indent=3))
1665+
utils.dump_yaml(rcgf, test_name+'.cgf')
16661666
dump_file.close()
16671667

16681668
if sig_addrs:

riscv-isac/riscv_isac/utils.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# See LICENSE.incore for details
22

33
"""Common Utils """
4+
import io
45
import logging
56
import os
67
import pathlib
@@ -46,8 +47,15 @@ def get_value_at_location(elf_path, location, bytes):
4647
return int.from_bytes(value, byteorder='little', signed=False)
4748
return None
4849

49-
def dump_yaml(foo, outfile):
50-
yaml.dump(foo, outfile)
50+
def dump_yaml(foo, outfile = None):
51+
"""
52+
Dump yaml to outfile. If outfile is None, dump to string.
53+
"""
54+
if outfile is None:
55+
buf = io.StringIO()
56+
yaml.dump(foo, buf)
57+
return buf.getvalue()
58+
return yaml.dump(foo, outfile)
5159

5260
def load_yaml_file(foo):
5361
try:

0 commit comments

Comments
 (0)