Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove use of _get_yaml_content #87

Merged
merged 1 commit into from
May 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

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