Skip to content

Commit

Permalink
reducing some redundancy
Browse files Browse the repository at this point in the history
  • Loading branch information
braingram committed Dec 18, 2024
1 parent 4bfb1fb commit 9692501
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
11 changes: 5 additions & 6 deletions asdf/_convenience.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from contextlib import contextmanager

from ._asdf import AsdfFile, open_asdf
from ._display import DEFAULT_MAX_COLS, DEFAULT_MAX_ROWS, DEFAULT_SHOW_VALUES, render_tree
from ._display import DEFAULT_MAX_COLS, DEFAULT_MAX_ROWS, DEFAULT_SHOW_VALUES

__all__ = ["info"]

Expand Down Expand Up @@ -41,18 +41,17 @@ def info(node_or_path, max_rows=DEFAULT_MAX_ROWS, max_cols=DEFAULT_MAX_COLS, sho
the rendered tree.
"""
with _manage_node(node_or_path) as node:
lines = render_tree(node, max_rows=max_rows, max_cols=max_cols, show_values=show_values, identifier="root")
print("\n".join(lines))
node.info(max_rows=max_rows, max_cols=max_cols, show_values=show_values)


@contextmanager
def _manage_node(node_or_path):
if isinstance(node_or_path, (str, pathlib.Path)):
with open_asdf(node_or_path) as af:
yield af.tree
yield af

elif isinstance(node_or_path, AsdfFile):
yield node_or_path.tree
yield node_or_path

else:
yield node_or_path
yield AsdfFile(node_or_path)
5 changes: 3 additions & 2 deletions asdf/commands/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Commands for displaying summaries of ASDF trees
"""

from asdf import _convenience as convenience
import asdf

from .main import Command

Expand Down Expand Up @@ -36,4 +36,5 @@ def run(cls, args):


def info(filename, max_rows, max_cols, show_values):
convenience.info(filename, max_rows=max_rows, max_cols=max_cols, show_values=show_values)
with asdf.open(filename) as af:
af.info(max_rows, max_cols, show_values)

0 comments on commit 9692501

Please sign in to comment.