Skip to content

Commit be3d0db

Browse files
committed
Using safe dump does not resolve issue 46, unless we also use safe load / get rid of all comments altogether. Saving the data again seems to help!? :-)
1 parent 484eedb commit be3d0db

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

bidscoin/bids.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import pydicom
2222
from importlib import util
2323
from ruamel.yaml import YAML
24-
yaml = YAML(typ='safe', pure=True) # 'safe' load and dump
24+
yaml = YAML()
2525

2626
logger = logging.getLogger('bidscoin')
2727

@@ -505,7 +505,13 @@ def save_bidsmap(filename: str, bidsmap: dict):
505505
try:
506506
load_bidsmap(filename, '', False)
507507
except:
508-
logger.error(f'The saved output bidsmap does not seem to be valid YAML, please check {filename}, e.g. by way of an online yaml validator, such as https://yamlchecker.com/')
508+
# Just trying again seems to help? :-)
509+
with open(filename, 'w') as stream:
510+
yaml.dump(bidsmap, stream)
511+
try:
512+
load_bidsmap(filename, '', False)
513+
except:
514+
logger.error(f'The saved output bidsmap does not seem to be valid YAML, please check {filename}, e.g. by way of an online yaml validator, such as https://yamlchecker.com/')
509515

510516

511517
def parse_x_protocol(pattern: str, dicomfile: str) -> str:

0 commit comments

Comments
 (0)