diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7147831f..e2b87628 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -153,7 +153,7 @@ jobs: - name: Install dependencies run: > sudo apt-get update && - sudo apt-get install -y libenchant-dev libxml2-dev libxslt-dev + sudo apt-get install -y libenchant-2-dev libxml2-dev libxslt-dev if: runner.os == 'Linux' && startsWith(matrix.python-version.toxenv, 'docs-') - name: Install dependencies run: brew install enchant diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7c4dce8f..0e1a3fbd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,7 +5,6 @@ repos: rev: v4.4.0 hooks: - id: check-ast - - id: check-docstring-first - id: check-json - id: check-toml - id: check-vcs-permalinks diff --git a/docs/api/index.rst b/docs/api/index.rst new file mode 100644 index 00000000..7ba62c23 --- /dev/null +++ b/docs/api/index.rst @@ -0,0 +1,22 @@ +API Reference +============= + +Submodules +---------- + +.. toctree:: + :titlesonly: + + /api/jsonschema/validators/index + /api/jsonschema/exceptions/index + /api/jsonschema/protocols/index + +:mod:`jsonschema` +----------------- + +.. automodule:: jsonschema + :members: + :imported-members: + :exclude-members: Validator + +.. autodata:: jsonschema._format._F diff --git a/docs/api/jsonschema/exceptions/index.rst b/docs/api/jsonschema/exceptions/index.rst new file mode 100644 index 00000000..8fb1f4f3 --- /dev/null +++ b/docs/api/jsonschema/exceptions/index.rst @@ -0,0 +1,6 @@ +:py:mod:`jsonschema.exceptions` +=============================== + +.. automodule:: jsonschema.exceptions + :members: + :undoc-members: diff --git a/docs/api/jsonschema/protocols/index.rst b/docs/api/jsonschema/protocols/index.rst new file mode 100644 index 00000000..195dbeeb --- /dev/null +++ b/docs/api/jsonschema/protocols/index.rst @@ -0,0 +1,6 @@ +:py:mod:`jsonschema.protocols` +============================== + +.. automodule:: jsonschema.protocols + :members: + :undoc-members: diff --git a/docs/api/jsonschema/validators/index.rst b/docs/api/jsonschema/validators/index.rst new file mode 100644 index 00000000..f5cf82ca --- /dev/null +++ b/docs/api/jsonschema/validators/index.rst @@ -0,0 +1,6 @@ +:py:mod:`jsonschema.validators` +=============================== + +.. automodule:: jsonschema.validators + :members: + :undoc-members: diff --git a/docs/conf.py b/docs/conf.py index 949556a7..d691aaf9 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -23,9 +23,6 @@ "sphinx.ext.intersphinx", "sphinx.ext.napoleon", "sphinx.ext.viewcode", - - "autoapi.extension", - "sphinx_autodoc_typehints", "sphinx_copybutton", "sphinx_json_schema_spec", "sphinxcontrib.spelling", @@ -39,6 +36,33 @@ html_theme = "furo" +# See sphinx-doc/sphinx#10785 +_TYPE_ALIASES = { + "jsonschema._format._F", # format checkers +} + + +def _resolve_type_aliases(app, env, node, contnode): + if ( + node["refdomain"] == "py" + and node["reftype"] == "class" + and node["reftarget"] in _TYPE_ALIASES + ): + return app.env.get_domain("py").resolve_xref( + env, + node["refdoc"], + app.builder, + "data", + node["reftarget"], + node, + contnode, + ) + + +def setup(app): + app.connect("missing-reference", _resolve_type_aliases) + + # = Builders = doctest_global_setup = """ diff --git a/docs/validate.rst b/docs/validate.rst index c3b51dd8..6a721d79 100644 --- a/docs/validate.rst +++ b/docs/validate.rst @@ -58,6 +58,7 @@ versions. .. autoclass:: TypeChecker :members: + :noindex: .. autoexception:: jsonschema.exceptions.UndefinedTypeCheck :noindex: @@ -88,7 +89,7 @@ given how common validating these types are. If you *do* want the generality, or just want to add a few specific additional types as being acceptable for a validator object, then you should update an -existing `TypeChecker` or create a new one. You may then create a new +existing `jsonschema.TypeChecker` or create a new one. You may then create a new `Validator` via `jsonschema.validators.extend`. .. testcode:: @@ -252,6 +253,7 @@ The supported mechanism for ensuring these dependencies are present is again as .. autoclass:: FormatChecker :members: + :noindex: :exclude-members: cls_checks .. attribute:: checkers diff --git a/jsonschema/_format.py b/jsonschema/_format.py index 5ec97977..6a7f4a89 100644 --- a/jsonschema/_format.py +++ b/jsonschema/_format.py @@ -11,6 +11,7 @@ from jsonschema.exceptions import FormatError _FormatCheckCallable = typing.Callable[[object], bool] +#: A format checker callable. _F = typing.TypeVar("_F", bound=_FormatCheckCallable) _RaisesType = typing.Union[ typing.Type[Exception], typing.Tuple[typing.Type[Exception], ...], diff --git a/jsonschema/exceptions.py b/jsonschema/exceptions.py index 87db3df3..55c3ae73 100644 --- a/jsonschema/exceptions.py +++ b/jsonschema/exceptions.py @@ -340,6 +340,15 @@ def relevance(error): relevance = by_relevance() +""" +A key function (e.g. to use with `sorted`) which sorts errors by relevance. + +Example: + +.. code:: python + + sorted(validator.iter_errors(12), key=jsonschema.exceptions.relevance) +""" def best_match(errors, key=relevance):