YAML(typ="saf") fails with pure=True for docs containing embedded yaml docs
ruamel.yaml is a YAML 1.2 parser/emitter for Python
Brought to you by:
anthon
The minimal repro we have for this bug is here. This works on ruamel 0.17.21, breaks on >0.18 (18.6 confirmed). It works on any version if pure=False in the YAML() call.
import yaml
from ruamel.yaml import YAML
import io
x = {
'environment_variables': {
'EVAL_SPEC': "determined:\n metaconfig: jobs/templates/eval-exec-v2-metaconfig.yaml\n name: cceval-1b_lr32_cd72_dep\n project: pretrain-eval\n workspace: Dev\npodspec: ampere-small.yaml\n"
}
}
assert yaml.safe_load(x["environment_variables"]["EVAL_SPEC"])
y = YAML(typ="safe", pure=True)
stream = io.StringIO()
y.dump(x, stream=stream)
s = stream.getvalue()
print(s)
a = y.load(s)
b = yaml.safe_load(a['environment_variables']['EVAL_SPEC'])
print(b)
ParserError Traceback (most recent call last)
<ipython-input-1-03fdb81d998a> in <cell line: 20>()
18
19 a = y.load(s)
---> 20 b = yaml.safe_load(a['environment_variables']['EVAL_SPEC'])
21 print(b)
8 frames
/usr/local/lib/python3.10/dist-packages/yaml/parser.py in parse_block_mapping_key(self)
436 if not self.check_token(BlockEndToken):
437 token = self.peek_token()
--> 438 raise ParserError("while parsing a block mapping", self.marks[-1],
439 "expected <block end>, but found %r" % token.id, token.start_mark)
440 token = self.get_token()
It looks like you are also using PyYAML, which only supports a subset of YAML 1.1, and ruamel.yaml dumps by default to YAML 1.2. So I would expect you to use
y.version = (1, 1)
or similar to force YAML 1.1 output.It would also be useful if you include the actual value of
s