From be46fe6f8a5398b80f8aa0b123cb2de2ebdf3e85 Mon Sep 17 00:00:00 2001 From: Daniel D'Avella Date: Mon, 17 Dec 2018 16:45:39 -0500 Subject: [PATCH] Provide source information for deprecation warnings from extensions --- CHANGES.rst | 5 +++++ asdf/extension.py | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index e74d25371..e9b6dd618 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -3,6 +3,11 @@ - Define the ``in`` operator for top-level ``AsdfFile`` objects. [#623] +2.3.1 (unreleased) +------------------ + +- Provide source information for ``AsdfDeprecationWarning`` that come from + extensions from external packages. [#629] 2.3.0 (2018-11-28) ------------------ diff --git a/asdf/extension.py b/asdf/extension.py index 4325fc538..17d491051 100644 --- a/asdf/extension.py +++ b/asdf/extension.py @@ -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 " @@ -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