Skip to content

Commit

Permalink
replace legacy asdf extension with resource_mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
braingram committed Mar 6, 2023
1 parent 67e8071 commit a92a6ab
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 24 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ test = [
'tracker' = 'https://github.com/spacetelescope/stpipe/issues'

[project.entry-points]
asdf_extensions = { stpipe = 'stpipe.integration:StpipeExtension' }
'asdf.resource_mappings' = {stpipe = 'stpipe.integration:get_resource_mappings'}

[project.scripts]
stpipe = 'stpipe.cli.main:main'
Expand Down
2 changes: 1 addition & 1 deletion src/stpipe/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,6 @@ def _validate_asdf(asdf_file, schema_uri):
asdf.ValidationError
"""
# TODO: We should add a method on AsdfFile to facilitate this:
schema = asdf.schema.load_schema(schema_uri, asdf_file.resolver)
schema = asdf.schema.load_schema(schema_uri)
tagged_tree = asdf.yamlutil.custom_tree_to_tagged_tree(asdf_file.tree, asdf_file)
asdf.schema.validate(tagged_tree, asdf_file, schema)
27 changes: 5 additions & 22 deletions src/stpipe/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,15 @@
"""
import os

from asdf.extension import AsdfExtension
from asdf import util
from asdf.resource import DirectoryResourceMapping


SCHEMAS_PATH = os.path.abspath(
os.path.join(os.path.dirname(__file__), "resources", "schemas")
)


class StpipeExtension(AsdfExtension):
"""
ASDF extension providing access to the stpipe schemas. This
class is registered with the asdf_extensions entry point.
"""
@property
def types(self):
# Required by the ABC but unused here
return []

@property
def tag_mapping(self):
# Required by the ABC but unused here
return []

@property
def url_mapping(self):
return [
("http://stsci.edu/schemas/stpipe", util.filepath_to_url(SCHEMAS_PATH) + "/{url_suffix}.yaml"),
]
def get_resource_mappings():
return [
DirectoryResourceMapping(SCHEMAS_PATH, "http://stsci.edu/schemas/stpipe/", recursive=True),
]

0 comments on commit a92a6ab

Please sign in to comment.