Skip to content

Commit

Permalink
Merge pull request #1852 from braingram/rm_4p0_deprecations
Browse files Browse the repository at this point in the history
Remove deprecated code
  • Loading branch information
braingram authored Nov 8, 2024
2 parents d717270 + a7a9b7d commit abeef0e
Show file tree
Hide file tree
Showing 26 changed files with 172 additions and 963 deletions.
122 changes: 8 additions & 114 deletions asdf/_asdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from ._helpers import validate_version
from .config import config_context, get_config
from .exceptions import (
AsdfDeprecationWarning,
AsdfManifestURIMismatchWarning,
AsdfPackageVersionWarning,
AsdfWarning,
Expand All @@ -31,21 +30,6 @@
from .util import NotSet


def __getattr__(name):
if name == "SerializationContext":
warnings.warn(
"importing SerializationContext from asdf.asdf is deprecated. "
"Please import SerializationContext from asdf.extension",
AsdfDeprecationWarning,
)
from .extension._serialization_context import SerializationContext

return SerializationContext

msg = f"module {__name__!r} has no attribute {name!r}"
raise AttributeError(msg)


def _get_asdf_library_info():
"""
Get information about asdf to include in the asdf_library entry
Expand All @@ -72,9 +56,7 @@ def __init__(
uri=None,
extensions=None,
version=None,
ignore_version_mismatch=NotSet,
ignore_unrecognized_tag=False,
ignore_implicit_conversion=NotSet,
memmap=True,
lazy_load=True,
custom_schema=None,
Expand All @@ -100,22 +82,10 @@ def __init__(
The ASDF Standard version. If not provided, defaults to the
configured default version. See `asdf.config.AsdfConfig.default_version`.
ignore_version_mismatch : bool, optional
Deprecated and unused. This setting does nothing since asdf 3.0.0
When `True`, do not raise warnings for mismatched schema versions.
Set to `True` by default.
ignore_unrecognized_tag : bool, optional
When `True`, do not raise warnings for unrecognized tags. Set to
`False` by default.
ignore_implicit_conversion : bool
DEPRECATED
When `True`, do not raise warnings when types in the tree are
implicitly converted into a serializable object. The motivating
case for this is currently ``namedtuple``, which cannot be serialized
as-is.
memmap : bool, optional
When `True`, when reading files, attempt to memmap underlying data
arrays when possible. Defaults to ``True``.
Expand Down Expand Up @@ -155,14 +125,7 @@ def __init__(
else:
self._custom_schema = None

if ignore_version_mismatch is not NotSet:
warnings.warn(
"ignore_version_mismatch is deprecated and has done nothing since asdf 3.0.0",
AsdfDeprecationWarning,
)

self._ignore_unrecognized_tag = ignore_unrecognized_tag
self._ignore_implicit_conversion = ignore_implicit_conversion

# Context of a call to treeutil.walk_and_modify, needed in the AsdfFile
# in case walk_and_modify is re-entered by extension code (via
Expand All @@ -177,12 +140,6 @@ def __init__(
self._closed = False
self._external_asdf_by_uri = {}
self._blocks = BlockManager(uri=uri, lazy_load=lazy_load, memmap=memmap)
# this message is passed into find_references to only warn if
# a reference was found
find_ref_warning_msg = (
"find_references during AsdfFile.__init__ is deprecated. "
"call AsdfFile.find_references after AsdfFile.__init__"
)
if tree is None:
# Bypassing the tree property here, to avoid validating
# an empty tree.
Expand All @@ -196,21 +153,12 @@ def __init__(
self._blocks._uri = tree.uri
# Set directly to self._tree (bypassing property), since
# we can assume the other AsdfFile is already valid.
self._tree = tree.tree
self.find_references(_warning_msg=find_ref_warning_msg)
# Call "walk_and_modify" here to use it's logic for
# creating a "copy" of the other tree. This mimics what was previously
# a call to find_references (which we longer do in AsdfFile.__init__)
self._tree = treeutil.walk_and_modify(tree.tree, lambda o: o)
else:
self._tree = AsdfObject(tree)
try:
self.validate()
except ValidationError:
warnings.warn(
"Validation during AsdfFile.__init__ is deprecated. "
"Please use AsdfFile.validate to validate the tree",
AsdfDeprecationWarning,
)
raise

self.find_references(_warning_msg=find_ref_warning_msg)

self._comments = []

Expand Down Expand Up @@ -252,14 +200,6 @@ def version_string(self):
"""
return str(self._version)

@property
def version_map(self):
warnings.warn(
"AsdfFile.version_map is deprecated. Please use the extension_manager",
AsdfDeprecationWarning,
)
return versioning._get_version_map(self.version_string)

@property
def extensions(self):
"""
Expand Down Expand Up @@ -619,16 +559,7 @@ def tree(self):

@tree.setter
def tree(self, tree):
asdf_object = AsdfObject(tree)
# Only perform custom validation if the tree is not empty
try:
self._validate(asdf_object, custom=bool(tree))
except ValidationError:
warnings.warn(
"Validation on tree assignment is deprecated. Please use AsdfFile.validate", AsdfDeprecationWarning
)
raise
self._tree = asdf_object
self._tree = AsdfObject(tree)

def keys(self):
return self.tree.keys()
Expand Down Expand Up @@ -956,9 +887,6 @@ def _open_asdf(
# to select the correct tag for us.
tree = yamlutil.custom_tree_to_tagged_tree(AsdfObject(), self)

find_ref_warning_msg = "find_references during open is deprecated. call AsdfFile.find_references after open"
tree = reference.find_references(tree, self, _warning_msg=find_ref_warning_msg)

if self.version <= versioning.FILL_DEFAULTS_MAX_VERSION and get_config().legacy_fill_schema_defaults:
schema.fill_defaults(tree, self, reading=True)

Expand Down Expand Up @@ -1325,49 +1253,22 @@ def write_to(
if version is not None:
self.version = previous_version

def find_references(self, _warning_msg=False):
def find_references(self):
"""
Finds all external "JSON References" in the tree and converts
them to ``reference.Reference`` objects.
"""
# Set directly to self._tree, since it doesn't need to be re-validated.
self._tree = reference.find_references(self._tree, self, _warning_msg=_warning_msg)
self._tree = reference.find_references(self._tree, self)

def resolve_references(self, **kwargs):
def resolve_references(self):
"""
Finds all external "JSON References" in the tree, loads the
external content, and places it directly in the tree. Saving
a ASDF file after this operation means it will have no
external references, and will be completely self-contained.
"""
if len(kwargs):
warnings.warn("Passing kwargs to resolve_references is deprecated and does nothing", AsdfDeprecationWarning)
self._tree = reference.resolve_references(self._tree, self)
try:
self.validate()
except ValidationError:
warnings.warn(
"Validation during resolve_references is deprecated. "
"Please use AsdfFile.validate after resolve_references to validate the resolved tree",
AsdfDeprecationWarning,
)
raise

def resolve_and_inline(self):
"""
Resolves all external references and inlines all data. This
produces something that, when saved, is a 100% valid YAML
file.
"""
warnings.warn(
"resolve_and_inline is deprecated. "
"Use AsdfFile.resolve_references and all_array_storage=inline "
"during AsdfFile.write_to",
AsdfDeprecationWarning,
)
self.resolve_references()
for b in self._blocks.blocks:
self.set_array_storage(b.data, "inline")

def fill_defaults(self):
"""
Expand Down Expand Up @@ -1607,7 +1508,6 @@ def open_asdf(
mode=None,
validate_checksums=False,
extensions=None,
ignore_version_mismatch=NotSet,
ignore_unrecognized_tag=False,
_force_raw_types=False,
memmap=True,
Expand Down Expand Up @@ -1643,11 +1543,6 @@ def open_asdf(
Additional extensions to use when reading and writing the file.
May be an `asdf.extension.Extension` or a `list` of extensions.
ignore_version_mismatch : bool, optional
Deprecated and unused. This setting does nothing since asdf 3.0.0
When `True`, do not raise warnings for mismatched schema versions.
Set to `True` by default.
ignore_unrecognized_tag : bool, optional
When `True`, do not raise warnings for unrecognized tags. Set to
`False` by default.
Expand Down Expand Up @@ -1713,7 +1608,6 @@ def open_asdf(
mode = "r"

instance = AsdfFile(
ignore_version_mismatch=ignore_version_mismatch,
ignore_unrecognized_tag=ignore_unrecognized_tag,
memmap=memmap,
lazy_load=lazy_load,
Expand Down
2 changes: 1 addition & 1 deletion asdf/_convenience.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def info(node_or_path, max_rows=DEFAULT_MAX_ROWS, max_cols=DEFAULT_MAX_COLS, sho
Parameters
----------
node_or_path : str, pathlib.Path, asdf.asdf.AsdfFile, or any ASDF tree node
node_or_path : str, pathlib.Path, asdf.AsdfFile, or any ASDF tree node
The tree or sub-tree to render. Strings and Path objects
will first be passed to asdf.open(...).
Expand Down
9 changes: 3 additions & 6 deletions asdf/_tests/_regtests/test_1715.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import pytest

import asdf


Expand All @@ -22,7 +20,6 @@ def test_id_in_tree_breaks_ref(tmp_path):
af["myref"] = {"$ref": "external.asdf#/thing"}
af.write_to(main_fn)

with pytest.warns(asdf.exceptions.AsdfDeprecationWarning, match="find_references"):
with asdf.open(main_fn) as af:
af.resolve_references()
assert af["myref"] == 42
with asdf.open(main_fn) as af:
af.resolve_references()
assert af["myref"] == 42
8 changes: 3 additions & 5 deletions asdf/_tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
import os
import pathlib
import sys
import warnings

import numpy as np
import pytest
from numpy.testing import assert_array_equal

import asdf
from asdf import config_context, get_config, treeutil, versioning
from asdf.exceptions import AsdfDeprecationWarning, AsdfPackageVersionWarning, ValidationError
from asdf.exceptions import AsdfPackageVersionWarning, ValidationError
from asdf.extension import ExtensionProxy
from asdf.resource import ResourceMappingProxy
from asdf.testing.helpers import roundtrip_object, yaml_to_asdf
Expand Down Expand Up @@ -261,9 +260,8 @@ def test_context_handler_resolve_and_inline(tmp_path):
ff.write_to(str(tempname))

with asdf.open(tempname) as newf:
with warnings.catch_warnings():
warnings.filterwarnings("ignore", "resolve_and_inline is deprecated", AsdfDeprecationWarning)
newf.resolve_and_inline()
newf.resolve_references()
newf.set_array_storage(newf["random"], "inline")

with pytest.raises(OSError, match=r"Cannot access data from closed ASDF file"):
newf.tree["random"][0]
Expand Down
10 changes: 1 addition & 9 deletions asdf/_tests/test_asdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from asdf._asdf import AsdfFile, open_asdf
from asdf._entry_points import get_extensions
from asdf._tests._helpers import assert_tree_match
from asdf.exceptions import AsdfDeprecationWarning, AsdfWarning
from asdf.exceptions import AsdfWarning
from asdf.extension import ExtensionProxy
from asdf.testing.helpers import yaml_to_asdf
from asdf.versioning import AsdfVersion
Expand Down Expand Up @@ -102,14 +102,6 @@ def test_asdf_file_version():
with pytest.raises(ValueError, match=r"ASDF Standard version .* is not supported by asdf==.*"):
af.version = AsdfVersion("2.5.4")

af.version = "1.0.0"
with pytest.warns(AsdfDeprecationWarning, match="AsdfFile.version_map is deprecated"):
assert af.version_map["tags"]["tag:stsci.edu:asdf/core/asdf"] == "1.0.0"

af.version = "1.2.0"
with pytest.warns(AsdfDeprecationWarning, match="AsdfFile.version_map is deprecated"):
assert af.version_map["tags"]["tag:stsci.edu:asdf/core/asdf"] == "1.1.0"


def test_asdf_file_extensions():
af = AsdfFile()
Expand Down
Loading

0 comments on commit abeef0e

Please sign in to comment.