Skip to content

Commit ac3fef1

Browse files
authored
Merge pull request #589 from spacetelescope/v2.1.x
Release candidate for v2.1.1
2 parents ade4b33 + 102f3e1 commit ac3fef1

19 files changed

Lines changed: 327 additions & 74 deletions

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ env:
2222
# overidden underneath. They are defined here in order to save having
2323
# to repeat them for all configurations.
2424
- PYTHON_VERSION=3.6
25-
- PYTEST_VERSION=3.6
25+
- PYTEST_VERSION=3.7
2626
- ASTROPY_VERSION=stable
2727
- NUMPY_VERSION=stable
2828
- PIP_DEPENDENCIES='pytest-faulthandler importlib_resources'
@@ -39,9 +39,10 @@ env:
3939
- PIP_DEPENDENCIES='collective.checkdocs pygments' SETUP_CMD='checkdocs'
4040
- PYTHON_VERSION=3.5 SETUP_CMD='test'
4141
- PYTHON_VERSION=3.6 SETUP_CMD='test'
42-
- PYTHON_VERSION=3.7 SETUP_CMD='test'
42+
- PYTHON_VERSION=3.7 PYTEST_VERSION=3.8 SETUP_CMD='test'
4343

4444
matrix:
45+
fast_finish: true
4546
include:
4647

4748
# Do a coverage test
@@ -62,6 +63,7 @@ matrix:
6263
# also test against development version of Astropy
6364
- env: MAIN_CMD='pytest' SETUP_CMD='' ASTROPY_VERSION=development
6465
GWCS_PIP="$GWCS_GIT"
66+
PYTEST_VERSION=3.8
6567

6668
# latest stable versions
6769
- env: NUMPY_VERSION=stable SETUP_CMD='test'

CHANGES.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
2.1.1 (2018-11-01)
2+
------------------
3+
4+
- Make sure extension metadata is written even when constructing the ASDF tree
5+
on-the-fly. [#549]
6+
7+
- Fix large integer validation when storing `numpy` integer literals in the
8+
tree. [#553]
9+
10+
- Fix bug that caused subclass of external type to be serialized by the wrong
11+
tag. [#560]
12+
13+
- Fix bug that occurred when attempting to open invalid file but Astropy import
14+
fails while checking for ASDF-in-FITS. [#562]
15+
16+
- Fix bug that caused tree creation to fail when unable to locate a schema file
17+
for an unknown tag. This now simply causes a warning, and the offending node
18+
is converted to basic Python data structures. [#571]
19+
120
2.1.0 (2018-09-25)
221
------------------
322

appveyor.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ environment:
55

66
global:
77
PYTHON: "C:\\conda"
8+
PYTEST_VERSION: "3.7"
89
MINICONDA_VERSION: "latest"
910
CMD_IN_ENV: "cmd /E:ON /V:ON /C .\\ci-helpers\\appveyor\\windows_sdk.cmd"
1011
SETUP_CMD: "test"
@@ -29,20 +30,22 @@ environment:
2930
NUMPY_VERSION: "1.12.0"
3031
platform: x64
3132

32-
- PYTHON_VERSION: "3.6"
33+
- PYTHON_VERSION: "3.7"
34+
PYTEST_VERSION: "3.7"
3335
platform: x64
3436

3537
- PYTHON_VERSION: "3.6"
3638
ASTROPY_VERSION: "stable"
3739
platform: x64
3840

39-
- PYTHON_VERSION: "3.6"
41+
- PYTHON_VERSION: "3.7"
42+
PYTEST_VERSION: "3.7"
4043
ASTROPY_VERSION: "development"
4144
GWCS_PIP: "%GWCS_GIT%"
4245
platform: x64
4346

4447
# Tests against development version of numpy may fail
45-
- PYTHON_VERSION: "3.6"
48+
- PYTHON_VERSION: "3.7"
4649
NUMPY_VERSION: "development"
4750
platform: x64
4851

asdf/asdf.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -677,10 +677,14 @@ def _open_impl(cls, self, fd, uri=None, mode='r',
677677
ignore_missing_extensions=ignore_missing_extensions,
678678
_extension_metadata=self._extension_metadata)
679679
except ValueError:
680-
pass
681-
raise ValueError(
682-
"Input object does not appear to be ASDF file or FITS with " +
683-
"ASDF extension")
680+
raise ValueError(
681+
"Input object does not appear to be an ASDF file or a FITS with " +
682+
"ASDF extension") from None
683+
except ImportError:
684+
raise ValueError(
685+
"Input object does not appear to be an ASDF file. Cannot check " +
686+
"if it is a FITS with ASDF extension because 'astropy' is not " +
687+
"installed") from None
684688
return cls._open_asdf(self, fd, uri=uri, mode=mode,
685689
validate_checksums=validate_checksums,
686690
do_not_fill_defaults=do_not_fill_defaults,
@@ -827,6 +831,7 @@ def _pre_write(self, fd, all_array_storage, all_array_compression,
827831
self._blocks.finalize(self)
828832

829833
self._tree['asdf_library'] = get_asdf_library_info()
834+
self._update_extension_history()
830835

831836
def _serial_write(self, fd, pad_blocks, include_block_index):
832837
self._write_tree(self._tree, fd, pad_blocks)
@@ -912,8 +917,6 @@ def update(self, all_array_storage=None, all_array_compression='input',
912917
write out in the latest version supported by asdf.
913918
"""
914919

915-
self._update_extension_history()
916-
917920
fd = self._fd
918921

919922
if fd is None:
@@ -922,7 +925,9 @@ def update(self, all_array_storage=None, all_array_compression='input',
922925

923926
if not fd.writable():
924927
raise IOError(
925-
"Can not update, since associated file is read-only")
928+
"Can not update, since associated file is read-only. Make "
929+
"sure that the AsdfFile was opened with mode='rw' and the "
930+
"underlying file handle is writable.")
926931

927932
if version is not None:
928933
self.version = version
@@ -1054,8 +1059,6 @@ def write_to(self, fd, all_array_storage=None, all_array_compression='input',
10541059
write out in the latest version supported by asdf.
10551060
"""
10561061

1057-
self._update_extension_history()
1058-
10591062
original_fd = self._fd
10601063

10611064
if version is not None:

asdf/asdftypes.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,11 @@ def add_subclasses(typ, asdftype):
126126
# hierarchy than the existing subclass.
127127
if subclass in self._class_by_subclass:
128128
if issubclass(self._class_by_subclass[subclass], typ):
129-
continue
129+
# Allow for cases where a subclass tag is being
130+
# overridden by a tag from another extension.
131+
if (self._extension_by_cls[subclass] ==
132+
index._extension_by_type[asdftype]):
133+
continue
130134
self._class_by_subclass[subclass] = typ
131135
self._type_by_subclasses[subclass] = asdftype
132136
self._extension_by_cls[subclass] = index._extension_by_type[asdftype]

asdf/conftest.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@
2121
TESTED_VERSIONS[packagename] = version.version
2222

2323

24-
pytest_plugins = [
25-
'asdf.tests.schema_tester'
26-
]
27-
28-
2924
try:
3025
PYTEST_HEADER_MODULES['Astropy'] = 'astropy'
3126
PYTEST_HEADER_MODULES['jsonschema'] = 'jsonschema'

asdf/extension.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,10 @@ def extension_list(self):
231231
def package_metadata(self):
232232
return self._package_metadata
233233

234+
def reset(self):
235+
"""This will be used primarily for testing purposes."""
236+
self._extensions = []
237+
self._extension_list = None
238+
self._package_metadata = {}
239+
234240
default_extensions = _DefaultExtensions()

asdf/schema.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
import os
55
import json
66
import datetime
7+
import warnings
8+
from numbers import Integral
79
from functools import lru_cache
810
from collections import OrderedDict
11+
from collections.abc import Mapping
912
from urllib import parse as urlparse
1013

1114
from jsonschema import validators as mvalidators
@@ -217,7 +220,12 @@ def iter_errors(self, instance, _schema=None, _seen=set()):
217220
if tag is not None:
218221
schema_path = self.ctx.resolver(tag)
219222
if schema_path != tag:
220-
s = load_schema(schema_path, self.ctx.resolver)
223+
try:
224+
s = load_schema(schema_path, self.ctx.resolver)
225+
except FileNotFoundError:
226+
msg = "Unable to locate schema file for '{}': '{}'"
227+
warnings.warn(msg.format(tag, schema_path))
228+
s = {}
221229
if s:
222230
with self.resolver.in_scope(schema_path):
223231
for x in super(ASDFValidator, self).iter_errors(instance, s):
@@ -312,7 +320,6 @@ def load_custom_schema(url):
312320
core = load_schema(AsdfObject.yaml_tag)
313321

314322
def update(d, u):
315-
from collections import Mapping
316323
for k, v in u.items():
317324
# Respect the property ordering of the core schema
318325
if k == 'propertyOrder' and k in d:
@@ -457,7 +464,7 @@ def validate_large_literals(instance):
457464
"""
458465
# We can count on 52 bits of precision
459466
for instance in treeutil.iter_tree(instance):
460-
if (isinstance(instance, int) and (
467+
if (isinstance(instance, (Integral)) and (
461468
instance > ((1 << 51) - 1) or
462469
instance < -((1 << 51) - 2))):
463470
raise ValidationError(

asdf/tags/core/tests/test_history.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,3 +286,12 @@ def types(self):
286286
pass
287287

288288
assert len(warnings) == 0
289+
290+
# Make sure that this works even when constructing the tree on-the-fly
291+
tmpfile3 = str(tmpdir.join('custom_extension2.asdf'))
292+
with asdf.AsdfFile(extensions=FractionExtension()) as ff:
293+
ff.tree['fraction'] = fractions.Fraction(4, 5)
294+
ff.write_to(tmpfile3)
295+
296+
with asdf.open(tmpfile3, extensions=FractionExtension()) as af:
297+
assert len(af['history']['extensions']) == 2

asdf/tests/__init__.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
This packages contains affiliated package tests.
44
"""
55

6+
import numpy as np
7+
68
from .. import CustomType
79

810

@@ -20,3 +22,27 @@ def from_tree_tagged(cls, tree, ctx):
2022
@classmethod
2123
def from_tree(cls, tree, ctx):
2224
return tree
25+
26+
27+
def create_small_tree():
28+
x = np.arange(0, 10, dtype=np.float)
29+
tree = {
30+
'science_data': x,
31+
'subset': x[3:-3],
32+
'skipping': x[::2],
33+
'not_shared': np.arange(10, 0, -1, dtype=np.uint8)
34+
}
35+
return tree
36+
37+
38+
def create_large_tree():
39+
# These are designed to be big enough so they don't fit in a
40+
# single block, but not so big that RAM/disk space for the tests
41+
# is enormous.
42+
x = np.random.rand(256, 256)
43+
y = np.random.rand(16, 16, 16)
44+
tree = {
45+
'science_data': x,
46+
'more': y
47+
}
48+
return tree

0 commit comments

Comments
 (0)