Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to directly access schema file to paths #1707

Open
WilliamJamieson opened this issue Dec 15, 2023 · 0 comments
Open

Add ability to directly access schema file to paths #1707

WilliamJamieson opened this issue Dec 15, 2023 · 0 comments

Comments

@WilliamJamieson
Copy link
Contributor

In order to automatically generate static Python code based on schemas (for Roman) I ideally would like the ability to directly access the path to a schema using its URI. Currently, most access patterns result in the loaded bytes object containing the file's data rather than just the file path. Note that it is possible for me to work with the bytes, but it requires a lot of hacks deep into the code generator. Instead, if I provide a function that returns a file path given a URI then the generator can simply use its own read and parse functionality to read the schema.

Note that, I can do this for the Rad schemas to get say the aperture-1.0.0 schema using:

from asdf.config import get_config

schema_uri = "asdf://stsci.edu/datamodels/roman/schemas/aperture-1.0.0"

manager = get_config().resource_manager

schema_file_path = manager._mappings_by_uri[schema_uri]._delegate._uri_to_file[schema_uri]

This makes use of several private ASDF APIs. The reason I cannot use the public API is that the DirectoryResourceMapping.__getitem__ object used to register the Rad schemas with ASDF calls .read_bytes() on the path objects in the _uri_to_file dictionary.

Something like a .get_file_path_for_uri(uri) method on the resource manager would be idea for what I need. I may also require a .has_file_path_for_uri(uri) as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant