Skip to content

Commit e24f0ee

Browse files
authored
Merge pull request #1021 from DanielNoord/docs/autodoc
Use only ``autodoc`` to generate the API documentation
2 parents 2815178 + 1b2d03b commit e24f0ee

File tree

10 files changed

+81
-6
lines changed

10 files changed

+81
-6
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ jobs:
153153
- name: Install dependencies
154154
run: >
155155
sudo apt-get update &&
156-
sudo apt-get install -y libenchant-dev libxml2-dev libxslt-dev
156+
sudo apt-get install -y libenchant-2-dev libxml2-dev libxslt-dev
157157
if: runner.os == 'Linux' && startsWith(matrix.python-version.toxenv, 'docs-')
158158
- name: Install dependencies
159159
run: brew install enchant

.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ repos:
55
rev: v4.4.0
66
hooks:
77
- id: check-ast
8-
- id: check-docstring-first
98
- id: check-json
109
- id: check-toml
1110
- id: check-vcs-permalinks

docs/api/index.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
API Reference
2+
=============
3+
4+
Submodules
5+
----------
6+
7+
.. toctree::
8+
:titlesonly:
9+
10+
/api/jsonschema/validators/index
11+
/api/jsonschema/exceptions/index
12+
/api/jsonschema/protocols/index
13+
14+
:mod:`jsonschema`
15+
-----------------
16+
17+
.. automodule:: jsonschema
18+
:members:
19+
:imported-members:
20+
:exclude-members: Validator
21+
22+
.. autodata:: jsonschema._format._F
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
:py:mod:`jsonschema.exceptions`
2+
===============================
3+
4+
.. automodule:: jsonschema.exceptions
5+
:members:
6+
:undoc-members:
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
:py:mod:`jsonschema.protocols`
2+
==============================
3+
4+
.. automodule:: jsonschema.protocols
5+
:members:
6+
:undoc-members:
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
:py:mod:`jsonschema.validators`
2+
===============================
3+
4+
.. automodule:: jsonschema.validators
5+
:members:
6+
:undoc-members:

docs/conf.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
"sphinx.ext.intersphinx",
2424
"sphinx.ext.napoleon",
2525
"sphinx.ext.viewcode",
26-
27-
"autoapi.extension",
28-
"sphinx_autodoc_typehints",
2926
"sphinx_copybutton",
3027
"sphinx_json_schema_spec",
3128
"sphinxcontrib.spelling",
@@ -39,6 +36,33 @@
3936

4037
html_theme = "furo"
4138

39+
# See sphinx-doc/sphinx#10785
40+
_TYPE_ALIASES = {
41+
"jsonschema._format._F", # format checkers
42+
}
43+
44+
45+
def _resolve_type_aliases(app, env, node, contnode):
46+
if (
47+
node["refdomain"] == "py"
48+
and node["reftype"] == "class"
49+
and node["reftarget"] in _TYPE_ALIASES
50+
):
51+
return app.env.get_domain("py").resolve_xref(
52+
env,
53+
node["refdoc"],
54+
app.builder,
55+
"data",
56+
node["reftarget"],
57+
node,
58+
contnode,
59+
)
60+
61+
62+
def setup(app):
63+
app.connect("missing-reference", _resolve_type_aliases)
64+
65+
4266
# = Builders =
4367

4468
doctest_global_setup = """

docs/validate.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ versions.
5858

5959
.. autoclass:: TypeChecker
6060
:members:
61+
:noindex:
6162

6263
.. autoexception:: jsonschema.exceptions.UndefinedTypeCheck
6364
:noindex:
@@ -88,7 +89,7 @@ given how common validating these types are.
8889

8990
If you *do* want the generality, or just want to add a few specific additional
9091
types as being acceptable for a validator object, then you should update an
91-
existing `TypeChecker` or create a new one. You may then create a new
92+
existing `jsonschema.TypeChecker` or create a new one. You may then create a new
9293
`Validator` via `jsonschema.validators.extend`.
9394

9495
.. testcode::
@@ -252,6 +253,7 @@ The supported mechanism for ensuring these dependencies are present is again as
252253

253254
.. autoclass:: FormatChecker
254255
:members:
256+
:noindex:
255257
:exclude-members: cls_checks
256258

257259
.. attribute:: checkers

jsonschema/_format.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from jsonschema.exceptions import FormatError
1212

1313
_FormatCheckCallable = typing.Callable[[object], bool]
14+
#: A format checker callable.
1415
_F = typing.TypeVar("_F", bound=_FormatCheckCallable)
1516
_RaisesType = typing.Union[
1617
typing.Type[Exception], typing.Tuple[typing.Type[Exception], ...],

jsonschema/exceptions.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,15 @@ def relevance(error):
340340

341341

342342
relevance = by_relevance()
343+
"""
344+
A key function (e.g. to use with `sorted`) which sorts errors by relevance.
345+
346+
Example:
347+
348+
.. code:: python
349+
350+
sorted(validator.iter_errors(12), key=jsonschema.exceptions.relevance)
351+
"""
343352

344353

345354
def best_match(errors, key=relevance):

0 commit comments

Comments
 (0)