Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register empty 1.0.0 extension to avoid warning when opening old files #475

Merged
merged 3 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ other
- Register all available asdf extension manifests from ``asdf-wcs-schemas``
except 1.0.0 (which contains duplicate tag versions). [#469]

- Register empty extension for 1.0.0 to avoid warning about a missing
extension when opening old files. [#475]


0.18.3 (2022-12-23)
-------------------
Expand Down
16 changes: 15 additions & 1 deletion gwcs/extension.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
import importlib.resources

from asdf.extension import ManifestExtension
from asdf.extension import Extension, ManifestExtension
from .converters.wcs import (
CelestialFrameConverter, CompositeFrameConverter, FrameConverter,
Frame2DConverter, SpectralFrameConverter, StepConverter,
Expand Down Expand Up @@ -58,6 +58,20 @@
if len(WCS_MANIFEST_URIS) == 1 or '1.0.0' not in uri
]

# if we don't register something for the 1.0.0 extension/manifest
# opening old files will issue AsdfWarning messages stating that
# the file was produced with an extension that is not installed
# As the 1.0.1 and 1.1.0 extensions support all the required tags
# it's not a helpful warning so here we register an 'empty'
# extension for 1.0.0 which doesn't support any tags or types
# but will be installed into asdf preventing the warning
if len(TRANSFORM_EXTENSIONS) > 1:
class _EmptyExtension(Extension):
extension_uri = 'asdf://asdf-format.org/astronomy/gwcs/extensions/gwcs-1.0.0'
legacy_class_names=["gwcs.extension.GWCSExtension"]

TRANSFORM_EXTENSIONS.append(_EmptyExtension())


def get_extensions():
"""
Expand Down
58 changes: 58 additions & 0 deletions gwcs/tests/test_extension.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import io
import warnings

import asdf
import asdf_wcs_schemas
import gwcs.extension

import pytest


@pytest.mark.skipif(asdf_wcs_schemas.__version__ < "0.2.0", reason="version 0.2 provides the new manifests")
def test_empty_extension():
"""
Test that an empty extension was installed for gwcs 1.0.0
and that extensions are installed for gwcs 1.0.1 and 1.1.0
"""
extensions = gwcs.extension.get_extensions()
assert len(extensions) > 1

extensions_by_uri = {ext.extension_uri: ext for ext in extensions}

# check for duplicate uris
assert len(extensions_by_uri) == len(extensions)

# check that all 3 versions are installed
for version in ('1.0.0', '1.0.1', '1.1.0'):
assert f"asdf://asdf-format.org/astronomy/gwcs/extensions/gwcs-{version}" in extensions_by_uri

# the 1.0.0 extension should support no tags or types
legacy = extensions_by_uri["asdf://asdf-format.org/astronomy/gwcs/extensions/gwcs-1.0.0"]
assert len(legacy.tags) == 0
assert len(legacy.converters) == 0


def test_open_legacy_without_warning():
"""
Opening a file produced with extension 1.0.0 should not produce any
warnings because of the empty extension registered for 1.0.0
"""
asdf_bytes = b"""#ASDF 1.0.0
#ASDF_STANDARD 1.5.0
%YAML 1.1
%TAG ! tag:stsci.edu:asdf/
--- !core/asdf-1.1.0
asdf_library: !core/software-1.0.0 {author: The ASDF Developers, homepage: 'http://github.com/asdf-format/asdf',
name: asdf, version: 2.9.2}
history:
extensions:
- !core/extension_metadata-1.0.0
extension_class: asdf.extension._manifest.ManifestExtension
extension_uri: asdf://asdf-format.org/astronomy/gwcs/extensions/gwcs-1.0.0
software: !core/software-1.0.0 {name: gwcs, version: 0.18.0}
foo: 1
..."""
with warnings.catch_warnings():
warnings.simplefilter("error")
with asdf.open(io.BytesIO(asdf_bytes)) as af:
assert af['foo'] == 1
Loading