From efc983a62c84f791c1afa99f902ba99cc26e123e Mon Sep 17 00:00:00 2001 From: Ryan Ly Date: Thu, 26 Oct 2023 12:42:16 -0700 Subject: [PATCH] Fix usage of latest ruamel.yaml (#84) * Fix usage of latest ruamel.yaml * fix unused import * Update doc_builds.yml * Update doc_builds.yml --- .github/workflows/doc_builds.yml | 10 ++++++++++ hdmf_docutils/doctools/rst.py | 17 +++++++---------- setup.py | 3 ++- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/.github/workflows/doc_builds.yml b/.github/workflows/doc_builds.yml index dac94c9..c817cc9 100644 --- a/.github/workflows/doc_builds.yml +++ b/.github/workflows/doc_builds.yml @@ -22,6 +22,11 @@ jobs: cd hdmf-common-schema python -m pip install -r requirements-doc.txt + - name: Install the current hdmf-docutils + run: | + pip uninstall hdmf-docutils --yes + pip install . + - name: Build HDMF-Common-Schema Docs run: | cd hdmf-common-schema @@ -35,6 +40,11 @@ jobs: cd nwb-schema python -m pip install -r requirements-doc.txt + - name: Install the current hdmf-docutils + run: | + pip uninstall hdmf-docutils --yes + pip install . + - name: Build NWB-Schema Docs run: | cd nwb-schema diff --git a/hdmf_docutils/doctools/rst.py b/hdmf_docutils/doctools/rst.py index ac41232..952f1cd 100644 --- a/hdmf_docutils/doctools/rst.py +++ b/hdmf_docutils/doctools/rst.py @@ -288,17 +288,14 @@ def spec_to_yaml(spec): :return: YAML string for the current specification """ import json - import sys - - try: - from ruamel import yaml - except ImportError: - import yaml + from ruamel.yaml import YAML + from ruamel.yaml.compat import StringIO clean_spec = json.loads(json.dumps(spec, sort_keys=True, indent=4, separators=(',', ': '))) - if sys.version_info[0] == 3: - return yaml.dump(clean_spec, default_flow_style=False) - else: - return yaml.safe_dump(clean_spec, default_flow_style=False) + yaml = YAML(pure=True) + yaml.default_flow_style = False + stream = StringIO() + yaml.dump(clean_spec, stream) + return stream.getvalue() def add_spec(self, spec): """ diff --git a/setup.py b/setup.py index 046caa1..805c2af 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,8 @@ 'pillow', 'sphinx', 'sphinx-gallery', - 'sphinx_rtd_theme' + 'sphinx_rtd_theme', + 'ruamel.yaml' ], 'setup_requires': 'pytest-runner', 'packages': find_packages(),