Skip to content

Commit

Permalink
Rename create_catalog starred param
Browse files Browse the repository at this point in the history
'versions' concurs with both the docs and the tests

'vocabularies' does not concur with what vocabularies are either in JSON Schema or in jschon
  • Loading branch information
marksparkza committed Apr 1, 2023
1 parent 8a6093c commit 1cdcf74
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Miscellaneous:
``default_core_vocabulary`` and ``default_core_vocabulary_uri``
* Improve kwarg-based construction of ``RelativeJSONPointer``
* Rename ``AnnotationKeyword`` to ``_AnnotationKeyword``
* Rename ``vocabularies`` parameter of ``create_catalog()`` to ``versions``
* Allow passthrough of arguments to pytest when invoking tox
* Add pytest command line options ``--testsuite-file`` and ``--testsuite-description``
* Python 3.11 is now tested (no changes were required to support it)
Expand Down
10 changes: 5 additions & 5 deletions docs/tutorial/catalog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The role of the :class:`~jschon.catalog.Catalog` in jschon is twofold:
cooperative schemas that work together to evaluate :class:`~jschon.json.JSON`
documents.
#. It provides the infrastructure required for constructing
:class:`~jschon.jsonschema.JSONSchema` objects. This can include metaschemas,
:class:`~jschon.jsonschema.JSONSchema` objects. This can include meta-schemas,
vocabularies and keyword implementations, format validators, and URI-to-directory
mappings enabling URI-identified schemas to be located on disk.

Expand All @@ -18,14 +18,14 @@ at startup:
>>> catalog = create_catalog('2020-12')

The :func:`~jschon.create_catalog` function accepts a variable argument list
indicating which versions of the JSON Schema vocabulary to support. For example,
the following initialization call will enable our application to work with both
indicating which versions of the JSON Schema vocabularies to support. For example,
the following initialization call will enable your application to work with both
2019-09 and 2020-12 schemas:

>>> catalog = create_catalog('2019-09', '2020-12')

If our application requires distinct :class:`~jschon.catalog.Catalog`
instances with different configurations, then our setup might look something
If your application requires distinct :class:`~jschon.catalog.Catalog`
instances with different configurations, then your setup might look something
like this:

>>> catalog_1 = create_catalog('2019-09', name='Catalog 1')
Expand Down
18 changes: 9 additions & 9 deletions jschon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,30 @@
__version__ = '0.10.0'


def create_catalog(*vocabularies: str, name: str = 'catalog') -> Catalog:
def create_catalog(*versions: str, name: str = 'catalog') -> Catalog:
"""Create and return a :class:`~jschon.catalog.Catalog` instance,
initialized with a meta-schema and keyword support for each of the
specified JSON Schema `vocabularies`.
specified JSON Schema `versions`.
:param vocabularies: Any of ``2019-09``, ``2020-12``, ``next``.
:param versions: Any of ``2019-09``, ``2020-12``, ``next``.
:param name: A unique name for the :class:`~jschon.catalog.Catalog` instance.
:raise ValueError: If any of `vocabularies` is unrecognized.
:raise ValueError: If any of `versions` is unrecognized.
"""
from .catalog import _2019_09, _2020_12, _next

catalog = Catalog(name=name)

vocabulary_initializers = {
version_initializers = {
'2019-09': _2019_09.initialize,
'2020-12': _2020_12.initialize,
'next': _next.initialize,
}
try:
for vocabulary in vocabularies:
vocabulary_init = vocabulary_initializers[vocabulary]
vocabulary_init(catalog)
for version in versions:
version_init = version_initializers[version]
version_init(catalog)

except KeyError as e:
raise ValueError(f'Unsupported vocabulary "{e.args[0]}"')
raise ValueError(f'Unrecognized version {e.args[0]!r}')

return catalog

0 comments on commit 1cdcf74

Please sign in to comment.