diff --git a/dandi/dandiset.py b/dandi/dandiset.py index 97a33a563..c6c5a5e1d 100644 --- a/dandi/dandiset.py +++ b/dandi/dandiset.py @@ -4,7 +4,7 @@ from pathlib import Path from .consts import dandiset_metadata_file -from .utils import find_parent_directory_containing +from .utils import find_parent_directory_containing, yaml_dump from . import get_logger @@ -52,7 +52,7 @@ def get_dandiset_record(cls, meta): # It can be edied online and obtained from the dandiarchive. # It also gets updated using dandi organize """ - yaml_rec = yaml.dump(meta) + yaml_rec = yaml_dump(meta) return header + yaml_rec def update_metadata(self, meta): diff --git a/dandi/download.py b/dandi/download.py index 0771a344a..396c09f77 100644 --- a/dandi/download.py +++ b/dandi/download.py @@ -186,7 +186,7 @@ def download( dandiset_path = op.join(output_dir, e["path"]) dandiset_yaml = op.join(dandiset_path, dandiset_metadata_file) lgr.info( - f"Updating f{dandiset_metadata_file} from obtained dandiset metadata" + f"Updating {dandiset_metadata_file} from obtained dandiset metadata" ) if op.lexists(dandiset_yaml): if existing != "overwrite": diff --git a/dandi/utils.py b/dandi/utils.py index a437d3adf..ba2a72781 100644 --- a/dandi/utils.py +++ b/dandi/utils.py @@ -333,6 +333,20 @@ def find_parent_directory_containing(filename, path=None): path = path.parent # go up +def yaml_dump(rec): + """Consistent dump into yaml + + Of primary importance is default_flow_style=False + to assure proper formatting on versions of pyyaml before + 5.1: https://github.com/yaml/pyyaml/pull/256 + """ + import yaml + return yaml.safe_dump( + rec, + default_flow_style=False + ) + + # # Borrowed from DataLad (MIT license) #