Skip to content

Commit

Permalink
Add missing docstrings and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Ed Slavich committed Aug 10, 2020
1 parent 547211b commit 15336c1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
37 changes: 37 additions & 0 deletions asdf/asdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,19 @@ def __exit__(self, type, value, traceback):
self.close()

def _check_extensions(self, tree, strict=False):
"""
Compare the user's installed extensions to metadata in the tree
and warn when a) an extension is missing or b) an extension is
present but the file was written with a later version of the
extension's package.
Parameters
----------
tree : AsdfObject
Fully converted tree of custom types.
strict : bool, optional
Set to `True` to convert warnings to exceptions.
"""
if 'history' not in tree or not isinstance(tree['history'], dict) or \
'extensions' not in tree['history']:
return
Expand Down Expand Up @@ -305,6 +318,21 @@ def _check_extensions(self, tree, strict=False):
warnings.warn(msg, AsdfWarning)

def _process_extensions(self, requested_extensions):
"""
Validate a list of extensions requested by the user and
add missing extensions registered with the current `AsdfConfig`.
Parameters
----------
requested_extensions : object
May be any of the following: `asdf.extension.AsdfExtension`, `str`
extension URI, `asdf.extension.AsdfExtensionList` or a `list`
of URIs and/or extensions.
Returns
-------
list of asdf.extension.AsdfExtension
"""
if requested_extensions is None:
requested_extensions = []
elif isinstance(requested_extensions, (AsdfExtension, ExtensionProxy, str)):
Expand Down Expand Up @@ -336,6 +364,15 @@ def _get_extension(e):
return extensions

def _update_extension_history(self, serialization_context):
"""
Update the extension metadata on this file's tree to reflect
extensions used during serialization.
Parameters
----------
serialization_context : asdf.asdf.SerializationContext
The context that was used to serialize the tree.
"""
if serialization_context.version < versioning.NEW_HISTORY_FORMAT_MIN_VERSION:
return

Expand Down
4 changes: 4 additions & 0 deletions asdf/yamlutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,10 @@ def dump_tree(tree, fd, ctx, tree_finalizer=None, _serialization_context=None):
extension metadata on the tagged tree before it is fully
serialized to YAML.
"""
# The _serialization_context parameter allows AsdfFile to track
# what extensions were used when converting the tree's custom
# types. In 3.0, it will be passed as the `ctx` instead of the
# AsdfFile itself.
tags = None
tree_type = ctx.type_index.from_custom_type(type(tree))
if tree_type is not None:
Expand Down

0 comments on commit 15336c1

Please sign in to comment.