Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoSign in
Socket

asdf

Package Overview
Dependencies
Maintainers
8
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

asdf - pypi Package Compare versions

Comparing version
3.5.0
to
4.0.0
+16
-13
.github/pull_request_template.md

@@ -19,3 +19,3 @@ <!---

# Description
## Description

@@ -29,15 +29,18 @@ <!--

# Checklist:
## Tasks
- [ ] pre-commit checks ran successfully
- [ ] tests ran successfully
- [ ] for a public change, added a [towncrier news fragment](https://towncrier.readthedocs.io/en/stable/tutorial.html#creating-news-fragments) <details><summary>`changes/<PR#>.<changetype>.rst`</summary>
- [ ] [run `pre-commit` on your machine](https://pre-commit.com/#quick-start)
- [ ] run `pytest` on your machine
- [ ] Does this PR add new features and / or change user-facing code / API? (if not, label with `no-changelog-entry-needed`)
- [ ] write news fragment(s) in `changes/`: `echo "changed something" > changes/<PR#>.<changetype>.rst` (see below for change types)
- [ ] update relevant docstrings and / or `docs/` page
- [ ] for any new features, add unit tests
- ``changes/<PR#>.feature.rst``: new feature
- ``changes/<PR#>.bugfix.rst``: bug fix
- ``changes/<PR#>.doc.rst``: documentation change
- ``changes/<PR#>.removal.rst``: deprecation or removal of public API
- ``changes/<PR#>.general.rst``: infrastructure or miscellaneous change
</details>
- [ ] for a public change, updated documentation
- [ ] for any new features, unit tests were added
<details><summary>news fragment change types...</summary>
- ``changes/<PR#>.feature.rst``: new feature
- ``changes/<PR#>.bugfix.rst``: bug fix
- ``changes/<PR#>.doc.rst``: documentation change
- ``changes/<PR#>.removal.rst``: deprecation or removal of public API
- ``changes/<PR#>.general.rst``: infrastructure or miscellaneous change
</details>

@@ -47,3 +47,3 @@ name: CI

name: Python 3.13 coverage
python-version: 3.13-dev
python-version: 3.13
- linux: coverage

@@ -50,0 +50,0 @@ name: Python 3.12 coverage

@@ -76,1 +76,2 @@ name: Downstream

- linux: dkist
- linux: abacusutils
Metadata-Version: 2.1
Name: asdf
Version: 3.5.0
Version: 4.0.0
Summary: Python implementation of the ASDF Standard

@@ -261,7 +261,4 @@ Author-email: The ASDF Developers <help@stsci.edu>

.. warning::
The ``copy_arrays`` argument of `asdf.open()` and `AsdfFile` is deprecated,
and will be removed in ASDF 4.0. It is replaced by ``memmap``, which
is the opposite of ``copy_arrays`` (``memmap == not copy_arrays``).
In ASDF 4.0, ``memmap`` will default to ``False``, which means arrays
will no longer be memory-mapped by default.
The ``memmap`` argument replaces ``copy_arrays`` as of ASDF 4.0
(``memmap == not copy_arrays``).

@@ -268,0 +265,0 @@ To get a quick overview of the data stored in the file, use the top-level

@@ -29,3 +29,2 @@ CHANGES.rst

asdf/_version.py
asdf/asdf.py
asdf/config.py

@@ -41,3 +40,2 @@ asdf/conftest.py

asdf/search.py
asdf/stream.py
asdf/tagged.py

@@ -44,0 +42,0 @@ asdf/treeutil.py

@@ -21,3 +21,3 @@ """

----------
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

@@ -24,0 +24,0 @@ will first be passed to asdf.open(...).

@@ -135,5 +135,5 @@ import os

raise TypeError('Read or append modes don\'t work with atomic_open')
f = tempfile.NamedTemporaryFile(mode, prefix='.___atomic_write',
f = tempfile.NamedTemporaryFile(mode, prefix='.asdf_tmp',
dir=os.path.dirname(filename),
delete=False)
return _AtomicWFile(f, f.name, filename)

@@ -1,3 +0,1 @@

import pytest
import asdf

@@ -25,5 +23,4 @@

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

@@ -80,4 +80,5 @@ import datetime

result = helpers.roundtrip_object(subclass_metadata)
# support for this was dropped in 1.6.0
result = helpers.roundtrip_object(subclass_metadata, version="1.5.0")
assert result == subclass_metadata

@@ -78,3 +78,3 @@ import contextlib

---
$schema: "http://stsci.edu/schemas/asdf/asdf-schema-1.0.0"
$schema: "http://stsci.edu/schemas/asdf/asdf-schema-1.1.0"
id: "http://nowhere.org/schemas/custom/datatype-1.0.0"

@@ -106,3 +106,3 @@ type: object

---
$schema: "http://stsci.edu/schemas/asdf/asdf-schema-1.0.0"
$schema: "http://stsci.edu/schemas/asdf/asdf-schema-1.1.0"
id: "http://nowhere.org/schemas/custom/ndim-1.0.0"

@@ -287,3 +287,3 @@ type: object

yaml = """
x0: !core/ndarray-1.0.0
x0: !core/ndarray-1.1.0
data: [-1.0, 1.0]

@@ -377,3 +377,3 @@ """

def test_inline_bare():
content = "arr: !core/ndarray-1.0.0 [[1, 2, 3, 4], [5, 6, 7, 8]]"
content = "arr: !core/ndarray-1.1.0 [[1, 2, 3, 4], [5, 6, 7, 8]]"
buff = helpers.yaml_to_asdf(content)

@@ -420,3 +420,3 @@

content = """
arr: !core/ndarray-1.0.0
arr: !core/ndarray-1.1.0
data: [[1, 2, 3, 1234], [5, 6, 7, 8]]

@@ -433,3 +433,3 @@ mask: 1234

content = """
arr: !core/ndarray-1.0.0
arr: !core/ndarray-1.1.0
data: [[1, 2, 3, .NaN], [5, 6, 7, 8]]

@@ -464,3 +464,3 @@ mask: .NaN

def test_inline_string():
content = "arr: !core/ndarray-1.0.0 ['a', 'b', 'c']"
content = "arr: !core/ndarray-1.1.0 ['a', 'b', 'c']"
buff = helpers.yaml_to_asdf(content)

@@ -474,3 +474,3 @@

content = """
arr: !core/ndarray-1.0.0
arr: !core/ndarray-1.1.0
datatype: [['ascii', 4], uint16, uint16, ['ascii', 4]]

@@ -633,6 +633,6 @@ data: [[M110, 110, 205, And],

content = """
arr: !core/ndarray-1.0.0
arr: !core/ndarray-1.1.0
data: [1, 2, 3]
dtype: int32
mask: !core/ndarray-1.0.0
mask: !core/ndarray-1.1.0
data: [true, true, false]

@@ -648,6 +648,6 @@ """

content = """
arr: !core/ndarray-1.0.0
arr: !core/ndarray-1.1.0
data: [1, 2, 3]
dtype: int32
mask: !core/ndarray-1.0.0
mask: !core/ndarray-1.1.0
data: ['a', 'b', 'c']

@@ -670,3 +670,3 @@ """

obj: !<tag:nowhere.org:custom/ndim-1.0.0>
a: !core/ndarray-1.0.0
a: !core/ndarray-1.1.0
data: [1, 2, 3]

@@ -686,3 +686,3 @@ """

obj: !<tag:nowhere.org:custom/ndim-1.0.0>
a: !core/ndarray-1.0.0
a: !core/ndarray-1.1.0
data: [[1, 2, 3]]

@@ -697,3 +697,3 @@ """

obj: !<tag:nowhere.org:custom/ndim-1.0.0>
a: !core/ndarray-1.0.0
a: !core/ndarray-1.1.0
shape: [1, 3]

@@ -709,3 +709,3 @@ data: [[1, 2, 3]]

obj: !<tag:nowhere.org:custom/ndim-1.0.0>
b: !core/ndarray-1.0.0
b: !core/ndarray-1.1.0
data: [1, 2, 3]

@@ -720,3 +720,3 @@ """

obj: !<tag:nowhere.org:custom/ndim-1.0.0>
b: !core/ndarray-1.0.0
b: !core/ndarray-1.1.0
data: [[1, 2, 3]]

@@ -731,3 +731,3 @@ """

obj: !<tag:nowhere.org:custom/ndim-1.0.0>
b: !core/ndarray-1.0.0
b: !core/ndarray-1.1.0
data: [[[1, 2, 3]]]

@@ -750,3 +750,3 @@ """

obj: !<tag:nowhere.org:custom/datatype-1.0.0>
a: !core/ndarray-1.0.0
a: !core/ndarray-1.1.0
data: [1, 2, 3]

@@ -762,3 +762,3 @@ datatype: float32

obj: !<tag:nowhere.org:custom/datatype-1.0.0>
a: !core/ndarray-1.0.0
a: !core/ndarray-1.1.0
data: [1, 2, 3]

@@ -779,3 +779,3 @@ datatype: float64

obj: !<tag:nowhere.org:custom/datatype-1.0.0>
a: !core/ndarray-1.0.0
a: !core/ndarray-1.1.0
data: [1, 2, 3]

@@ -791,3 +791,3 @@ datatype: int16

obj: !<tag:nowhere.org:custom/datatype-1.0.0>
b: !core/ndarray-1.0.0
b: !core/ndarray-1.1.0
data: [1, 2, 3]

@@ -808,3 +808,3 @@ datatype: int16

obj: !<tag:nowhere.org:custom/datatype-1.0.0>
a: !core/ndarray-1.0.0
a: !core/ndarray-1.1.0
data: [[1, 'a'], [2, 'b'], [3, 'c']]

@@ -832,3 +832,3 @@ datatype:

obj: !<tag:nowhere.org:custom/datatype-1.0.0>
c: !core/ndarray-1.0.0
c: !core/ndarray-1.1.0
data: [[1, 'a'], [2, 'b'], [3, 'c']]

@@ -848,3 +848,3 @@ datatype:

obj: !<tag:nowhere.org:custom/datatype-1.0.0>
c: !core/ndarray-1.0.0
c: !core/ndarray-1.1.0
data: [[1, 'a'], [2, 'b'], [3, 'c']]

@@ -869,3 +869,3 @@ datatype:

obj: !<tag:nowhere.org:custom/datatype-1.0.0>
c: !core/ndarray-1.0.0
c: !core/ndarray-1.1.0
data: [[1, 'a', 0], [2, 'b', 1], [3, 'c', 2]]

@@ -892,3 +892,3 @@ datatype:

obj: !<tag:nowhere.org:custom/datatype-1.0.0>
c: !core/ndarray-1.0.0
c: !core/ndarray-1.1.0
data: [1, 2, 3]

@@ -908,3 +908,3 @@ """

obj: !<tag:nowhere.org:custom/datatype-1.0.0>
d: !core/ndarray-1.0.0
d: !core/ndarray-1.1.0
data: [[1, 'a'], [2, 'b'], [3, 'c']]

@@ -929,3 +929,3 @@ datatype:

obj: !<tag:nowhere.org:custom/datatype-1.0.0>
d: !core/ndarray-1.0.0
d: !core/ndarray-1.1.0
data: [[1, 'a'], [2, 'b'], [3, 'c']]

@@ -954,3 +954,3 @@ datatype:

content = """
arr: !core/ndarray-1.0.0
arr: !core/ndarray-1.1.0
data: [1, 2, 3]

@@ -1007,3 +1007,3 @@ shape: [2]

with asdf.AsdfFile(tree) as af:
with asdf.AsdfFile(tree, memmap=False) as af:
# Make sure we're actually writing to an internal array for this test

@@ -1034,3 +1034,3 @@ af.write_to(tmpfile, all_array_storage="internal")

# Opening in read mode (the default) should mean array is readonly
with asdf.open(tmpfile) as af:
with asdf.open(tmpfile, memmap=True) as af:
assert af["data"].flags.writeable is False

@@ -1079,3 +1079,3 @@ with pytest.raises(ValueError, match=r"assignment destination is read-only"):

with asdf.open(tmpfile, mode="rw") as af:
with asdf.open(tmpfile, mode="rw", memmap=True) as af:
assert np.all(af.tree["data"] == 0)

@@ -1082,0 +1082,0 @@ array_before = af.tree["data"].__array__()

@@ -7,3 +7,2 @@ import copy

import sys
import warnings

@@ -16,3 +15,3 @@ import numpy as np

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

@@ -66,3 +65,3 @@ from asdf.resource import ResourceMappingProxy

with asdf.open(tmpfile) as af:
with asdf.open(tmpfile, memmap=True) as af:
assert af["baz"].flags.writeable is False

@@ -267,5 +266,4 @@

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")

@@ -272,0 +270,0 @@ with pytest.raises(OSError, match=r"Cannot access data from closed ASDF file"):

@@ -814,14 +814,9 @@ import io

[
({}, True),
({"memmap": True}, True),
({"memmap": False}, False),
({"copy_arrays": True}, False),
({"copy_arrays": False}, True),
({"copy_arrays": True, "memmap": True}, True),
({"copy_arrays": False, "memmap": True}, True),
({"copy_arrays": True, "memmap": False}, False),
({"copy_arrays": False, "memmap": False}, False),
({}, False),
({"lazy_load": True, "memmap": True}, True),
({"lazy_load": False, "memmap": True}, True),
({"lazy_load": True, "memmap": False}, False),
({"lazy_load": False, "memmap": False}, False),
],
)
@pytest.mark.filterwarnings("ignore:copy_arrays is deprecated")
def test_open_no_memmap(filename_with_array, open_kwargs, should_memmap):

@@ -832,7 +827,5 @@ """

default (no kwargs)
copy_arrays
memmap (overwrites copy_arrays)
memmap
"""
with asdf.open(filename_with_array, lazy_load=False, **open_kwargs) as af:
with asdf.open(filename_with_array, **open_kwargs) as af:
array = af.tree["array"]

@@ -839,0 +832,0 @@ if should_memmap:

@@ -9,3 +9,3 @@ import os

from asdf._tests._helpers import assert_tree_match
from asdf.exceptions import AsdfDeprecationWarning, AsdfWarning
from asdf.exceptions import AsdfWarning
from asdf.extension import ExtensionProxy

@@ -106,11 +106,3 @@ from asdf.testing.helpers import yaml_to_asdf

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():

@@ -117,0 +109,0 @@ af = AsdfFile()

@@ -0,1 +1,2 @@

import collections
import fractions

@@ -9,3 +10,3 @@ import sys

from asdf import AsdfFile, config_context
from asdf.exceptions import AsdfManifestURIMismatchWarning, AsdfSerializationError, AsdfWarning, ValidationError
from asdf.exceptions import AsdfManifestURIMismatchWarning, AsdfSerializationError, ValidationError
from asdf.extension import (

@@ -896,6 +897,4 @@ Compressor,

extension = FullExtension(converters=[FooConverter()], tags=tags)
ctx_type = pytest.warns if is_subclass else pytest.raises
exception_class = AsdfWarning if is_subclass else RuntimeError
with config_context() as config:
with ctx_type(exception_class, match="Converter handles multiple tags"):
with pytest.raises(RuntimeError, match="Converter handles multiple tags"):
config.add_extension(extension)

@@ -1054,1 +1053,31 @@

assert isinstance(converter.delegate, MailboxConverter)
def test_named_tuple_extension():
Point = collections.namedtuple("Point", ["x", "y"])
class PointConverter:
tags = ["asdf://example.com/tags/point-1.0.0"]
types = [Point]
def to_yaml_tree(self, obj, tag, ctx):
return list(obj)
def from_yaml_tree(self, node, tag, ctx):
return Point(*node)
class PointExtension:
tags = PointConverter.tags
converters = [PointConverter()]
extension_uri = "asdf://example.com/extensions/point-1.0.0"
pt = Point(1, 2)
# without the extension we can't serialize this
with pytest.raises(AsdfSerializationError, match="is not serializable by asdf"):
roundtrip_object(pt)
with config_context() as cfg:
cfg.add_extension(PointExtension())
rpt = roundtrip_object(pt)
assert isinstance(rpt, Point)

@@ -102,3 +102,2 @@ import io

@pytest.mark.filterwarnings("ignore::asdf.exceptions.AsdfDeprecationWarning")
def test_not_asdf_file():

@@ -105,0 +104,0 @@ buff = io.BytesIO(b"SIMPLE")

@@ -113,3 +113,3 @@ import io

with _roundtrip(tree, get_write_fd, get_read_fd) as ff:
with _roundtrip(tree, get_write_fd, get_read_fd, read_options={"memmap": True}) as ff:
assert len(ff._blocks.blocks) == 2

@@ -137,3 +137,3 @@ assert isinstance(ff._blocks.blocks[0].cached_data, np.memmap)

with _roundtrip(tree, get_write_fd, get_read_fd) as ff:
with _roundtrip(tree, get_write_fd, get_read_fd, read_options={"memmap": True}) as ff:
assert len(ff._blocks.blocks) == 2

@@ -178,3 +178,3 @@ assert isinstance(ff._blocks.blocks[0].cached_data, np.memmap)

with _roundtrip(tree, get_write_fd, get_read_fd) as ff:
with _roundtrip(tree, get_write_fd, get_read_fd, read_options={"memmap": True}) as ff:
assert len(ff._blocks.blocks) == 2

@@ -181,0 +181,0 @@ assert isinstance(ff._blocks.blocks[0].cached_data, np.memmap)

@@ -111,3 +111,3 @@ import datetime

metadata = af.tree["history"]["extensions"][0]
assert metadata.extension_uri == "asdf://asdf-format.org/core/extensions/core-1.5.0"
assert metadata.extension_uri == "asdf://asdf-format.org/core/extensions/core-1.6.0"
assert metadata.extension_class == "asdf.extension._manifest.ManifestExtension"

@@ -114,0 +114,0 @@ assert metadata.software["name"] == "asdf"

@@ -159,3 +159,3 @@ import os

---
$schema: "asdf://stsci.edu/schemas/asdf/asdf-schema-1.0.0"
$schema: "asdf://stsci.edu/schemas/asdf/asdf-schema-1.1.0"
id: "asdf://somewhere.org/asdf/schemas/foo-1.0.0"

@@ -225,3 +225,3 @@

---
$schema: "asdf://stsci.edu/schemas/asdf/asdf-schema-1.0.0"
$schema: "asdf://stsci.edu/schemas/asdf/asdf-schema-1.1.0"
id: "asdf://somewhere.org/asdf/schemas/bar-1.0.0"

@@ -250,3 +250,3 @@

---
$schema: "asdf://stsci.edu/schemas/asdf/asdf-schema-1.0.0"
$schema: "asdf://stsci.edu/schemas/asdf/asdf-schema-1.1.0"
id: "asdf://somewhere.org/asdf/schemas/drink-1.0.0"

@@ -653,3 +653,10 @@

tree = {"random": 3.14159, "rtest": recursive_obj}
af = asdf.AsdfFile(tree)
af = asdf.AsdfFile()
# we need to do this to avoid validation against the
# manifest (generated in manifest_extension) which is
# now supported with the default asdf standard 1.6.0
# I'm not sure why the manifest has this restriction
# and prior to switching to the default 1.6.0 was ignored
# which allowed this test to pass.
af._tree = tree
af.info(refresh_extension_manager=True)

@@ -656,0 +663,0 @@ captured = capsys.readouterr()

@@ -10,3 +10,2 @@ import io

from asdf import reference
from asdf.exceptions import AsdfDeprecationWarning
from asdf.tags.core import ndarray

@@ -61,5 +60,2 @@

assert len(ff._external_asdf_by_uri) == 1
with pytest.raises((ValueError, RuntimeError), match=r"assignment destination is read-only"):
# Assignment destination is readonly
ff.tree["science_data"][0] = 42

@@ -85,4 +81,2 @@ assert_array_equal(ff.tree["science_data2"], exttree["cool_stuff"]["a"])

with asdf.AsdfFile({}, uri=(tmp_path / "main.asdf").as_uri()) as ff:
# avoid passing tree to AsdfFile to avoid the deprecation warning, this can be updated
# when automatic find_references on AsdfFile.__init__ is removed
ff.tree = tree

@@ -95,10 +89,8 @@ ff.find_references()

with pytest.warns(AsdfDeprecationWarning, match="find_references during open"), asdf.open(internal_path) as ff:
# this can be updated to add a find_references call when the deprecated automatic
# find_references on open is removed
with asdf.open(internal_path) as ff:
ff.find_references()
do_asserts(ff)
with pytest.warns(AsdfDeprecationWarning, match="find_references during open"), asdf.open(internal_path) as ff:
# this can be updated to add a find_references call when the deprecated automatic
# find_references on open is removed
with asdf.open(internal_path) as ff:
ff.find_references()
assert len(ff._external_asdf_by_uri) == 0

@@ -131,4 +123,2 @@ ff.resolve_references()

# avoid passing tree to AsdfFile to avoid the deprecation warning, this can be updated
# when automatic find_references on AsdfFile.__init__ is removed
ff = asdf.AsdfFile()

@@ -140,4 +130,2 @@ ff.tree = tree

# avoid passing tree to AsdfFile to avoid the deprecation warning, this can be updated
# when automatic find_references on AsdfFile.__init__ is removed
ff = asdf.AsdfFile({}, uri="http://httpstat.us/404")

@@ -150,4 +138,2 @@ ff.tree = tree

# avoid passing tree to AsdfFile to avoid the deprecation warning, this can be updated
# when automatic find_references on AsdfFile.__init__ is removed
ff = asdf.AsdfFile({}, uri=(tmp_path / "main.asdf").as_uri())

@@ -168,4 +154,2 @@ ff.tree = tree

# avoid passing tree to AsdfFile to avoid the deprecation warning, this can be updated
# when automatic find_references on AsdfFile.__init__ is removed
with asdf.AsdfFile({}, uri=(tmp_path / "main.asdf").as_uri()) as ff:

@@ -179,4 +163,2 @@ ff.tree = tree

# avoid passing tree to AsdfFile to avoid the deprecation warning, this can be updated
# when automatic find_references on AsdfFile.__init__ is removed
with asdf.AsdfFile({}, uri=(tmp_path / "main.asdf").as_uri()) as ff:

@@ -206,8 +188,4 @@ ff.tree = tree

with (
pytest.warns(AsdfDeprecationWarning, match="find_references during open"),
asdf.open(os.path.join(str(tmp_path), "source.asdf")) as ff,
):
# this can be updated to add a find_references call when the deprecated automatic
# find_references on open is removed
with (asdf.open(os.path.join(str(tmp_path), "source.asdf")) as ff,):
ff.find_references()
assert ff.tree["ref"]._uri == "external.asdf#f~0o~0o~1/a"

@@ -221,4 +199,3 @@

with pytest.warns(AsdfDeprecationWarning, match="find_references during AsdfFile.__init__"):
ff = asdf.AsdfFile(tree)
ff = asdf.AsdfFile(tree)
ff.find_references()

@@ -225,0 +202,0 @@ assert isinstance(ff.tree["bar"], reference.Reference)

@@ -11,3 +11,3 @@ import contextlib

from asdf import config_context, constants, get_config, schema, tagged, util, yamlutil
from asdf.exceptions import AsdfConversionWarning, AsdfDeprecationWarning, AsdfWarning, ValidationError
from asdf.exceptions import AsdfConversionWarning, AsdfWarning, ValidationError
from asdf.extension import TagDefinition

@@ -55,3 +55,3 @@ from asdf.testing.helpers import yaml_to_asdf

things:
$ref: "http://stsci.edu/schemas/asdf/core/ndarray-1.0.0"
$ref: "http://stsci.edu/schemas/asdf/core/ndarray-1.1.0"
required: [name, things]

@@ -122,3 +122,3 @@ ...

---
$schema: "http://stsci.edu/schemas/asdf/asdf-schema-1.0.0"
$schema: "http://stsci.edu/schemas/asdf/asdf-schema-1.1.0"
id: "http://stsci.edu/schemas/asdf/nugatory/nugatory-1.0.0"

@@ -130,3 +130,3 @@ tag: "tag:stsci.edu:asdf/nugatory/nugatory-1.0.0"

foobar:
$ref: "../core/ndarray-1.0.0"
$ref: "../core/ndarray-1.1.0"

@@ -143,26 +143,2 @@ required: [foobar]

def test_load_schema_with_full_tag(tmp_path):
schema_def = """
%YAML 1.1
---
$schema: "http://stsci.edu/schemas/asdf/asdf-schema-1.0.0"
id: "http://stsci.edu/schemas/asdf/nugatory/nugatory-1.0.0"
tag: "tag:stsci.edu:asdf/nugatory/nugatory-1.0.0"
type: object
properties:
foobar:
$ref: "tag:stsci.edu:asdf/core/ndarray-1.0.0"
required: [foobar]
...
"""
schema_path = tmp_path / "nugatory.yaml"
schema_path.write_bytes(schema_def.encode())
with pytest.warns(AsdfDeprecationWarning, match="Resolving by tag is deprecated"):
schema_tree = schema.load_schema(str(schema_path), resolve_references=True)
schema.check_schema(schema_tree)
def test_load_schema_with_file_url(tmp_path):

@@ -173,3 +149,3 @@ schema_def = """

---
$schema: "http://stsci.edu/schemas/asdf/asdf-schema-1.0.0"
$schema: "http://stsci.edu/schemas/asdf/asdf-schema-1.1.0"
id: "http://stsci.edu/schemas/asdf/nugatory/nugatory-1.0.0"

@@ -181,3 +157,3 @@ tag: "tag:stsci.edu:asdf/nugatory/nugatory-1.0.0"

foobar:
$ref: "http://stsci.edu/schemas/asdf/core/ndarray-1.0.0"
$ref: "http://stsci.edu/schemas/asdf/core/ndarray-1.1.0"

@@ -197,3 +173,3 @@ required: [foobar]

---
$schema: http://stsci.edu/schemas/asdf/asdf-schema-1.0.0
$schema: http://stsci.edu/schemas/asdf/asdf-schema-1.1.0
id: asdf://somewhere.org/schemas/bar

@@ -207,3 +183,3 @@

---
$schema: http://stsci.edu/schemas/asdf/asdf-schema-1.0.0
$schema: http://stsci.edu/schemas/asdf/asdf-schema-1.1.0
id: asdf://somewhere.org/schemas/foo

@@ -246,3 +222,3 @@

---
$schema: http://stsci.edu/schemas/asdf/asdf-schema-1.0.0
$schema: http://stsci.edu/schemas/asdf/asdf-schema-1.1.0
id: http://stsci.edu/schemas/bar

@@ -256,3 +232,3 @@

---
$schema: http://stsci.edu/schemas/asdf/asdf-schema-1.0.0
$schema: http://stsci.edu/schemas/asdf/asdf-schema-1.1.0
id: http://stsci.edu/schemas/foo

@@ -415,3 +391,3 @@

ndarray_schema = schema.load_schema("http://stsci.edu/schemas/asdf/core/ndarray-1.0.0")
ndarray_schema = schema.load_schema("http://stsci.edu/schemas/asdf/core/ndarray-1.1.0")
property_order = ndarray_schema["anyOf"][1]["propertyOrder"]

@@ -487,3 +463,3 @@

yaml = f"""
array: !core/ndarray-1.0.0
array: !core/ndarray-1.1.0
data: [0, 1, 2]

@@ -551,3 +527,3 @@ custom: !<{tag_uri}>

s["properties"]["a"]["tag"] = "tag:stsci.edu/asdf/core/ndarray-1.0.0"
s["properties"]["a"]["tag"] = "tag:stsci.edu/asdf/core/ndarray-1.1.0"
with pytest.raises(ValidationError, match=r"mismatched tags, wanted .*, got .*"):

@@ -639,2 +615,4 @@ schema.check_schema(s)

with config_context() as cfg:
# later versions do not fill defaults
cfg.default_version = "1.5.0"
cfg.add_extension(DefaultExtension())

@@ -650,3 +628,3 @@ cfg.add_resource_mapping({schema_uri: tag_schema})

"""
buff = yaml_to_asdf(yaml)
buff = yaml_to_asdf(yaml, version="1.5.0")
with asdf.open(buff) as ff:

@@ -773,3 +751,3 @@ assert "a" in ff.tree["custom"]

"Something"
things: !core/ndarray-1.0.0
things: !core/ndarray-1.1.0
data: [1, 2, 3]

@@ -831,3 +809,3 @@ """

"Something"
things: !core/ndarray-1.0.0
things: !core/ndarray-1.1.0
data: [1, 2, 3]

@@ -1261,3 +1239,3 @@ """

---
$schema: http://stsci.edu/schemas/asdf/asdf-schema-1.0.0
$schema: http://stsci.edu/schemas/asdf/asdf-schema-1.1.0
id: asdf://somewhere.org/schemas/foo

@@ -1278,3 +1256,3 @@ tag: asdf://somewhere.org/tags/foo

---
$schema: http://stsci.edu/schemas/asdf/asdf-schema-1.0.0
$schema: http://stsci.edu/schemas/asdf/asdf-schema-1.1.0
id: asdf://somewhere.org/schemas/bar

@@ -1281,0 +1259,0 @@ tag: asdf://somewhere.org/tags/bar-*

@@ -19,6 +19,6 @@ import pytest

- {'message': 'there is no tag'}
- !core/ndarray-1.0.0
- !core/ndarray-1.1.0
[[1, 2, 3], [4, 5, 6]]
- !<tag:nowhere.org:custom/also_undefined-1.3.0>
- !core/ndarray-1.0.0 [[7],[8],[9],[10]]
- !core/ndarray-1.1.0 [[7],[8],[9],[10]]
- !core/complex-1.0.0 3.14j

@@ -25,0 +25,0 @@ """

import contextlib
import io
import warnings

@@ -10,15 +9,4 @@ import numpy as np

from asdf import generic_io, util
from asdf.exceptions import AsdfDeprecationWarning
def test_is_primitive():
with warnings.catch_warnings():
warnings.filterwarnings("ignore", "asdf.util.is_primitive is deprecated", AsdfDeprecationWarning)
for value in [None, "foo", 1, 1.39, 1 + 1j, True]:
assert util.is_primitive(value) is True
for value in [[], (), {}, set()]:
assert util.is_primitive(value) is False
def test_not_set():

@@ -108,21 +96,2 @@ assert util.NotSet is not None

def test_minversion():
import numpy as np
import yaml
good_versions = ["1.16", "1.16.1", "1.16.0.dev", "1.16dev"]
bad_versions = ["100000", "100000.2rc1"]
with warnings.catch_warnings():
warnings.filterwarnings("ignore", "asdf.util.minversion", AsdfDeprecationWarning)
for version in good_versions:
assert util.minversion(np, version)
assert util.minversion("numpy", version)
for version in bad_versions:
assert not util.minversion(np, version)
assert not util.minversion("numpy", version)
assert util.minversion(yaml, "3.1")
assert util.minversion("yaml", "3.1")
@pytest.mark.parametrize("input_type", ["filename", "binary_file", "generic_file"])

@@ -129,0 +98,0 @@ @pytest.mark.parametrize("tagged", [True, False])

from itertools import combinations
import pytest
from asdf.exceptions import AsdfDeprecationWarning
from asdf.versioning import (
AsdfSpec,
AsdfVersion,

@@ -174,111 +170,1 @@ asdf_standard_development_version,

assert (2, 1, 1) >= version
def test_spec_version_match():
with pytest.warns(AsdfDeprecationWarning, match="AsdfSpec is deprecated"):
spec = AsdfSpec(">=1.1.0")
assert spec.match(AsdfVersion("1.1.0"))
assert spec.match(AsdfVersion("1.2.0"))
assert not spec.match(AsdfVersion("1.0.0"))
assert not spec.match(AsdfVersion("1.0.9"))
def test_spec_version_select():
with pytest.warns(AsdfDeprecationWarning, match="AsdfSpec is deprecated"):
spec = AsdfSpec(">=1.1.0")
versions = [AsdfVersion(x) for x in ["1.0.0", "1.0.9", "1.1.0", "1.2.0"]]
assert spec.select(versions) == "1.2.0"
assert spec.select(versions[:-1]) == "1.1.0"
assert spec.select(versions[:-2]) is None
def test_spec_version_filter():
with pytest.warns(AsdfDeprecationWarning, match="AsdfSpec is deprecated"):
spec = AsdfSpec(">=1.1.0")
versions = [AsdfVersion(x) for x in ["1.0.0", "1.0.9", "1.1.0", "1.2.0"]]
for x, y in zip(spec.filter(versions), ["1.1.0", "1.2.0"]):
assert x == y
def test_spec_string_match():
with pytest.warns(AsdfDeprecationWarning, match="AsdfSpec is deprecated"):
spec = AsdfSpec(">=1.1.0")
assert spec.match("1.1.0")
assert spec.match("1.2.0")
assert not spec.match("1.0.0")
assert not spec.match("1.0.9")
def test_spec_string_select():
with pytest.warns(AsdfDeprecationWarning, match="AsdfSpec is deprecated"):
spec = AsdfSpec(">=1.1.0")
versions = ["1.0.0", "1.0.9", "1.1.0", "1.2.0"]
assert spec.select(versions) == "1.2.0"
assert spec.select(versions[:-1]) == "1.1.0"
assert spec.select(versions[:-2]) is None
def test_spec_string_filter():
with pytest.warns(AsdfDeprecationWarning, match="AsdfSpec is deprecated"):
spec = AsdfSpec(">=1.1.0")
versions = ["1.0.0", "1.0.9", "1.1.0", "1.2.0"]
for x, y in zip(spec.filter(versions), ["1.1.0", "1.2.0"]):
assert x == y
def test_spec_tuple_match():
with pytest.warns(AsdfDeprecationWarning, match="AsdfSpec is deprecated"):
spec = AsdfSpec(">=1.1.0")
assert spec.match((1, 1, 0))
assert spec.match((1, 2, 0))
assert not spec.match((1, 0, 0))
assert not spec.match((1, 0, 9))
def test_spec_tuple_select():
with pytest.warns(AsdfDeprecationWarning, match="AsdfSpec is deprecated"):
spec = AsdfSpec(">=1.1.0")
versions = [(1, 0, 0), (1, 0, 9), (1, 1, 0), (1, 2, 0)]
assert spec.select(versions) == "1.2.0"
assert spec.select(versions[:-1]) == "1.1.0"
assert spec.select(versions[:-2]) is None
def test_spec_tuple_filter():
with pytest.warns(AsdfDeprecationWarning, match="AsdfSpec is deprecated"):
spec = AsdfSpec(">=1.1.0")
versions = [(1, 0, 0), (1, 0, 9), (1, 1, 0), (1, 2, 0)]
for x, y in zip(spec.filter(versions), ["1.1.0", "1.2.0"]):
assert x == y
def test_spec_equal():
"""Make sure that equality means match"""
with pytest.warns(AsdfDeprecationWarning, match="AsdfSpec is deprecated"):
spec = AsdfSpec(">=1.2.0")
version0 = AsdfVersion("1.1.0")
version1 = AsdfVersion("1.3.0")
assert spec != version0
assert version0 != spec
assert spec == version1
assert version1 == spec
assert spec != "1.1.0"
assert "1.1.0" != spec
assert spec == "1.3.0"
assert "1.3.0" == spec
assert spec != (1, 1, 0)
assert (1, 1, 0) != spec
assert spec == (1, 3, 0)
assert (1, 3, 0) == spec
import contextlib
import io
import re
from collections import OrderedDict, namedtuple
from typing import NamedTuple
from collections import OrderedDict

@@ -13,3 +12,3 @@ import numpy as np

from asdf import tagged, treeutil, yamlutil
from asdf.exceptions import AsdfConversionWarning, AsdfDeprecationWarning, AsdfSerializationError, AsdfWarning
from asdf.exceptions import AsdfConversionWarning, AsdfDeprecationWarning, AsdfSerializationError
from asdf.testing.helpers import yaml_to_asdf

@@ -112,10 +111,2 @@

def run_tuple_test(input_tree, **kwargs):
content, tree = _roundtrip(input_tree, **kwargs)
assert b"tuple" not in content
assert isinstance(tree["val"], list)
return content, tree
def test_python_tuple():

@@ -130,5 +121,8 @@ """

run_tuple_test(input_tree)
content, tree = _roundtrip(input_tree)
assert b"tuple" not in content
assert isinstance(tree["val"], list)
@contextlib.contextmanager

@@ -149,71 +143,2 @@ def multi_warn(category, matches):

def test_named_tuple_collections():
"""
Ensure that we are able to serialize a collections.namedtuple.
"""
nt = namedtuple("TestNamedTuple1", ("one", "two", "three"))
input_tree = {"val": nt(1, 2, 3)}
with multi_warn(AsdfDeprecationWarning, ["ignore_implicit_conversion", "implicit conversion is deprecated"]):
run_tuple_test(input_tree, init_kwargs={"ignore_implicit_conversion": True})
def test_named_tuple_typing():
"""
Ensure that we are able to serialize a typing.NamedTuple.
"""
class NT(NamedTuple):
one: int
two: int
three: int
input_tree = {"val": NT(1, 2, 3)}
with multi_warn(AsdfDeprecationWarning, ["ignore_implicit_conversion", "implicit conversion is deprecated"]):
run_tuple_test(input_tree, init_kwargs={"ignore_implicit_conversion": True})
def test_named_tuple_collections_recursive():
nt = namedtuple("TestNamedTuple3", ("one", "two", "three"))
input_tree = {"val": nt(1, 2, np.ones(3))}
with multi_warn(AsdfDeprecationWarning, ["ignore_implicit_conversion", "implicit conversion is deprecated"]):
_, tree = run_tuple_test(input_tree, init_kwargs={"ignore_implicit_conversion": True})
assert (tree["val"][2] == np.ones(3)).all()
def test_named_tuple_typing_recursive(tmp_path):
class NT(NamedTuple):
one: int
two: int
three: np.ndarray
input_tree = {"val": NT(1, 2, np.ones(3))}
with multi_warn(AsdfDeprecationWarning, ["ignore_implicit_conversion", "implicit conversion is deprecated"]):
_, tree = run_tuple_test(input_tree, init_kwargs={"ignore_implicit_conversion": True})
assert (tree["val"][2] == np.ones(3)).all()
def test_implicit_conversion_warning():
nt = namedtuple("TestTupleWarning", ("one", "two", "three"))
tree = {"val": nt(1, 2, np.ones(3))}
with (
pytest.warns(AsdfWarning, match=r"Failed to serialize instance"),
pytest.warns(AsdfDeprecationWarning, match=r"implicit conversion is deprecated"),
asdf.AsdfFile(tree),
):
pass
with multi_warn(AsdfDeprecationWarning, ["ignore_implicit_conversion", "implicit conversion is deprecated"]):
with asdf.AsdfFile(tree, ignore_implicit_conversion=True):
pass
@pytest.mark.xfail(reason="pyyaml has a bug and does not support tuple keys")

@@ -352,8 +277,9 @@ def test_python_tuple_key():

af["a"] = MyNDArray([1, 2, 3])
with pytest.warns(AsdfConversionWarning, match=r"A ndarray subclass .*"):
with pytest.raises(AsdfSerializationError, match=r".*is not serializable by asdf.*"):
af.write_to(fn)
with asdf.config.config_context() as cfg:
cfg.convert_unknown_ndarray_subclasses = False
with pytest.raises(AsdfSerializationError, match=r".*is not serializable by asdf.*"):
with pytest.warns(AsdfDeprecationWarning, match=r"convert_unknown_ndarray_subclasses"):
cfg.convert_unknown_ndarray_subclasses = True
with pytest.warns(AsdfConversionWarning, match=r"A ndarray subclass .*"):
af.write_to(fn)

@@ -360,0 +286,0 @@

@@ -15,3 +15,3 @@ # file generated by setuptools_scm

__version__ = version = '3.5.0'
__version_tuple__ = version_tuple = (3, 5, 0)
__version__ = version = '4.0.0'
__version_tuple__ = version_tuple = (4, 0, 0)

@@ -9,2 +9,3 @@ """

import threading
import warnings
from contextlib import contextmanager

@@ -14,2 +15,3 @@

from ._helpers import validate_version
from .exceptions import AsdfDeprecationWarning
from .extension import ExtensionProxy

@@ -30,3 +32,3 @@ from .resource import ResourceManager, ResourceMappingProxy

DEFAULT_DEFAULT_ARRAY_SAVE_BASE = True
DEFAULT_CONVERT_UNKNOWN_NDARRAY_SUBCLASSES = True
DEFAULT_CONVERT_UNKNOWN_NDARRAY_SUBCLASSES = False
DEFAULT_LAZY_TREE = False

@@ -464,2 +466,9 @@

def convert_unknown_ndarray_subclasses(self, value):
if value:
msg = (
"Enabling convert_unknown_ndarray_subclasses is deprecated. "
"Please add a Converter or install an extension that supports "
"the ndarray subclass you'd like to convert"
)
warnings.warn(msg, AsdfDeprecationWarning)
self._convert_unknown_ndarray_subclasses = value

@@ -466,0 +475,0 @@

@@ -7,5 +7,3 @@ """

import abc
import warnings
from asdf.exceptions import AsdfWarning
from asdf.util import get_class_name, uri_match

@@ -32,3 +30,3 @@

one of the tag patterns listed in the 'tags' property.
ctx : asdf.asdf.SerializationContext
ctx : asdf.extension.SerializationContext
Context of the current serialization request.

@@ -184,19 +182,4 @@

if len(relevant_tags) > 1 and not hasattr(delegate, "select_tag"):
# we cannot use isinstance here because Converter supports
# virtual subclasses
if Converter in delegate.__class__.__mro__:
# prior to asdf 3.0 Converter provided a default select_tag
# to provide backwards compatibility allow Converter subclasses
# to be registered with >1 tag but produce a warning
msg = (
"Converter handles multiple tags for this extension, "
"but does not implement a select_tag method. "
"This previously worked because Converter subclasses inherited "
"the now removed select_tag. This will be an error in a future "
"version of asdf"
)
warnings.warn(msg, AsdfWarning)
else:
msg = "Converter handles multiple tags for this extension, but does not implement a select_tag method."
raise RuntimeError(msg)
msg = "Converter handles multiple tags for this extension, but does not implement a select_tag method."
raise RuntimeError(msg)

@@ -203,0 +186,0 @@ self._tags = sorted(relevant_tags)

@@ -7,3 +7,2 @@ """

import warnings
import weakref

@@ -16,3 +15,2 @@ from collections.abc import Sequence

from . import generic_io, treeutil, util
from .exceptions import AsdfDeprecationWarning
from .util import _patched_urllib_parse

@@ -110,3 +108,3 @@

def find_references(tree, ctx, _warning_msg=False):
def find_references(tree, ctx):
"""

@@ -119,8 +117,6 @@ Find all of the JSON references in the tree, and convert them into

if isinstance(tree, dict) and "$ref" in tree:
if _warning_msg:
warnings.warn(_warning_msg, AsdfDeprecationWarning)
return Reference(tree["$ref"], asdffile=ctx)
return tree
return treeutil.walk_and_modify(tree, do_find, ignore_implicit_conversion=ctx._ignore_implicit_conversion)
return treeutil.walk_and_modify(tree, do_find)

@@ -141,3 +137,3 @@

return treeutil.walk_and_modify(tree, do_resolve, ignore_implicit_conversion=ctx._ignore_implicit_conversion)
return treeutil.walk_and_modify(tree, do_resolve)

@@ -144,0 +140,0 @@

@@ -19,3 +19,3 @@ import copy

from .config import get_config
from .exceptions import AsdfDeprecationWarning, AsdfWarning
from .exceptions import AsdfWarning
from .util import _patched_urllib_parse

@@ -53,10 +53,4 @@

def _tag_to_uri(input_str):
if not input_str.startswith(constants.STSCI_SCHEMA_TAG_BASE):
return input_str
warnings.warn(
"Resolving by tag is deprecated. Use uris instead of tags",
AsdfDeprecationWarning,
)
return f"http://stsci.edu/schemas/asdf{input_str[len(constants.STSCI_SCHEMA_TAG_BASE):]}"
def _default_resolver(uri):
return uri

@@ -244,3 +238,3 @@

def _create_validator(validators=YAML_VALIDATORS, visit_repeat_nodes=False):
meta_schema = _load_schema_cached(YAML_SCHEMA_METASCHEMA_ID, _tag_to_uri, False)
meta_schema = _load_schema_cached(YAML_SCHEMA_METASCHEMA_ID, None, False)

@@ -345,5 +339,2 @@ type_checker = mvalidators.Draft4Validator.TYPE_CHECKER.redefine_many(

def _make_schema_loader(resolver):
if resolver is None:
resolver = _tag_to_uri
def load_schema(url):

@@ -422,5 +413,2 @@ # Check if this is a URI provided by the new

"""
if resolver is None:
resolver = _tag_to_uri
# We want to cache the work that went into constructing the schema, but returning

@@ -473,3 +461,3 @@ # the same object is treacherous, because users who mutate the result will not

if resolver is None:
resolver = _tag_to_uri
resolver = _default_resolver
loader = _make_schema_loader(resolver)

@@ -744,5 +732,5 @@ schema, url = loader(url)

meta_schema_id = schema.get("$schema", YAML_SCHEMA_METASCHEMA_ID)
meta_schema = _load_schema_cached(meta_schema_id, _tag_to_uri, False)
meta_schema = _load_schema_cached(meta_schema_id, None, False)
resolver = _make_jsonschema_refresolver(_tag_to_uri)
resolver = _make_jsonschema_refresolver(_default_resolver)

@@ -749,0 +737,0 @@ cls = mvalidators.create(

@@ -5,27 +5,7 @@ """

import warnings
from io import BytesIO
import asdf
from asdf.exceptions import AsdfDeprecationWarning
from asdf.versioning import AsdfSpec
def format_tag(organization, standard, version, tag_name):
"""
Format a YAML tag.
"""
warnings.warn("format_tag is deprecated", AsdfDeprecationWarning)
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):

@@ -32,0 +12,0 @@ """

@@ -6,8 +6,5 @@ """

import types
import warnings
from contextlib import contextmanager
from . import lazy_nodes, tagged
from .exceptions import AsdfDeprecationWarning, AsdfWarning
from .util import NotSet

@@ -225,3 +222,3 @@ __all__ = ["walk", "iter_tree", "walk_and_modify", "get_children", "is_container", "PendingValue", "RemoveNode"]

def walk_and_modify(top, callback, ignore_implicit_conversion=NotSet, postorder=True, _context=None):
def walk_and_modify(top, callback, postorder=True, _context=None):
"""Modify a tree by walking it with a callback function. It also has

@@ -258,10 +255,2 @@ the effect of doing a deep copy.

ignore_implicit_conversion : bool
DEPRECATED
Controls whether warnings should be issued when implicitly converting a
given type instance in the tree into a serializable object. The primary
case for this is currently ``namedtuple``.
Defaults to `False`.
Returns

@@ -273,6 +262,2 @@ -------

"""
if ignore_implicit_conversion is NotSet:
ignore_implicit_conversion = False
else:
warnings.warn("ignore_implicit_conversion is deprecated", AsdfDeprecationWarning)
callback_arity = callback.__code__.co_argcount

@@ -367,14 +352,5 @@ if callback_arity < 1 or callback_arity > 2:

try:
result = node.__class__(contents)
if isinstance(node, tagged.Tagged):
result._tag = node._tag
except TypeError:
# The derived class signature is different, so simply store the
# list representing the contents. Currently this is primarily
# intended to handle namedtuple and NamedTuple instances.
if not ignore_implicit_conversion:
warnings.warn(f"Failed to serialize instance of {type(node)}, converting to list instead", AsdfWarning)
result = contents
warnings.warn("implicit conversion is deprecated. Please instead use a Converter.", AsdfDeprecationWarning)
result = node.__class__(contents)
if isinstance(node, tagged.Tagged):
result._tag = node._tag

@@ -386,3 +362,5 @@ return result

result = _handle_mapping(node, json_id)
elif isinstance(node, tuple):
# don't treat namedtuple instances as tuples
# see: https://github.com/python/cpython/issues/52044
elif isinstance(node, tuple) and not hasattr(node, "_fields"):
result = _handle_immutable_sequence(node, json_id)

@@ -389,0 +367,0 @@ elif isinstance(node, (list, lazy_nodes.AsdfListNode)):

@@ -8,13 +8,8 @@ import enum

import sys
import types
import warnings
from functools import lru_cache
from importlib import metadata
from urllib.request import pathname2url
import numpy as np
import yaml
from packaging.version import Version
from . import constants, exceptions
from . import constants

@@ -27,5 +22,5 @@ # The standard library importlib.metadata returns duplicate entrypoints

if sys.version_info >= (3, 12):
from importlib.metadata import packages_distributions
pass
else:
from importlib_metadata import packages_distributions
pass

@@ -51,11 +46,6 @@

"load_yaml",
"human_list",
"get_array_base",
"get_base_uri",
"filepath_to_url",
"iter_subclasses",
"calculate_padding",
"resolve_name",
"NotSet",
"is_primitive",
"uri_match",

@@ -112,31 +102,2 @@ "get_class_name",

def human_list(line, separator="and"):
"""
Formats a list for human readability.
Parameters
----------
l : sequence
A sequence of strings
separator : string, optional
The word to use between the last two entries. Default:
``"and"``.
Returns
-------
formatted_list : string
Examples
--------
>>> human_list(["vanilla", "strawberry", "chocolate"], "or") # doctest: +SKIP
'vanilla, strawberry or chocolate'
"""
warnings.warn("asdf.util.human_list is deprecated", exceptions.AsdfDeprecationWarning)
if len(line) == 1:
return line[0]
return ", ".join(line[:-1]) + " " + separator + " " + line[-1]
def get_array_base(arr):

@@ -163,11 +124,2 @@ """

def filepath_to_url(path):
"""
For a given local file path, return a file:// url.
"""
msg = "asdf.util.filepath_to_url is deprecated. Please use pathlib.Path.as_uri"
warnings.warn(msg, exceptions.AsdfDeprecationWarning)
return _patched_urllib_parse.urljoin("file:", pathname2url(path))
def _iter_subclasses(cls):

@@ -182,10 +134,2 @@ """

def iter_subclasses(cls):
"""
Returns all subclasses of a class.
"""
warnings.warn("asdf.util.iter_subclasses is deprecated", exceptions.AsdfDeprecationWarning)
yield from _iter_subclasses(cls)
def calculate_padding(content_size, pad_blocks, block_size):

@@ -322,68 +266,2 @@ """

def resolve_name(name):
"""Resolve a name like ``module.object`` to an object and return it.
This ends up working like ``from module import object`` but is easier
to deal with than the `__import__` builtin and supports digging into
submodules.
Parameters
----------
name : `str`
A dotted path to a Python object--that is, the name of a function,
class, or other object in a module with the full path to that module,
including parent modules, separated by dots. Also known as the fully
qualified name of the object.
Examples
--------
>>> resolve_name('asdf.util.resolve_name') # doctest: +SKIP
<function resolve_name at 0x...>
Raises
------
`ImportError`
If the module or named object is not found.
"""
warnings.warn(
"asdf.util.resolve_name is deprecated, see astropy.utils.resolve_name", exceptions.AsdfDeprecationWarning
)
# Note: On python 2 these must be str objects and not unicode
parts = [str(part) for part in name.split(".")]
if len(parts) == 1:
# No dots in the name--just a straight up module import
cursor = 1
attr_name = "" # Must not be unicode on Python 2
else:
cursor = len(parts) - 1
attr_name = parts[-1]
module_name = parts[:cursor]
while cursor > 0:
try:
ret = __import__(str(".".join(module_name)), fromlist=[attr_name])
break
except ImportError:
if cursor == 0:
raise
cursor -= 1
module_name = parts[:cursor]
attr_name = parts[cursor]
ret = ""
for part in parts[cursor:]:
try:
ret = getattr(ret, part)
except AttributeError as err:
raise ImportError(name) from err
return ret
def get_class_name(obj, instance=True):

@@ -406,61 +284,2 @@ """

def minversion(module, version, inclusive=True):
"""
Returns `True` if the specified Python module satisfies a minimum version
requirement, and `False` if not.
Copied from astropy.utils.misc.minversion to avoid dependency on astropy.
Parameters
----------
module : module or `str`
An imported module of which to check the version, or the name of
that module (in which case an import of that module is attempted--
if this fails `False` is returned).
version : `str`
The version as a string that this module must have at a minimum (e.g.
``'0.12'``).
inclusive : `bool`
The specified version meets the requirement inclusively (i.e. ``>=``)
as opposed to strictly greater than (default: `True`).
"""
warnings.warn("asdf.util.minversion is deprecated, see astropy.utils.minversion", exceptions.AsdfDeprecationWarning)
if isinstance(module, types.ModuleType):
module_name = module.__name__
module_version = getattr(module, "__version__", None)
elif isinstance(module, str):
module_name = module
module_version = None
try:
with warnings.catch_warnings():
warnings.filterwarnings("ignore", "asdf.util.resolve_name", exceptions.AsdfDeprecationWarning)
module = resolve_name(module_name)
except ImportError:
return False
else:
msg = f"module argument must be an actual imported module, or the import name of the module; got {module!r}"
raise ValueError(msg)
if module_version is None:
try:
module_version = metadata.version(module_name)
except metadata.PackageNotFoundError:
# Maybe the distribution name is different from package name.
# Calling packages_distributions is costly so we do it only
# if necessary, as only a few packages don't have the same
# distribution name.
dist_names = packages_distributions()
module_version = metadata.version(dist_names[module_name][0])
if inclusive:
return Version(module_version) >= Version(version)
return Version(module_version) > Version(version)
class _InheritDocstrings(type):

@@ -519,20 +338,2 @@ """

def is_primitive(value):
"""
Determine if a value is an instance of a "primitive" type.
Parameters
----------
value : object
the value to test
Returns
-------
bool
True if the value is primitive, False otherwise
"""
warnings.warn("asdf.util.is_primitive is deprecated", exceptions.AsdfDeprecationWarning)
return isinstance(value, (bool, int, float, complex, str)) or value is None
def uri_match(pattern, uri):

@@ -539,0 +340,0 @@ """

@@ -6,3 +6,2 @@ """

import warnings
from functools import total_ordering

@@ -13,8 +12,6 @@

from .exceptions import AsdfDeprecationWarning
_yaml_base_loader = yaml.CSafeLoader if getattr(yaml, "__with_libyaml__", None) else yaml.SafeLoader
__all__ = ["AsdfVersion", "AsdfSpec", "AsdfVersionMixin", "split_tag_version", "join_tag_version"]
__all__ = ["AsdfVersion", "AsdfVersionMixin", "split_tag_version", "join_tag_version"]

@@ -38,30 +35,2 @@

_version_map = {}
def _get_version_map(version):
version_map = _version_map.get(version)
if version_map is None:
from .config import get_config
uri = f"http://stsci.edu/schemas/asdf/version_map-{version}"
# The following call to yaml.load is safe because we're
# using a loader that inherits from pyyaml's SafeLoader.
version_map = yaml.load(get_config().resource_manager[uri], Loader=_yaml_base_loader) # noqa: S506
# Separate the core tags from the rest of the standard for convenience
version_map["core"] = {}
version_map["standard"] = {}
for tag_name, tag_version in version_map["tags"].items():
if tag_name.startswith("tag:stsci.edu:asdf/core"):
version_map["core"][tag_name] = tag_version
else:
version_map["standard"][tag_name] = tag_version
_version_map[version] = version_map
return version_map
@total_ordering

@@ -120,39 +89,2 @@ class AsdfVersionMixin:

class AsdfSpec(SimpleSpec):
"""
Deprecated.
"""
def __init__(self, *args, **kwargs):
warnings.warn("AsdfSpec is deprecated.", AsdfDeprecationWarning)
super().__init__(*args, **kwargs)
def match(self, version):
if isinstance(version, (str, tuple, list)):
version = AsdfVersion(version)
return super().match(version)
def __iterate_versions(self, versions):
for v in versions:
yield AsdfVersion(v) if isinstance(v, (str, tuple, list)) else v
def select(self, versions):
return super().select(self.__iterate_versions(versions))
def filter(self, versions):
return super().filter(self.__iterate_versions(versions))
def __eq__(self, other):
"""Equality between Spec and Version, string, or tuple, means match"""
if isinstance(other, SimpleSpec):
return super().__eq__(other)
return self.match(other)
def __ne__(self, other):
return not self.__eq__(other)
def __hash__(self):
return super().__hash__()
supported_versions = [

@@ -169,7 +101,7 @@ AsdfVersion("1.0.0"),

default_version = AsdfVersion("1.5.0")
default_version = AsdfVersion("1.6.0")
# This is the ASDF Standard version that is currently in development
# it is possible that breaking changes will be made to this version.
asdf_standard_development_version = AsdfVersion("1.6.0")
asdf_standard_development_version = AsdfVersion("1.7.0")

@@ -176,0 +108,0 @@

@@ -321,3 +321,2 @@ import warnings

_walker,
ignore_implicit_conversion=ctx._ignore_implicit_conversion,
# Walk the tree in preorder, so that extensions can return

@@ -366,3 +365,2 @@ # container nodes with unserialized children.

_walker,
ignore_implicit_conversion=ctx._ignore_implicit_conversion,
# Walk the tree in postorder, so that extensions receive

@@ -369,0 +367,0 @@ # container nodes with children already deserialized.

@@ -0,1 +1,33 @@

4.0.0 (2024-11-19)
==================
Feature
-------
- Switch default ASDF standard to 1.6.0. (`#1744
<https://github.com/asdf-format/asdf/pull/1744>`_)
- Raise RuntimeError if a Convert subclass supports multiple tags but doesn't
implement select_tag. (`#1853
<https://github.com/asdf-format/asdf/pull/1853>`_)
General
-------
- Set ``memmap=False`` to default for ``asdf.open`` and ``AsdfFile.__init__``.
(`#1801 <https://github.com/asdf-format/asdf/pull/1801>`_)
Removal
-------
- remove ``copy_arrays`` (replaced by ``memmap``) (`#1800
<https://github.com/asdf-format/asdf/pull/1800>`_)
- Remove deprecated API. See docs for full details. (`#1852
<https://github.com/asdf-format/asdf/pull/1852>`_)
- Switch default convert_unknown_ndarray_subclasses to False and issue
deprecation warning if it is enabled. (`#1858
<https://github.com/asdf-format/asdf/pull/1858>`_)
3.5.0 (2024-10-02)

@@ -2,0 +34,0 @@ ==================

@@ -43,4 +43,4 @@ .. currentmodule:: asdf.config

default_array_save_base: True
convert_unknown_ndarray_subclasses: True
default_version: 1.5.0
convert_unknown_ndarray_subclasses: False
default_version: 1.6.0
io_block_size: -1

@@ -70,4 +70,4 @@ legacy_fill_schema_defaults: True

default_array_save_base: True
convert_unknown_ndarray_subclasses: True
default_version: 1.5.0
convert_unknown_ndarray_subclasses: False
default_version: 1.6.0
io_block_size: -1

@@ -85,4 +85,4 @@ legacy_fill_schema_defaults: True

default_array_save_base: True
convert_unknown_ndarray_subclasses: True
default_version: 1.5.0
convert_unknown_ndarray_subclasses: False
default_version: 1.6.0
io_block_size: -1

@@ -178,7 +178,7 @@ legacy_fill_schema_defaults: True

of subclasses of ndarray but will issue a warning when an instance is
converted. In a future version of asdf this default will change
to ``False``, a deprecation warning will be issued and finally
the conversion of instances of subclasses will be removed.
converted. This currently defaults to ``False`` and issues
a deprecation warning if enabled. In a future version of asdf
this setting will be removed.
Defaults to ``True``.
Defaults to ``False``.

@@ -185,0 +185,0 @@ default_version

@@ -9,4 +9,131 @@ .. currentmodule:: asdf

.. _whats_new_3.0.0:
.. _whats_new_4.0.0:
4.0.0
=====
Hi! Asdf 4.0.0 is a new major version including:
- :ref:`removal of deprecated API <whats_new_4.0.0_removed>`
- :ref:`changes to a few key defaults <whats_new_4.0.0_defaults>`
.. _whats_new_4.0.0_removed:
Removed API
-----------
- The ``copy_arrays`` argument for ``asdf.open`` and ``AsdfFile`` has been removed
and replaced by ``memmap`` (``memmap == not copy_arrays``).
- ``ignore_version_mismatch`` has had no effect since asdf 3.0.0 and was removed.
- the `asdf.util` submodule had several unused functions removed:
- ``filepath_to_url``, see ``pathlib.Path.as_uri`` as an alternative
- ``is_primitive``, use ``isinstance``
- ``iter_subclasses``, use ``object.__subclasses__``
- ``minversion``, see ``astropy.utils.minversion``
- ``resolve_name``, see ``astropy.utils.resolve_name``
- ``human_list``, use ``pprint`` or your own string formatting
- ``versioning.AsdfSpec``, see `asdf.versioning.AsdfVersion` comparisons
- ``asdf.testing.helpers.format_tag``, use your own string formatting
- ``AsdfFile.version_map``, could have been removed with the legacy extension API
- ``AsdfFile.resolve_and_inline``, use `AsdfFile.resolve_references` and ``all_array_storage=="inline"``
- ``asdf.asdf``, the public items in this submodule are all in the top level `asdf` module
- ``asdf.asdf.SerializationContext``, available at `asdf.extension.SerializationContext`
- ``asdf.stream``, see `asdf.tags.core.Stream`
- ``ignore_implicit_conversion`` has been removed (see :ref:`whats_new_4.0.0_implicit_conversion` below)
- providing a tag uri within a schema ``$ref`` will no longer resolve to the schema uri associated with that tag
.. _whats_new_4.0.0_defaults:
New Defaults
------------
.. _whats_new_4.0.0_memmap:
Memory mapping disabled by default
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Calls to ``asdf.open() and ``AsdfFile()`` will now default to ``memmap=False``, disabling memory mapping of arrays by default.
.. _whats_new_4.0.0_standard:
ASDF standard version
^^^^^^^^^^^^^^^^^^^^^
By default asdf 4.0.0 will write files that use the 1.6.0 version of the
ASDF standard. This change should be transparent and all files
that use the older standards are readable. If you wish to write files
using the 1.5.0 (or older) ASDF standard you can provide a version
to `AsdfFile.write_to` or change `asdf.config.AsdfConfig.default_version`.
In addition to new schemas and tags ASDF standard 1.6.0 comes with
a few other changes (scheduled for this version).
- Opening files will no longer trigger `AsdfFile.fill_defaults`.
- Mapping keys are restricted to str, int, bool
See :external+asdf-standard:ref:`yaml_subset`
.. _whats_new_4.0.0_validation:
Validation
^^^^^^^^^^
Several operations no longer automatically trigger tree validation.
These changes were made to limit the number of times a tree is validated
to allow incremental construction of trees and to improve performance.
- providing a tree to ``AsdfFile.__init__`` no longer triggers validation
- calling `AsdfFile.resolve_references` no longer triggers validation
- assigning a new tree to `AsdfFile.tree` no longer triggers validation
.. note::
Validation can be triggered with `AsdfFile.validate` and will
occur when writing to a file (or reading if ``AsdfConfig.validate_on_read``
is enabled).
.. _whats_new_4.0.0_find_references:
Find References
^^^^^^^^^^^^^^^
Similar to :ref:`whats_new_4.0.0_validation` several operations no longer
automatically trigger `AsdfFile.find_references`:
- `asdf.open` does not trigger `AsdfFile.find_references`
- providing a tree (or `AsdfFile`) to ``AsdfFile.__init__`` no longer triggers `AsdfFile.find_references`
.. note::
`AsdfFile.find_references` is only for JSON pointer references
which are most useful for external references. YAML anchors and
aliases are automatically resolved.
.. _whats_new_4.0.0_implicit_conversion:
Implicit Conversion
^^^^^^^^^^^^^^^^^^^
In older asdf versions ``namedtuple`` instances were automatically
converted to lists when written to a file. When read back in the
``namedtuple`` was not reconstructed and instead these objects were
returned as lists. With asdf 4.0.0 this "implicit conversion" is
no longer performed which allows extensions to implement converters
for ``namedtuple`` instances.
.. _whats_new_4.0.0_unknown_ndarray_subclasses:
Unknown NDArray Subclasses
^^^^^^^^^^^^^^^^^^^^^^^^^^
In asdf 3.0.0 a config attribute was added
`asdf.config.AsdfConfig.convert_unknown_ndarray_subclasses` that
was enabled by default (to retain the behavior of the removed legacy
extension that handled ndarrays).
In asdf 4.0.0 this setting is disabled by default and issues a deprecation
warning when enabled. In an upcoming version of asdf this setting will
be removed.
See :ref:`convert_unknown_ndarray_subclasses` for more details.
3.0.0

@@ -32,3 +159,3 @@ =====

.. _whats_new_3.0.0__ew_features:
.. _whats_new_3.0.0__new_features:

@@ -35,0 +162,0 @@ New features

Metadata-Version: 2.1
Name: asdf
Version: 3.5.0
Version: 4.0.0
Summary: Python implementation of the ASDF Standard

@@ -261,7 +261,4 @@ Author-email: The ASDF Developers <help@stsci.edu>

.. warning::
The ``copy_arrays`` argument of `asdf.open()` and `AsdfFile` is deprecated,
and will be removed in ASDF 4.0. It is replaced by ``memmap``, which
is the opposite of ``copy_arrays`` (``memmap == not copy_arrays``).
In ASDF 4.0, ``memmap`` will default to ``False``, which means arrays
will no longer be memory-mapped by default.
The ``memmap`` argument replaces ``copy_arrays`` as of ASDF 4.0
(``memmap == not copy_arrays``).

@@ -268,0 +265,0 @@ To get a quick overview of the data stored in the file, use the top-level

import io
import os
import pathlib
import warnings
from dataclasses import dataclass

@@ -44,8 +43,2 @@

)
parser.addini(
"asdf_schema_ignore_version_mismatch",
"Set to true to disable warnings when missing explicit support for a tag",
type="string",
default="",
)
parser.addoption("--asdf-tests", action="store_true", help="Enable ASDF schema tests")

@@ -286,11 +279,3 @@

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 != "":
from asdf.exceptions import AsdfDeprecationWarning
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"))

@@ -297,0 +282,0 @@ xfail_tests = _parse_test_list(parent.config.getini("asdf_schema_xfail_tests"))

@@ -189,7 +189,4 @@ ASDF - Advanced Scientific Data Format

.. warning::
The ``copy_arrays`` argument of `asdf.open()` and `AsdfFile` is deprecated,
and will be removed in ASDF 4.0. It is replaced by ``memmap``, which
is the opposite of ``copy_arrays`` (``memmap == not copy_arrays``).
In ASDF 4.0, ``memmap`` will default to ``False``, which means arrays
will no longer be memory-mapped by default.
The ``memmap`` argument replaces ``copy_arrays`` as of ASDF 4.0
(``memmap == not copy_arrays``).

@@ -196,0 +193,0 @@ To get a quick overview of the data stored in the file, use the top-level

+23
-0

@@ -327,1 +327,24 @@ [tox]

-W "ignore::asdf.exceptions.AsdfManifestURIMismatchWarning"
[testenv:abacusutils]
change_dir = {env_tmp_dir}
allowlist_externals =
git
bash
extras =
commands_pre =
bash -c "pip freeze -q | grep 'asdf @' > {env_tmp_dir}/requirements.txt"
git clone https://github.com/abacusorg/abacusutils.git
pip install -vU setuptools wheel scipy Cython 'numpy<2' # for classy and corrfunc
pip install --no-build-isolation classy corrfunc
pip install -e abacusutils[test]
pip install -r {env_tmp_dir}/requirements.txt
# make an empty pytest.ini to prevent pytest from crawling up
# one directory and finding the pytest configuration for the asdf
# repo clone
bash -c "echo '' > pytest.ini"
pip freeze
commands =
# only running a subset of tests since only a portion of abacusutils
# relies on asdf
pytest abacusutils/tests/test_data.py
import warnings
from . import _asdf
from .exceptions import AsdfDeprecationWarning
warnings.warn(
"asdf.asdf is deprecated. Please use asdf.AsdfFile and asdf.open",
AsdfDeprecationWarning,
)
def __getattr__(name):
if hasattr(_asdf, name):
return getattr(_asdf, name)
warnings.warn(
"asdf.asdf is deprecated",
AsdfDeprecationWarning,
)
msg = f"module {__name__!r} has no attribute {name!r}"
raise AttributeError(msg)
import warnings
from .exceptions import AsdfDeprecationWarning
from .tags.core.stream import Stream # noqa: F401
warnings.warn(
"asdf.stream is deprecated. Please use asdf.tags.core.stream",
AsdfDeprecationWarning,
)

Sorry, the diff of this file is too big to display