From 5773a4af5c88a8aa5f8edc7e54e210aef585784d Mon Sep 17 00:00:00 2001 From: Brett Date: Wed, 7 Aug 2024 11:01:45 -0400 Subject: [PATCH 1/5] deprecate ignore_version_mismatch --- asdf/_asdf.py | 13 ++++++++++--- pytest_asdf/plugin.py | 18 ++++++++++-------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/asdf/_asdf.py b/asdf/_asdf.py index ba3ddab61..e270f4eb9 100644 --- a/asdf/_asdf.py +++ b/asdf/_asdf.py @@ -72,7 +72,7 @@ def __init__( uri=None, extensions=None, version=None, - ignore_version_mismatch=True, + ignore_version_mismatch=NotSet, ignore_unrecognized_tag=False, ignore_implicit_conversion=NotSet, copy_arrays=NotSet, @@ -102,6 +102,7 @@ def __init__( 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. @@ -162,7 +163,12 @@ def __init__( else: self._custom_schema = None - self._ignore_version_mismatch = ignore_version_mismatch + 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 @@ -1619,7 +1625,7 @@ def open_asdf( mode=None, validate_checksums=False, extensions=None, - ignore_version_mismatch=True, + ignore_version_mismatch=NotSet, ignore_unrecognized_tag=False, _force_raw_types=False, copy_arrays=NotSet, @@ -1657,6 +1663,7 @@ def open_asdf( 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. diff --git a/pytest_asdf/plugin.py b/pytest_asdf/plugin.py index bccdf3e8a..e43b2a721 100644 --- a/pytest_asdf/plugin.py +++ b/pytest_asdf/plugin.py @@ -1,6 +1,7 @@ import io import os import pathlib +import warnings from dataclasses import dataclass import numpy as np @@ -44,7 +45,6 @@ def pytest_addoption(parser): "asdf_schema_ignore_version_mismatch", "Set to true to disable warnings when missing explicit support for a tag", type="bool", - default=True, ) parser.addoption("--asdf-tests", action="store_true", help="Enable ASDF schema tests") @@ -59,7 +59,6 @@ def from_parent( skip_examples=False, validate_default=True, ignore_unrecognized_tag=False, - ignore_version_mismatch=False, skip_tests=None, xfail_tests=None, **kwargs, @@ -75,7 +74,6 @@ def from_parent( result.skip_examples = skip_examples result.validate_default = validate_default result.ignore_unrecognized_tag = ignore_unrecognized_tag - result.ignore_version_mismatch = ignore_version_mismatch result.skip_tests = [] if skip_tests is None else skip_tests result.xfail_tests = [] if xfail_tests is None else xfail_tests @@ -101,7 +99,6 @@ def collect(self): example, index, ignore_unrecognized_tag=self.ignore_unrecognized_tag, - ignore_version_mismatch=self.ignore_version_mismatch, name=name, ) self._set_markers(item) @@ -194,7 +191,6 @@ def from_parent( example, example_index, ignore_unrecognized_tag=False, - ignore_version_mismatch=False, **kwargs, ): if hasattr(super(), "from_parent"): @@ -206,7 +202,6 @@ def from_parent( result.filename = str(schema_path) result.example = SchemaExample.from_schema(example) result.ignore_unrecognized_tag = ignore_unrecognized_tag - result.ignore_version_mismatch = ignore_version_mismatch return result def runtest(self): @@ -220,7 +215,6 @@ def runtest(self): ff = AsdfFile( uri=pathlib.Path(self.filename).expanduser().absolute().as_uri(), ignore_unrecognized_tag=self.ignore_unrecognized_tag, - ignore_version_mismatch=self.ignore_version_mismatch, ) # Fake an external file @@ -288,6 +282,15 @@ def pytest_collect_file(file_path, parent): validate_default = parent.config.getini("asdf_schema_validate_default") ignore_unrecognized_tag = parent.config.getini("asdf_schema_ignore_unrecognized_tag") ignore_version_mismatch = parent.config.getini("asdf_schema_ignore_version_mismatch") + if ignore_version_mismatch in (True, False): + from asdf.exceptions import AsdfDeprecationWarning + + # pytest will return an empty list for getini on a bool with no default + # since we have a True or False here warn the user that this setting is deprecated + warnings.warn( + "asdf_schema_ignore_version_mismatch is deprecated " "and has done nothing since asdf 3.0.0", + AsdfDeprecationWarning, + ) skip_tests = _parse_test_list(parent.config.getini("asdf_schema_skip_tests")) xfail_tests = _parse_test_list(parent.config.getini("asdf_schema_xfail_tests")) @@ -315,7 +318,6 @@ def pytest_collect_file(file_path, parent): skip_examples=(file_path.stem in skip_examples), validate_default=validate_default, ignore_unrecognized_tag=ignore_unrecognized_tag, - ignore_version_mismatch=ignore_version_mismatch, skip_tests=schema_skip_tests, xfail_tests=schema_xfail_tests, ) From d0806c2e689945ea9f972dd8702dd704b6979767 Mon Sep 17 00:00:00 2001 From: Brett Date: Wed, 7 Aug 2024 11:46:17 -0400 Subject: [PATCH 2/5] add test for ignore_version_mismatch deprecation --- asdf/_tests/test_deprecated.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/asdf/_tests/test_deprecated.py b/asdf/_tests/test_deprecated.py index 55bb02d13..09a7a3a99 100644 --- a/asdf/_tests/test_deprecated.py +++ b/asdf/_tests/test_deprecated.py @@ -158,3 +158,9 @@ def test_copy_arrays_deprecation(copy_arrays, memmap, tmp_path): with pytest.warns(AsdfWarning, match="copy_arrays is deprecated; use memmap instead"): with asdf.open(fn, copy_arrays=copy_arrays, memmap=memmap) as af: pass + + +@pytest.mark.parametrize("value", [True, False]) +def test_ignore_version_mismatch_deprecation(value): + with pytest.warns(AsdfDeprecationWarning, match="ignore_version_mismatch is deprecated"): + asdf.AsdfFile({}, ignore_version_mismatch=value) From 6b1fddf8f6f4f327ca70c2ce4b007731efc97812 Mon Sep 17 00:00:00 2001 From: Brett Date: Wed, 7 Aug 2024 12:05:29 -0400 Subject: [PATCH 3/5] change trigger for warning --- pytest_asdf/plugin.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pytest_asdf/plugin.py b/pytest_asdf/plugin.py index e43b2a721..6f5e60e7a 100644 --- a/pytest_asdf/plugin.py +++ b/pytest_asdf/plugin.py @@ -44,7 +44,8 @@ def pytest_addoption(parser): parser.addini( "asdf_schema_ignore_version_mismatch", "Set to true to disable warnings when missing explicit support for a tag", - type="bool", + type="string", + default="", ) parser.addoption("--asdf-tests", action="store_true", help="Enable ASDF schema tests") @@ -282,13 +283,11 @@ def pytest_collect_file(file_path, parent): validate_default = parent.config.getini("asdf_schema_validate_default") ignore_unrecognized_tag = parent.config.getini("asdf_schema_ignore_unrecognized_tag") ignore_version_mismatch = parent.config.getini("asdf_schema_ignore_version_mismatch") - if ignore_version_mismatch in (True, False): + if ignore_version_mismatch != "": from asdf.exceptions import AsdfDeprecationWarning - # pytest will return an empty list for getini on a bool with no default - # since we have a True or False here warn the user that this setting is deprecated warnings.warn( - "asdf_schema_ignore_version_mismatch is deprecated " "and has done nothing since asdf 3.0.0", + "asdf_schema_ignore_version_mismatch is deprecated and has done nothing since asdf 3.0.0", AsdfDeprecationWarning, ) From 47a8b1ffd17689de7ea5e1fec181650e965422fe Mon Sep 17 00:00:00 2001 From: Brett Date: Thu, 8 Aug 2024 08:30:29 -0400 Subject: [PATCH 4/5] minor style fix --- asdf/_asdf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/asdf/_asdf.py b/asdf/_asdf.py index e270f4eb9..40b2971ac 100644 --- a/asdf/_asdf.py +++ b/asdf/_asdf.py @@ -165,7 +165,7 @@ def __init__( if ignore_version_mismatch is not NotSet: warnings.warn( - "ignore_version_mismatch is deprecated and has done " "nothing since asdf 3.0.0", + "ignore_version_mismatch is deprecated and has done nothing since asdf 3.0.0", AsdfDeprecationWarning, ) From 0e7ce93e910825e7a43b2a0f366c0ddba0004572 Mon Sep 17 00:00:00 2001 From: Brett Date: Tue, 20 Aug 2024 10:43:27 -0400 Subject: [PATCH 5/5] add changelog --- changes/1819.removal.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changes/1819.removal.rst diff --git a/changes/1819.removal.rst b/changes/1819.removal.rst new file mode 100644 index 000000000..881fe2444 --- /dev/null +++ b/changes/1819.removal.rst @@ -0,0 +1,2 @@ +Deprecate ``ignore_version_mismatch``. This option has done nothing since +asdf 3.0.0 and will be removed in an upcoming asdf version