| 1 |
import sys |
| 2 |
from pathlib import Path |
| 3 |
|
| 4 |
from asdf_standard import DirectoryResourceMapping |
| 5 |
|
| 6 |
if sys.version_info < (3, 9): |
| 7 |
import importlib_resources |
| 8 |
else: |
| 9 |
import importlib.resources as importlib_resources |
| 10 |
|
| 11 |
import asdf_wcs_schemas |
| 12 |
|
| 13 |
|
| 14 |
def get_resource_mappings(): |
| 15 |
""" |
| 16 |
Get the resource mapping instances for the datamodel schemas |
| 17 |
and manifests. This method is registered with the |
| 18 |
asdf.resource_mappings entry point. |
| 19 |
|
| 20 |
Returns |
| 21 |
------- |
| 22 |
list of collections.abc.Mapping |
| 23 |
""" |
| 24 |
resources_root = importlib_resources.files(asdf_wcs_schemas) / "resources" |
| 25 |
if not resources_root.is_dir(): |
| 26 |
# In an editable install, the resources directory will exist off the |
| 27 |
# repository root: |
| 28 |
resources_root = Path(__file__).parent.parent.parent / "resources" |
| 29 |
if not resources_root.is_dir(): |
| 30 |
raise RuntimeError("Missing resources directory") |
| 31 |
|
| 32 |
return [ |
| 33 |
DirectoryResourceMapping( |
| 34 |
resources_root / "schemas" / "stsci.edu" / "gwcs", |
| 35 |
"http://stsci.edu/schemas/gwcs/", |
| 36 |
), |
| 37 |
DirectoryResourceMapping( |
| 38 |
resources_root / "manifests", |
| 39 |
"asdf://asdf-format.org/astronomy/gwcs/manifests/", |
| 40 |
), |
| 41 |
] |