Skip to content

Commit

Permalink
Fix issue #1882: info not using custom extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
braingram committed Dec 20, 2024
1 parent 9692501 commit 0e655b2
Show file tree
Hide file tree
Showing 4 changed files with 283 additions and 233 deletions.
2 changes: 2 additions & 0 deletions asdf/_asdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1408,6 +1408,7 @@ def schema_info(self, key="description", path=None, preserve_list=True, refresh_
self.tree,
preserve_list=preserve_list,
refresh_extension_manager=refresh_extension_manager,
extension_manager=self.extension_manager,
)

def info(
Expand Down Expand Up @@ -1448,6 +1449,7 @@ def info(
show_values=show_values,
identifier="root",
refresh_extension_manager=refresh_extension_manager,
extension_manager=self.extension_manager,
)
print("\n".join(lines))

Expand Down
2 changes: 2 additions & 0 deletions asdf/_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def render_tree(
filters=None,
identifier="root",
refresh_extension_manager=False,
extension_manager=None,
):
"""
Render a tree as text with indents showing depth.
Expand All @@ -49,6 +50,7 @@ def render_tree(
identifier=identifier,
filters=[] if filters is None else filters,
refresh_extension_manager=refresh_extension_manager,
extension_manager=extension_manager,
)
if info is None:
return []
Expand Down
28 changes: 22 additions & 6 deletions asdf/_node_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def _filter_tree(info, filters):
return len(info.children) > 0 or all(f(info.node, info.identifier) for f in filters)


def create_tree(key, node, identifier="root", filters=None, refresh_extension_manager=False):
def create_tree(key, node, identifier="root", filters=None, refresh_extension_manager=False, extension_manager=None):
"""
Create a `NodeSchemaInfo` tree which can be filtered from a base node.
Expand All @@ -46,6 +46,7 @@ def create_tree(key, node, identifier="root", filters=None, refresh_extension_ma
identifier,
node,
refresh_extension_manager=refresh_extension_manager,
extension_manager=extension_manager,
)

if len(filters) > 0 and not _filter_tree(schema_info, filters):
Expand All @@ -62,6 +63,7 @@ def collect_schema_info(
filters=None,
preserve_list=True,
refresh_extension_manager=False,
extension_manager=None,
):
"""
Collect from the underlying schemas any of the info stored under key, relative to the path
Expand Down Expand Up @@ -91,6 +93,7 @@ def collect_schema_info(
identifier=identifier,
filters=[] if filters is None else filters,
refresh_extension_manager=refresh_extension_manager,
extension_manager=extension_manager,
)

info = schema_info.collect_info(preserve_list=preserve_list)
Expand Down Expand Up @@ -181,7 +184,7 @@ class NodeSchemaInfo:
The portion of the underlying schema corresponding to the node.
"""

def __init__(self, key, parent, identifier, node, depth, recursive=False, visible=True):
def __init__(self, key, parent, identifier, node, depth, recursive=False, visible=True, extension_manager=None):
self.key = key
self.parent = parent
self.identifier = identifier
Expand All @@ -191,6 +194,7 @@ def __init__(self, key, parent, identifier, node, depth, recursive=False, visibl
self.visible = visible
self.children = []
self.schema = None
self.extension_manager = extension_manager or _get_extension_manager()

@classmethod
def traversable(cls, node):
Expand Down Expand Up @@ -246,13 +250,15 @@ def set_schema_from_node(self, node, extension_manager):
self.schema = schema

@classmethod
def from_root_node(cls, key, root_identifier, root_node, schema=None, refresh_extension_manager=False):
def from_root_node(
cls, key, root_identifier, root_node, schema=None, refresh_extension_manager=False, extension_manager=None
):
"""
Build a NodeSchemaInfo tree from the given ASDF root node.
Intentionally processes the tree in breadth-first order so that recursively
referenced nodes are displayed at their shallowest reference point.
"""
extension_manager = _get_extension_manager(refresh_extension_manager)
extension_manager = extension_manager or _get_extension_manager(refresh_extension_manager)

current_nodes = [(None, root_identifier, root_node)]
seen = set()
Expand All @@ -263,11 +269,21 @@ def from_root_node(cls, key, root_identifier, root_node, schema=None, refresh_ex

for parent, identifier, node in current_nodes:
if (isinstance(node, (dict, tuple)) or cls.traversable(node)) and id(node) in seen:
info = NodeSchemaInfo(key, parent, identifier, node, current_depth, recursive=True)
info = NodeSchemaInfo(
key,
parent,
identifier,
node,
current_depth,
recursive=True,
extension_manager=extension_manager,
)
parent.children.append(info)

else:
info = NodeSchemaInfo(key, parent, identifier, node, current_depth)
info = NodeSchemaInfo(
key, parent, identifier, node, current_depth, extension_manager=extension_manager
)

if root_info is None:
root_info = info
Expand Down
Loading

0 comments on commit 0e655b2

Please sign in to comment.