Skip to content

Commit e6f5975

Browse files
authored
Merge pull request #92 from ehennestad/main
Update doctools to sort specification keys of embedded yaml in HDMF-preferred order
2 parents 06cedbb + a47b637 commit e6f5975

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

hdmf_docutils/doctools/rst.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,18 @@ def spec_to_yaml(spec):
290290
import json
291291
from ruamel.yaml import YAML
292292
from ruamel.yaml.compat import StringIO
293-
clean_spec = json.loads(json.dumps(spec, sort_keys=True, indent=4, separators=(',', ': ')))
293+
from hdmf.spec.write import YAMLSpecWriter
294+
295+
# Convert to plain dict first
296+
clean_spec = json.loads(json.dumps(spec, indent=4, separators=(',', ': ')))
297+
# Sort keys using YAMLSpecWriter's sort_keys method
298+
hdmf_yaml_writer = YAMLSpecWriter()
299+
sorted_spec = hdmf_yaml_writer.sort_keys(clean_spec)
300+
294301
yaml = YAML(pure=True)
295302
yaml.default_flow_style = False
296303
stream = StringIO()
297-
yaml.dump(clean_spec, stream)
304+
yaml.dump(sorted_spec, stream)
298305
return stream.getvalue()
299306

300307
def add_spec(self, spec):

0 commit comments

Comments
 (0)