|
1 |
| -"""Generate autosummary docs for imported members. |
| 1 | +"""Generate autosummary for imported members. |
2 | 2 |
|
3 |
| -This extension patches the :mod:`~sphinx.ext.autosummary` extension |
4 |
| -to generate docs for imported members. |
5 |
| -It needs to be loaded and :confval:`autosummary_generate` needs to be set to ``True``. |
| 3 | +.. deprecated:: 0.11.0 |
6 | 4 |
|
7 |
| -This will hopefully be superseded by the ability to add ``:imported-members:`` |
8 |
| -to `autosummary templates`_ in the future. See `Sphinx issue 4372`_. |
9 |
| -
|
10 |
| -.. _autosummary templates: http://www.sphinx-doc.org/en/master/usage/extensions/autosummary.html#customizing-templates |
11 |
| -.. _Sphinx issue 4372: https://github.com/sphinx-doc/sphinx/issues/4372 |
| 5 | + Use ``autosummary_imported_members = True`` instead. |
12 | 6 | """
|
| 7 | + |
13 | 8 | from __future__ import annotations
|
14 | 9 |
|
15 |
| -import logging |
16 |
| -from typing import TYPE_CHECKING, Any |
17 |
| -from pathlib import Path |
| 10 | +import sys |
| 11 | +from typing import TYPE_CHECKING |
18 | 12 |
|
19 |
| -from sphinx.ext import autosummary |
20 |
| -from sphinx.ext.autosummary.generate import generate_autosummary_docs |
21 | 13 |
|
22 |
| -from . import metadata, _setup_sig |
| 14 | +if sys.version_info >= (3, 11): |
| 15 | + from typing import Never |
| 16 | +else: # pragma: no cover |
| 17 | + from typing import NoReturn as Never |
| 18 | + |
| 19 | +from . import _setup_sig |
23 | 20 |
|
24 | 21 |
|
25 | 22 | if TYPE_CHECKING:
|
26 | 23 | from sphinx.application import Sphinx
|
27 | 24 |
|
28 | 25 |
|
29 |
| -logger = logging.getLogger(__name__) |
30 |
| - |
31 |
| - |
32 |
| -def _generate_stubs(app: Sphinx) -> None: |
33 |
| - gen_files = app.config.autosummary_generate |
34 |
| - |
35 |
| - if gen_files and not hasattr(gen_files, "__len__"): |
36 |
| - env = app.builder.env |
37 |
| - gen_files = [ |
38 |
| - env.doc2path(x, base=False) |
39 |
| - for x in env.found_docs |
40 |
| - if Path(env.doc2path(x)).is_file() |
41 |
| - ] |
42 |
| - if not gen_files: |
43 |
| - return |
44 |
| - |
45 |
| - ext = app.config.source_suffix |
46 |
| - gen_files = [ |
47 |
| - genfile + ("" if genfile.endswith(tuple(ext)) else ext[0]) |
48 |
| - for genfile in gen_files |
49 |
| - ] |
50 |
| - |
51 |
| - suffix = autosummary.get_rst_suffix(app) |
52 |
| - if suffix is None: |
53 |
| - return |
54 |
| - |
55 |
| - generate_autosummary_docs( |
56 |
| - gen_files, |
57 |
| - suffix=suffix, |
58 |
| - base_path=app.srcdir, |
59 |
| - imported_members=True, |
60 |
| - app=app, |
61 |
| - ) |
62 |
| - |
63 |
| - |
64 | 26 | @_setup_sig
|
65 |
| -def setup(_app: Sphinx) -> dict[str, Any]: |
66 |
| - """Patch autosummary to generate docs for imported members as well.""" |
67 |
| - autosummary.process_generate_options = _generate_stubs |
68 |
| - |
69 |
| - return metadata |
| 27 | +def setup(_app: Sphinx) -> Never: # pragma: no cover |
| 28 | + """Throws an :exc:`ImportError`.""" |
| 29 | + msg = ( |
| 30 | + "Please use `autosummary_imported_members = True` " |
| 31 | + f"instead of the {__name__} Sphinx extension." |
| 32 | + ) |
| 33 | + raise ImportError(msg) |
0 commit comments