-
Notifications
You must be signed in to change notification settings - Fork 57
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
Support asdf:// URI scheme #854
Support asdf:// URI scheme #854
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Just a couple questions for my own understanding.
""" | ||
assert generic_io.resolve_uri( | ||
'{}://somewhere.org/some-schema'.format(protocol), '#/definitions/foo' | ||
) == '{}://somewhere.org/some-schema#/definitions/foo'.format(protocol) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use f-strings here and bump the minimum version of python to 3.6 for our 2.8 release?
I don't see a good reason to keep supporting python 3.5 when it is no longer supported by astropy
and numpy
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're asking the good questions. I'll start an email discussion.
# We're importing our own copy of urllib.parse because | ||
# we need to patch it to support asdf:// URIs, but it'd | ||
# be irresponsible to do this for all users of a | ||
# standard library. | ||
urllib_parse_spec = importlib.util.find_spec('urllib.parse') | ||
patched_urllib_parse = importlib.util.module_from_spec(urllib_parse_spec) | ||
urllib_parse_spec.loader.exec_module(patched_urllib_parse) | ||
del urllib_parse_spec |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What the advantage of doing it this way rather than
import urllib.parse as patched_urllib_parse
It's still local to this module's namespace, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately while that aliases the module reference to a new name, it still points to the same module object. Import caches the module after loading it the first time so that other imports don't have to read and parse the module's code again.
# module1.py
import urllib.parse as module1_alias
# module2.py
import urllib.parse as module2_alias
# Fire up a console:
In [1]: import module1
In [2]: import module2
In [3]: module1.module1_alias is module2.module2_alias
Out[3]: True
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see. I didn't realize there was caching going on. This bypasses that. #themoreyouknow
# urllib.parse needs to know that it should treat asdf:// | ||
# URIs like http:// URIs for the purposes of joining | ||
# a relative path to a base URI. | ||
patched_urllib_parse.uses_relative.append('asdf') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Digging deep into the standard library. What a naughty boy. ;-) I had to go look at the library source code to see this explained.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This PR allow asdf to properly resolve relative references against
asdf://
URIs. Theurllib.parse
module maintains a list of URI schemes that should behave likehttp
with regard to resolving relative paths, and neededasdf
added to its list.There's a second change in here that fixes a long-standing issue with resolving references in metaschemas. It's common for such schemas to define an
id
property, but the asdf library didn't know not to treat that property object as a URI. The fix is to check thatid
is a string before assuming it's a URI.