From 0a22f7dfc1e145ed4830690696622ea94255c91c Mon Sep 17 00:00:00 2001 From: Daniel D'Avella Date: Fri, 9 Nov 2018 16:12:48 -0500 Subject: [PATCH 1/4] Make sure core tags are added to type index first --- CHANGES.rst | 7 +++++++ asdf/asdftypes.py | 12 +++++++++--- asdf/tests/test_asdftypes.py | 9 ++++++++- asdf/versioning.py | 12 +++++++++++- 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index fa91bc516..cd56a9f67 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,10 @@ +2.1.2 (unreleased) +------------------ + +- Make sure that all types corresponding to core tags are added to the type + index before any others. This fixes a bug that was related to the way that + subclass tags were overwritten by external extensions. [#598] + 2.1.1 (2018-11-01) ------------------ diff --git a/asdf/asdftypes.py b/asdf/asdftypes.py index 984a5ce0f..2b9c51297 100644 --- a/asdf/asdftypes.py +++ b/asdf/asdftypes.py @@ -95,7 +95,9 @@ def __init__(self, version, index): self._extensions_used = set() try: - version_map = get_version_map(self._version)['tags'] + version_map = get_version_map(self._version) + core_version_map = version_map['core'] + standard_version_map = version_map['standard'] except ValueError: raise ValueError( "Don't know how to write out ASDF version {0}".format( @@ -152,8 +154,12 @@ def add_by_tag(name, version): self._type_by_name[name] = asdftype add_all_types(asdftype) - # Process all types defined in the ASDF version map - for name, _version in version_map.items(): + # Process all types defined in the ASDF version map. It is important to + # make sure that tags that are associated with the core part of the + # standard are processed first in order to handle subclasses properly. + for name, _version in core_version_map.items(): + add_by_tag(name, AsdfVersion(_version)) + for name, _version in standard_version_map.items(): add_by_tag(name, AsdfVersion(_version)) # Now add any extension types that aren't known to the ASDF standard. diff --git a/asdf/tests/test_asdftypes.py b/asdf/tests/test_asdftypes.py index 5dd3ba302..f40485d24 100644 --- a/asdf/tests/test_asdftypes.py +++ b/asdf/tests/test_asdftypes.py @@ -5,6 +5,7 @@ import io import os import sys + import pytest import asdf @@ -219,7 +220,13 @@ def test_versioned_writing(monkeypatch): 'tags': { 'tag:stsci.edu:asdf/core/complex': '42.0.0', 'tag:stscu.edu:asdf/core/asdf': '1.0.0' - } + }, + # We need to insert these explicitly since we're monkeypatching + 'core': { + 'tag:stsci.edu:asdf/core/complex': '42.0.0', + 'tag:stscu.edu:asdf/core/asdf': '1.0.0' + }, + 'standard': {} }) # Add bogus version to supported versions diff --git a/asdf/versioning.py b/asdf/versioning.py index 00a92997e..312e6ac1b 100644 --- a/asdf/versioning.py +++ b/asdf/versioning.py @@ -5,9 +5,9 @@ This module deals with things that change between different versions of the ASDF spec. """ +from functools import total_ordering import yaml -from functools import total_ordering if getattr(yaml, '__with_libyaml__', None): # pragma: no cover _yaml_base_loader = yaml.CSafeLoader @@ -39,6 +39,16 @@ def get_version_map(version): except Exception: raise ValueError( "Could not load version map for version {0}".format(version)) + + # Separate the core tags from the rest of the standard for convenience + version_map['core'] = {} + version_map['standard'] = {} + for name, version in version_map['tags'].items(): + if name.startswith('tag:stsci.edu:asdf/core'): + version_map['core'][name] = version + else: + version_map['standard'][name] = version + _version_map[version] = version_map return version_map From 7d090498a9fcd4f9fa2bd430092fb9d26ed18af4 Mon Sep 17 00:00:00 2001 From: Daniel D'Avella Date: Mon, 5 Nov 2018 09:50:31 -0500 Subject: [PATCH 2/4] Add config option to schema tester to skip examples --- asdf/tests/schema_tester.py | 19 ++++++++++++++++--- setup.cfg | 1 + 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/asdf/tests/schema_tester.py b/asdf/tests/schema_tester.py index 514ce576f..2bd6c6257 100644 --- a/asdf/tests/schema_tester.py +++ b/asdf/tests/schema_tester.py @@ -62,13 +62,22 @@ def pytest_addoption(parser): "asdf_schema_root", "Root path indicating where schemas are stored") parser.addini( "asdf_schema_skip_names", "Base names of files to skip in schema tests") + parser.addini( + "asdf_schema_skip_examples", + "Base names of schemas whose examples should not be tested") class AsdfSchemaFile(pytest.File): + + def __init__(self, *args, skip_examples=False, **kwargs): + super().__init__(*args, **kwargs) + self.skip_examples = skip_examples + def collect(self): yield AsdfSchemaItem(str(self.fspath), self) - for example in self.find_examples_in_schema(): - yield AsdfSchemaExampleItem(str(self.fspath), self, example) + if not self.skip_examples: + for example in self.find_examples_in_schema(): + yield AsdfSchemaExampleItem(str(self.fspath), self, example) def find_examples_in_schema(self): """Returns generator for all examples in schema at given path""" @@ -186,6 +195,7 @@ def pytest_collect_file(path, parent): return skip_names = parent.config.getini('asdf_schema_skip_names') + skip_examples = parent.config.getini('asdf_schema_skip_examples') schema_roots = [os.path.join(str(parent.config.rootdir), root) for root in schema_roots] @@ -195,6 +205,9 @@ def pytest_collect_file(path, parent): for root in schema_roots: if str(path).startswith(root) and path.purebasename not in skip_names: - return AsdfSchemaFile(path, parent) + skip = path.purebasename in skip_examples + return AsdfSchemaFile( + path, parent, + skip_examples=(path.purebasename in skip_examples)) return None diff --git a/setup.cfg b/setup.cfg index ffb20ad43..f26212bbc 100644 --- a/setup.cfg +++ b/setup.cfg @@ -17,6 +17,7 @@ open_files_ignore = test.fits asdf.fits # Account for both the astropy test runner case and the native pytest case asdf_schema_root = asdf-standard/schemas asdf/schemas asdf_schema_skip_names = asdf-schema-1.0.0 draft-01 +asdf_schema_skip_examples = domain-1.0.0 #addopts = --doctest-rst [ah_bootstrap] From 6a7f5665b5eeb93983c87a4b755b2fbacae2cc2a Mon Sep 17 00:00:00 2001 From: Daniel D'Avella Date: Tue, 13 Nov 2018 12:19:33 -0500 Subject: [PATCH 3/4] Update version in setup.py to reflect 2.1.2 release --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index d2ee2ad70..0282f57bb 100755 --- a/setup.py +++ b/setup.py @@ -31,7 +31,7 @@ builtins._PACKAGE_NAME_ = PACKAGE_NAME # VERSION should be PEP386 compatible (http://www.python.org/dev/peps/pep-0386) -VERSION = '2.1.1' +VERSION = '2.1.2' # Indicates if this version is a release version RELEASE = 'dev' not in VERSION From 8000459c787c8f2e9f905b08953a5387776f125c Mon Sep 17 00:00:00 2001 From: Daniel D'Avella Date: Tue, 13 Nov 2018 12:19:57 -0500 Subject: [PATCH 4/4] Update change log to reflect v2.1.2 release --- CHANGES.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index cd56a9f67..d14f873f3 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,4 +1,4 @@ -2.1.2 (unreleased) +2.1.2 (2018-11-13) ------------------ - Make sure that all types corresponding to core tags are added to the type