Repository: asdf-format/asdf

Issue:
Add deprecations for 'legacy' extension system
The 'legacy' extensions should raise deprecation warnings in 2.15 as they will be removed in 3.0. Warnings should be issued for:

- [x] [CustomType](https://github.com/asdf-format/asdf/blob/cbc066dad91f236236dc04c6bd14a08ae84f01cb/asdf/types.py#L400): https://github.com/asdf-format/asdf/pull/1359
- [x] Resolver (see [comment below](https://github.com/asdf-format/asdf/issues/1333#issuecomment-1405703407)): https://github.com/asdf-format/asdf/pull/1362
- [x] [asdf.types](https://github.com/asdf-format/asdf/blob/cbc066dad91f236236dc04c6bd14a08ae84f01cb/asdf/types.py#L1) (this includes [format_tag](https://github.com/asdf-format/asdf/blob/cbc066dad91f236236dc04c6bd14a08ae84f01cb/asdf/types.py#L15)) https://github.com/asdf-format/asdf/pull/1401
- [x] asdf.tests.helpers.assert_extension_correctness: https://github.com/asdf-format/asdf/pull/1388
- [x] [asdf.extension.get_default_resolver](https://github.com/asdf-format/asdf/blob/master/asdf/extension/_legacy.py#L254): https://github.com/asdf-format/asdf/pull/1409
- [x] [asdf.extension.get_cached_asdf_extension_list](https://github.com/asdf-format/asdf/blob/master/asdf/extension/_legacy.py#L167): https://github.com/asdf-format/asdf/pull/1409
- [x] [asdf.extension.default_extensions](https://github.com/asdf-format/asdf/blob/43a9f381ef939931ced73ebf68dc07de68de6ce0/asdf/extension/_legacy.py#L251): https://github.com/asdf-format/asdf/pull/1409
- [x] [asdf.type_index](https://github.com/asdf-format/asdf/blob/master/asdf/type_index.py#L184): https://github.com/asdf-format/asdf/pull/1403
- [x] [asdf.AsdfFile.run_hook and similar](https://github.com/asdf-format/asdf/blob/master/asdf/asdf.py#L1412): https://github.com/asdf-format/asdf/pull/1417
- [x] [asdf.types.AsdfType](https://github.com/asdf-format/asdf/blob/a143b77856e93bd1df6aeff7672c0467ae1c5cde/asdf/types.py#L394): https://github.com/asdf-format/asdf/pull/1401
- [x] [asdf.types.ExtensionType](https://github.com/asdf-format/asdf/blob/a143b77856e93bd1df6aeff7672c0467ae1c5cde/asdf/types.py#L173): https://github.com/asdf-format/asdf/pull/1401
- [x] [asdf.extension.AsdfExtension](https://github.com/asdf-format/asdf/blob/43a9f381ef939931ced73ebf68dc07de68de6ce0/asdf/extension/_legacy.py#L13): https://github.com/asdf-format/asdf/pull/1429
- [x] [asdf.extension.AsdfExtensionList](https://github.com/asdf-format/asdf/blob/43a9f381ef939931ced73ebf68dc07de68de6ce0/asdf/extension/_legacy.py#L104): https://github.com/asdf-format/asdf/pull/1429
- [x] [asdf.extension.BuiltInExtension](https://github.com/asdf-format/asdf/blob/43a9f381ef939931ced73ebf68dc07de68de6ce0/asdf/extension/_legacy.py#L203): https://github.com/asdf-format/asdf/pull/1429
- [ ] [asdf_extensions entry point](https://github.com/asdf-format/asdf/blob/master/asdf/entry_points.py#L16): https://github.com/asdf-format/asdf/pull/1361

Discussion:
braingram: This is based off changes in #1429 and should not be merged before that PR.
braingram: @WilliamJamieson Thanks for catching those. They were all stale changes that are no longer required due to the work done to revive this PR.

Patch:
diff --git a/CHANGES.rst b/CHANGES.rst
index 16e6fcfc..10bc7e07 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -32,6 +32,7 @@ The ASDF Standard is at v1.6.0
   get_cached_asdf_extension_list in asdf.extension [#1409]
 - move asdf.types.format_tag to asdf.testing.helpers.format_tag [#1433]
 - Deprecate AsdfExtenion, AsdfExtensionList, BuiltinExtension [#1429]
+- Add AsdfDeprecationWarning to asdf_extensions entry point [#1361]
 
 2.14.3 (2022-12-15)
 -------------------
diff --git a/asdf/entry_points.py b/asdf/entry_points.py
index 9cd73752..1d8dfadc 100644
--- a/asdf/entry_points.py
+++ b/asdf/entry_points.py
@@ -23,7 +23,6 @@ def get_resource_mappings():
 def get_extensions():
     extensions = _list_entry_points(EXTENSIONS_GROUP, ExtensionProxy)
     legacy_extensions = _list_entry_points(LEGACY_EXTENSIONS_GROUP, ExtensionProxy)
-
     return extensions + legacy_extensions
 
 
@@ -55,30 +54,39 @@ def _list_entry_points(group, proxy_class):
         # Catch errors loading entry points and warn instead of raising
         try:
             with warnings.catch_warnings():
-                if entry_point.name == "astropy" and entry_point.group == LEGACY_EXTENSIONS_GROUP:
-                    # Filter out the legacy `CustomType` deprecation warnings from the deprecated astropy.io.misc.asdf
-                    # Testing will turn these into errors
-                    # Most of the astropy.io.misc.asdf deprecation warnings fall under this category
-                    warnings.filterwarnings(
-                        "ignore",
-                        category=AsdfDeprecationWarning,
-                        message=r".*from astropy.io.misc.asdf.* subclasses the deprecated CustomType .*",
-                    )
-                    warnings.filterwarnings(
-                        "ignore",
-                        category=AsdfDeprecationWarning,
-                        message="asdf.types is deprecated",
-                    )
-                    warnings.filterwarnings(
-                        "ignore",
-                        category=AsdfDeprecationWarning,
-                        message="AsdfExtension is deprecated",
-                    )
-                    warnings.filterwarnings(
-                        "ignore",
-                        category=AsdfDeprecationWarning,
-                        message="BuiltinExtension is deprecated",
-                    )
+                if entry_point.group == LEGACY_EXTENSIONS_GROUP:
+                    if entry_point.name in ("astropy", "astropy-asdf"):
+                        # Filter out the legacy `CustomType` deprecation warnings from the
+                        # deprecated astropy.io.misc.asdf
+                        # Testing will turn these into errors
+                        # Most of the astropy.io.misc.asdf deprecation warnings fall under this category
+                        warnings.filterwarnings(
+                            "ignore",
+                            category=AsdfDeprecationWarning,
+                            message=r".*from astropy.io.misc.asdf.* subclasses the deprecated CustomType .*",
+                        )
+                        warnings.filterwarnings(
+                            "ignore",
+                            category=AsdfDeprecationWarning,
+                            message="asdf.types is deprecated",
+                        )
+                        warnings.filterwarnings(
+                            "ignore",
+                            category=AsdfDeprecationWarning,
+                            message="AsdfExtension is deprecated",
+                        )
+                        warnings.filterwarnings(
+                            "ignore",
+                            category=AsdfDeprecationWarning,
+                            message="BuiltinExtension is deprecated",
+                        )
+                    elif entry_point.name != "builtin":
+                        warnings.warn(
+                            f"{package_name} uses the deprecated entry point {LEGACY_EXTENSIONS_GROUP}. "
+                            f"Please use the new extension api and entry point {EXTENSIONS_GROUP}: "
+                            "https://asdf.readthedocs.io/en/stable/asdf/extending/extensions.html",
+                            AsdfDeprecationWarning,
+                        )
 
                 elements = entry_point.load()()
 
diff --git a/tox.ini b/tox.ini
index 1be381cf..61318e19 100644
--- a/tox.ini
+++ b/tox.ini
@@ -157,7 +157,8 @@ commands_pre =
     pip install -r {env_tmp_dir}/requirements.txt
     pip freeze
 commands =
-    pytest specutils
+    pytest specutils \
+        -W "ignore::asdf.exceptions.AsdfDeprecationWarning:asdf.entry_points"
 
 [testenv:gwcs]
 change_dir = {env_tmp_dir}


Test patch:
diff --git a/asdf/tests/helpers.py b/asdf/tests/helpers.py
index 50a29907..3d685f12 100644
--- a/asdf/tests/helpers.py
+++ b/asdf/tests/helpers.py
@@ -394,7 +394,6 @@ def assert_no_warnings(warning_class=None):
     if warning_class is None:
         with warnings.catch_warnings():
             warnings.simplefilter("error")
-
             yield
     else:
         with pytest.warns(Warning) as recorded_warnings:
diff --git a/asdf/tests/test_asdf.py b/asdf/tests/test_asdf.py
index f002b9ae..517cfa3e 100644
--- a/asdf/tests/test_asdf.py
+++ b/asdf/tests/test_asdf.py
@@ -1,5 +1,4 @@
 import os
-import warnings
 
 import fsspec
 import pytest
@@ -19,9 +18,7 @@ def test_no_warnings_get_extensions():
     Smoke test for changes to the `importlib.metadata` entry points API.
     """
 
-    with warnings.catch_warnings():
-        warnings.simplefilter("error")
-
+    with assert_no_warnings():
         get_extensions()
 
 
diff --git a/asdf/tests/test_deprecated.py b/asdf/tests/test_deprecated.py
index 05a0035a..052fc05d 100644
--- a/asdf/tests/test_deprecated.py
+++ b/asdf/tests/test_deprecated.py
@@ -6,11 +6,14 @@ import asdf
 import asdf._types
 import asdf.extension
 import asdf.testing.helpers
+from asdf import entry_points
 from asdf._types import CustomType
 from asdf.exceptions import AsdfDeprecationWarning
 from asdf.tests.helpers import assert_extension_correctness
 from asdf.tests.objects import CustomExtension
 
+from .test_entry_points import _monkeypatch_entry_points, mock_entry_points  # noqa: F401
+
 
 def test_custom_type_warning():
     with pytest.warns(AsdfDeprecationWarning, match=r"^.* subclasses the deprecated CustomType .*$"):
@@ -103,3 +106,9 @@ def test_extension_class_deprecation(name):
 def test_top_level_asdf_extension_deprecation():
     with pytest.warns(AsdfDeprecationWarning, match="AsdfExtension is deprecated"):
         asdf.AsdfExtension
+
+
+def test_deprecated_entry_point(mock_entry_points):  # noqa: F811
+    mock_entry_points.append(("asdf_extensions", "legacy", "asdf.tests.test_entry_points:LegacyExtension"))
+    with pytest.warns(AsdfDeprecationWarning, match=".* uses the deprecated entry point asdf_extensions"):
+        entry_points.get_extensions()
diff --git a/asdf/tests/test_entry_points.py b/asdf/tests/test_entry_points.py
index bd397f2a..8c8cfb76 100644
--- a/asdf/tests/test_entry_points.py
+++ b/asdf/tests/test_entry_points.py
@@ -8,7 +8,7 @@ import pytest
 
 from asdf import entry_points
 from asdf._version import version as asdf_package_version
-from asdf.exceptions import AsdfWarning
+from asdf.exceptions import AsdfDeprecationWarning, AsdfWarning
 from asdf.extension import ExtensionProxy
 from asdf.resource import ResourceMappingProxy
 
@@ -23,7 +23,7 @@ def _monkeypatch_entry_points(monkeypatch, mock_entry_points):
     def _entry_points(*, group):
         for candidate_group, name, func_name in mock_entry_points:
             if candidate_group == group:
-                point = metadata.EntryPoint(name=name, group="asdf.tests.test_entry_points", value=func_name)
+                point = metadata.EntryPoint(name=name, group=group, value=func_name)
                 vars(point).update(dist=metadata.distribution("asdf"))
 
                 yield point
@@ -158,7 +158,8 @@ def test_get_extensions(mock_entry_points):
 
     mock_entry_points.clear()
     mock_entry_points.append(("asdf_extensions", "legacy", "asdf.tests.test_entry_points:LegacyExtension"))
-    extensions = entry_points.get_extensions()
+    with pytest.warns(AsdfDeprecationWarning, match=".* uses the deprecated entry point asdf_extensions"):
+        extensions = entry_points.get_extensions()
     assert len(extensions) == 1
     for e in extensions:
         assert isinstance(e, ExtensionProxy)
diff --git a/asdf/tests/test_types.py b/asdf/tests/test_types.py
index ee0b14bd..150fad36 100644
--- a/asdf/tests/test_types.py
+++ b/asdf/tests/test_types.py
@@ -402,6 +402,8 @@ undefined_data:
     assert missing[3][1] == 3.14j
 
     # There are two undefined tags, so we expect two warnings
+    # filter out only AsdfConversionWarning
+    warning = [w for w in warning if w.category == AsdfConversionWarning]
     assert len(warning) == 2
     for i, tag in enumerate(["also_undefined-1.3.0", "undefined_tag-1.0.0"]):
         assert (