Skip to content

Commit

Permalink
Merge pull request #629 from drdavella/extension-warnings
Browse files Browse the repository at this point in the history
Provide source information for deprecation warnings from extensions
  • Loading branch information
drdavella authored Dec 17, 2018
2 parents 8733f0e + 4438472 commit 1398fdf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
2.3.1 (unreleased)
------------------

- Provide source information for ``AsdfDeprecationWarning`` that come from
extensions from external packages. [#629]

- Ensure that top-level accesses to the tree outside a closed context handler
result in an ``OSError``. [#628]

Expand Down
8 changes: 7 additions & 1 deletion asdf/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ def __init__(self):

def _load_installed_extensions(self, group='asdf_extensions'):
for entry_point in iter_entry_points(group=group):
ext = entry_point.load()
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always', category=AsdfDeprecationWarning)
ext = entry_point.load()
if not issubclass(ext, AsdfExtension):
warnings.warn("Found entry point {}, from {} but it is not a "
"subclass of AsdfExtension, as expected. It is "
Expand All @@ -204,6 +206,10 @@ def _load_installed_extensions(self, group='asdf_extensions'):
self._package_metadata[name] = (dist.project_name, dist.version)
self._extensions.append(ext())

for warning in w:
warnings.warn('{} (from {})'.format(warning.message, name),
AsdfDeprecationWarning)

@property
def extensions(self):
# This helps avoid a circular dependency with external packages
Expand Down

0 comments on commit 1398fdf

Please sign in to comment.