Skip to content

Commit

Permalink
Merge pull request #82 from braingram/asdf_extension
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamJamieson committed Mar 13, 2023
2 parents e78c74f + 676cd07 commit 809607c
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- add ``importlib.metadata`` as a dependency and update loading of entry_points to drop
usage of pkg_resources [#84]
- update minimum python to 3.8 and ASDF version to 2.8 [#87]
- replace legacy AsdfExtension with resource_mapping [#82]

0.4.5 (2022-12-23)
==================
Expand Down
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),
]
2 changes: 1 addition & 1 deletion tests/test_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class LoggingPipeline(Pipeline):
"""

def process(self):
self.log.warning(f"This step has called out a warning.")
self.log.warning("This step has called out a warning.")

self.log.warning(f"{self.log} {self.log.handlers}")
return
Expand Down

0 comments on commit 809607c

Please sign in to comment.