Skip to content

Commit

Permalink
remove use of _get_yaml_content
Browse files Browse the repository at this point in the history
  • Loading branch information
braingram committed Dec 9, 2023
1 parent fd4417e commit b81dc08
Showing 1 changed file with 13 additions and 24 deletions.
37 changes: 13 additions & 24 deletions sphinx_asdf/asdf2rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
import textwrap

import asdf
from asdf import AsdfFile, versioning
from asdf.constants import ASDF_MAGIC, ASDF_STANDARD_COMMENT, BLOCK_FLAG_STREAMED
from asdf.constants import BLOCK_FLAG_STREAMED
from docutils import nodes
from docutils.parsers.rst import Directive
from sphinx.util.nodes import set_source_info

version_string = str(versioning.default_version)
TMPDIR = tempfile.mkdtemp()
GLOBALS = {}
FLAGS = {BLOCK_FLAG_STREAMED: "BLOCK_FLAG_STREAMED"}
Expand Down Expand Up @@ -105,28 +103,19 @@ def run(self):

parts = []
try:
ff = AsdfFile()
with asdf.open(filename, ignore_unrecognized_tag=True, ignore_missing_extensions=True) as af:
if af.version is None:
asdf_standard_version = version_string
else:
asdf_standard_version = af.version

file_version = af._file_format_version

header_comments = (
f"\n{ASDF_MAGIC.strip().decode('utf-8')} {file_version}\n"
f"#{ASDF_STANDARD_COMMENT.strip().decode('utf-8')} {asdf_standard_version}\n"
)

code = AsdfFile._open_impl(ff, filename, _get_yaml_content=True)
code = header_comments + code.strip().decode("utf-8")
code += "\n"
literal = nodes.literal_block(code, code)
literal["language"] = "yaml"
set_source_info(self, literal)
if show_header:
parts.append(literal)
with asdf.generic_io.get_file(filename, "r") as gf:
reader = gf.reader_until(

Check warning on line 108 in sphinx_asdf/asdf2rst.py

View check run for this annotation

Codecov / codecov/patch

sphinx_asdf/asdf2rst.py#L107-L108

Added lines #L107 - L108 were not covered by tests
asdf.constants.YAML_END_MARKER_REGEX,
7,
"End of YAML marker",
include=True,
)
code = reader.read().decode("utf-8") + "\n"
literal = nodes.literal_block(code, code)
literal["language"] = "yaml"
set_source_info(self, literal)
parts.append(literal)

Check warning on line 118 in sphinx_asdf/asdf2rst.py

View check run for this annotation

Codecov / codecov/patch

sphinx_asdf/asdf2rst.py#L114-L118

Added lines #L114 - L118 were not covered by tests

kwargs = dict()
# Use the ignore_unrecognized_tag parameter as a proxy for both options
Expand Down

0 comments on commit b81dc08

Please sign in to comment.