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

Allow adding a default source with a base URI of None #83

Merged
merged 2 commits into from
Jul 19, 2023

Conversation

handrews
Copy link
Contributor

@handrews handrews commented Mar 21, 2023

Minimally fixes #75. This can be used to match complete URIs, particularly URN-ish URIs using schemes that do not readily break down into a base and a relative reference.

The details of the change (using a string prefix after verifying the base URI when it is not None) is invisible to the public API, and the fundamental semantics are preserved.

This is sufficient for the use case that was blocking me: how to load a URI like tag:modern-json-schema.com,2023-03:something, which cannot be split. Its only components are the scheme tag and the path modern-json-schema.con,2023-03:something, and that path cannot be used as the start of a relative reference because it contains a :.

Potential workarounds

An alternative would be to register a source for each expected URI using the whole URI as a base URI, but that wouldn't work for URIs not known in advance.

Discarded approaches

I attempted the more flexible uri_prefix idea proposed in #75, but it became complicated and required awkward contortions to maintain backwards compatibility in the public API. I decided that the extra flexibility was not worthwhile as a source registered in this way can do whatever re-mapping it wants with the relative_path, such as converting : characters to something else so that the URI can be used on Mac OS X filesystems.

@codecov
Copy link

codecov bot commented Jun 21, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.01 🎉

Comparison is base (0c210c2) 92.72% compared to head (6812b6e) 92.73%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #83      +/-   ##
==========================================
+ Coverage   92.72%   92.73%   +0.01%     
==========================================
  Files          23       23              
  Lines        2049     2052       +3     
  Branches      434      435       +1     
==========================================
+ Hits         1900     1903       +3     
  Misses         97       97              
  Partials       52       52              
Impacted Files Coverage Δ
jschon/catalog/__init__.py 98.17% <100.00%> (+0.03%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

This can be used to match complete URIs, particularly URN-ish
URIs using schemes that do not readily break down into a base
and a relative reference.
@marksparkza
Copy link
Owner

I'm happy with this approach. It makes sense for base_uri=None to imply a default source; this just needs to be clarified in the docstring. Comments coming up...

jschon/catalog/__init__.py Show resolved Hide resolved
jschon/catalog/__init__.py Outdated Show resolved Hide resolved
tests/test_catalog.py Outdated Show resolved Hide resolved
@marksparkza marksparkza merged commit e6f71d0 into marksparkza:main Jul 19, 2023
6 checks passed
@handrews handrews deleted the default-source branch July 19, 2023 21:48
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

Successfully merging this pull request may close these issues.

Proposal: support a default source for URIs with no usable base URI vs relative-reference split
2 participants