[yeb] YAML format for ebfiles_repo#1822
Conversation
| YAML_DIR = r'%YAML' | ||
| YAML_SEP = '---' | ||
| YEB_FORMAT_EXTENSION = '.yeb' | ||
| EB_FORMAT_EXTENSION = '.eb' |
There was a problem hiding this comment.
this belongs in format/one.py since it has nothing to do with the .yeb format?
|
@Caylo you should look into a test for this too, i.e. build & install toy easyconfig, and check whether the dumped easyconfig can be parsed again, both for |
| if set(YAML_SPECIAL_CHARS).intersection(val): | ||
| return "'%s'" % val | ||
|
|
||
| return val |
| """ | ||
| if isinstance(val, basestring): | ||
| if YAML_SPECIAL_CHARS.intersection(val): | ||
| return "'%s'" % val |
There was a problem hiding this comment.
don't return inline, it makes code harder to read
so, do something like
if if isinstance(val, basestring) and YAML_SPECIAL_CHARS.intersection(val):
val = "'%s'" % val
return val|
@Caylo still a broken test: |
| """ | ||
| if isinstance(val, basestring): | ||
| if "'" in val: | ||
| val = '"%s"' % val |
| val = '"%s"' % val | ||
|
|
||
| elif YAML_SPECIAL_CHARS.intersection(val): | ||
| val = "'%s'" % val |
There was a problem hiding this comment.
@Caylo shouldn't this be the first option you try?
if the string includes both ' and any special YAML charachter, you'll still be in trouble since then you'll take the first option which quotes with "..." but doesn't escape YAML chars?
There was a problem hiding this comment.
@boegel YAML special chars are escaped by quoting the string (as YAML doesn't usually require quoting for regular strings). If the string contains both ' and any other special char, the string will be quoted with ".." anyway, so special chars don't matter anymore
now that im typing this, maybe a better solution is to add ' to YAML_SPECIAL_CHARS and always escape with double quotes
There was a problem hiding this comment.
Wait, but there was a difference between single-quoting and double-quoted strings in YAML, right?
Include a comment and reference w.r.t. that in this function please...
| if isinstance(val, basestring): | ||
| if "'" in val or YAML_SPECIAL_CHARS.intersection(val): | ||
| val = val.replace("'", "''") | ||
| val = "'%s'" % val |
There was a problem hiding this comment.
this looks a bit silly, let's collapse it to
val = "'%s'" % val.replace("'", "''")|
Going in, thanks @Caylo! |
Fixes #1695
Includes
#1826