Skip to content

Add remove_old configuration to sphinx.ext.apidoc #13668

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Contributors
* Dimitri Papadopoulos Orfanos -- linting and spelling
* Dmitry Shachnev -- modernisation and reproducibility
* Doug Hellmann -- graphviz improvements
* Edouard Choinière -- ``sphinx.ext.apidoc`` extension improvement
* Eric Larson -- better error messages
* Eric N. Vander Weele -- autodoc improvements
* Eric Wieser -- autodoc improvements
Expand Down
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ Features added
The location of the cache directory must not be relied upon externally,
as it may change without notice or warning in future releases.
Patch by Adam Turner.
* #13668: :mod:`sphinx.ext.apidoc`: Support :confval:`apidoc_remove_old`
and :code:`'remove_old'` key of :confval:`apidoc_modules` when using apidoc as
an extension, like :option:`sphinx-apidoc --remove-old`.
Patch by Edouard Choinière.

Bugs fixed
----------
Expand Down
9 changes: 9 additions & 0 deletions doc/usage/extensions/apidoc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ The apidoc extension uses the following configuration values:
:code-py:`'follow_links'`
See :confval:`apidoc_follow_links`.

:code-py:`'remove_old'`
See :confval:`apidoc_remove_old`.

:code-py:`'separate_modules'`
See :confval:`apidoc_separate_modules`.

Expand Down Expand Up @@ -129,6 +132,12 @@ The apidoc extension uses the following configuration values:

Follow symbolic links.

.. confval:: apidoc_remove_old
:type: :code-py:`bool`
:default: :code-py:`True`

Remove existing files in the output directory that are not created anymore.

.. confval:: apidoc_separate_modules
:type: :code-py:`bool`
:default: :code-py:`False`
Expand Down
1 change: 1 addition & 0 deletions sphinx/ext/apidoc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def setup(app: Sphinx) -> ExtensionMetadata:
)
app.add_config_value('apidoc_max_depth', 4, 'env', types=frozenset({int}))
app.add_config_value('apidoc_follow_links', False, 'env', types=frozenset({bool}))
app.add_config_value('apidoc_remove_old', True, 'env', types=frozenset({bool}))
app.add_config_value(
'apidoc_separate_modules', False, 'env', types=frozenset({bool})
)
Expand Down
2 changes: 2 additions & 0 deletions sphinx/ext/apidoc/_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

_BOOL_KEYS = frozenset({
'follow_links',
'remove_old',
'separate_modules',
'include_private',
'no_headings',
Expand Down Expand Up @@ -220,6 +221,7 @@ def _parse_module_options(
max_depth=max_depth,
quiet=True,
follow_links=bool_options['follow_links'],
remove_old=bool_options['remove_old'],
separate_modules=bool_options['separate_modules'],
include_private=bool_options['include_private'],
no_headings=bool_options['no_headings'],
Expand Down
2 changes: 2 additions & 0 deletions sphinx/ext/apidoc/_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class ApidocDefaults:
automodule_options: frozenset[str]
max_depth: int
follow_links: bool
remove_old: bool
separate_modules: bool
include_private: bool
no_headings: bool
Expand All @@ -91,6 +92,7 @@ def from_config(cls, config: Config, /) -> Self:
automodule_options=frozenset(config.apidoc_automodule_options),
max_depth=config.apidoc_max_depth,
follow_links=config.apidoc_follow_links,
remove_old=config.apidoc_remove_old,
separate_modules=config.apidoc_separate_modules,
include_private=config.apidoc_include_private,
no_headings=config.apidoc_no_headings,
Expand Down
Loading