Skip to content

Commit

Permalink
Merge pull request #87 from braingram/get_yaml_content
Browse files Browse the repository at this point in the history
remove use of _get_yaml_content
  • Loading branch information
braingram authored May 9, 2024
2 parents 6810cd0 + 467fe93 commit 3530e22
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(
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)

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

0 comments on commit 3530e22

Please sign in to comment.