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

move format_tag to testing.helpers #1433

Merged
merged 2 commits into from
Feb 22, 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
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ The ASDF Standard is at v1.6.0
- Add AsdfDeprecationWarning to asdf.types [#1401]
- deprecate default_extensions, get_default_resolver and
get_cached_asdf_extension_list in asdf.extension [#1409]
- move asdf.types.format_tag to asdf.testing.helpers.format_tag [#1433]

2.14.3 (2022-12-15)
-------------------
Expand Down
28 changes: 13 additions & 15 deletions asdf/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,28 @@
import warnings
from copy import copy

import asdf.testing.helpers

from . import tagged, util
from .exceptions import AsdfDeprecationWarning
from .versioning import AsdfSpec, AsdfVersion

__all__ = ["format_tag", "CustomType", "AsdfType", "ExtensionType"]
__all__ = ["format_tag", "CustomType", "AsdfType", "ExtensionType"] # noqa: F822


# regex used to parse module name from optional version string
MODULE_RE = re.compile(r"([a-zA-Z]+)(-(\d+\.\d+\.\d+))?")


def format_tag(organization, standard, version, tag_name):
"""
Format a YAML tag.
"""
tag = f"tag:{organization}:{standard}/{tag_name}"

if version is None:
return tag

if isinstance(version, AsdfSpec):
version = str(version.spec)

return f"{tag}-{version}"
def __getattr__(name):
if name == "format_tag":
warnings.warn(
"asdf.types.format_tag is deprecated. Please use asdf.testing.helpers.format_tag",
AsdfDeprecationWarning,
)
return asdf.testing.helpers.format_tag
msg = f"module {__name__!r} has no attribute {name!r}"
raise AttributeError(msg)


_all_asdftypes = set()
Expand Down Expand Up @@ -229,7 +227,7 @@ def make_yaml_tag(cls, name, versioned=True):
-------
`str` representing the YAML tag
"""
return format_tag(cls.organization, cls.standard, cls.version if versioned else None, name)
return asdf.testing.helpers.format_tag(cls.organization, cls.standard, cls.version if versioned else None, name)

@classmethod
def tag_base(cls):
Expand Down
16 changes: 16 additions & 0 deletions asdf/testing/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@
from io import BytesIO

import asdf
from asdf.versioning import AsdfSpec


def format_tag(organization, standard, version, tag_name):
"""
Format a YAML tag.
"""
tag = f"tag:{organization}:{standard}/{tag_name}"

if version is None:
return tag

if isinstance(version, AsdfSpec):
version = str(version.spec)

return f"{tag}-{version}"


def roundtrip_object(obj, version=None):
Expand Down
8 changes: 8 additions & 0 deletions asdf/tests/test_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import pytest

import asdf
import asdf._types
import asdf.extension
import asdf.testing.helpers
from asdf._types import CustomType
from asdf.exceptions import AsdfDeprecationWarning
from asdf.tests.helpers import assert_extension_correctness
Expand Down Expand Up @@ -84,3 +86,9 @@ def test_default_resolver():
def test_get_cached_asdf_extension_list_deprecation():
with pytest.warns(AsdfDeprecationWarning, match="get_cached_asdf_extension_list is deprecated"):
asdf.extension.get_cached_asdf_extension_list([])


def test_asdf_type_format_tag():
with pytest.warns(AsdfDeprecationWarning, match="asdf.types.format_tag is deprecated"):
asdf._types.format_tag
asdf.testing.helpers.format_tag
3 changes: 2 additions & 1 deletion asdf/tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from numpy.testing import assert_array_equal

import asdf
import asdf.testing.helpers
from asdf import _resolver as resolver
from asdf import _types as types
from asdf import config_context, constants, extension, get_config, schema, tagged, util, yamlutil
Expand Down Expand Up @@ -640,7 +641,7 @@ def test_schema_resolved_via_entry_points():
"""Test that entry points mappings to core schema works"""
with pytest.warns(AsdfDeprecationWarning, match="get_default_resolver is deprecated"):
r = extension.get_default_resolver()
tag = types.format_tag("stsci.edu", "asdf", "1.0.0", "fits/fits")
tag = asdf.testing.helpers.format_tag("stsci.edu", "asdf", "1.0.0", "fits/fits")
with pytest.warns(AsdfDeprecationWarning, match="default_extensions is deprecated"):
url = extension.default_extensions.extension_list.tag_mapping(tag)

Expand Down