Skip to content

Commit

Permalink
deprecate AsdfFile.resolve_and_inline
Browse files Browse the repository at this point in the history
  • Loading branch information
braingram committed Nov 20, 2023
1 parent 3c36f4f commit 19487b3
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
The ASDF Standard is at v1.6.0
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

- Deprecate ``asdf.asdf`` [#1690]
- Deprecate ``asdf.asdf`` and ``AsdfFile.resolve_and_inline`` [#1690]

3.0.1 (2023-10-30)
------------------
Expand Down
6 changes: 6 additions & 0 deletions asdf/_asdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,12 @@ def resolve_and_inline(self):
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")
Expand Down
4 changes: 2 additions & 2 deletions asdf/_tests/tags/core/tests/test_ndarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,8 @@ def test_unicode_to_list(tmpdir):
fd.seek(0)

with asdf.open(fd) as ff:
ff.resolve_and_inline()
ff.write_to(io.BytesIO())
ff.resolve_references()
ff.write_to(io.BytesIO(), all_array_storage="inline")


def test_inline_masked_array(tmpdir):
Expand Down
7 changes: 5 additions & 2 deletions asdf/_tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
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 AsdfWarning, ValidationError
from asdf.exceptions import AsdfDeprecationWarning, AsdfWarning, ValidationError
from asdf.extension import ExtensionProxy

from ._helpers import assert_no_warnings, assert_roundtrip_tree, assert_tree_match, yaml_to_asdf
Expand Down Expand Up @@ -258,7 +259,9 @@ def test_context_handler_resolve_and_inline(tmp_path):
ff.write_to(str(tempname))

with asdf.open(tempname) as newf:
newf.resolve_and_inline()
with warnings.catch_warnings():
warnings.filterwarnings("ignore", "resolve_and_inline is deprecated", AsdfDeprecationWarning)
newf.resolve_and_inline()

with pytest.raises(OSError, match=r"Cannot access data from closed ASDF file"):
newf.tree["random"][0]
Expand Down
8 changes: 8 additions & 0 deletions asdf/_tests/test_deprecated.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import sys

import numpy as np
import pytest

import asdf
from asdf.exceptions import AsdfDeprecationWarning


Expand All @@ -22,3 +24,9 @@ def test_asdf_asdf_deprecation():
if "asdf.asdf" in sys.modules:
del sys.modules["asdf.asdf"]
import asdf.asdf # noqa: F401


def test_resolve_and_inline_deprecation():
with pytest.warns(AsdfDeprecationWarning, match="resolve_and_inline is deprecated"):
af = asdf.AsdfFile({"arr": np.arange(42)})
af.resolve_and_inline()
2 changes: 1 addition & 1 deletion asdf/_tests/test_reference_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def _compare_trees(name_without_ext, expect_warnings=False):
yaml_path = name_without_ext + ".yaml"

with asdf_open(asdf_path) as af_handle:
af_handle.resolve_and_inline()
af_handle.resolve_references()

with asdf_open(yaml_path) as ref:

Expand Down
4 changes: 4 additions & 0 deletions docs/asdf/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ Version 3.1
``asdf.asdf`` is deprecated. Please use the top-level ``asdf`` module for
``AsdfFile`` and ``open`` (same as ``asdf.asdf.open_asdf``).

``AsdfFile.resolve_and_inline`` is deprecated. Please use
``AsdfFile.resolve_references`` and provide ``all_array_storage='inline'`` to
``AdsfFile.write_to`` (or ``AsdfFile.update``).

Version 3.0
===========

Expand Down

0 comments on commit 19487b3

Please sign in to comment.