Skip to content

Commit abce7c2

Browse files
committed
Add remove_old configuration to sphinx.ext.apidoc
Makes the option available to be configured when using apidoc as an extension instead of as a command-line tool.
1 parent 0767742 commit abce7c2

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

doc/usage/extensions/apidoc.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ The apidoc extension uses the following configuration values:
9292
:code-py:`'follow_links'`
9393
See :confval:`apidoc_follow_links`.
9494

95+
:code-py:`'remove_old'`
96+
See :confval:`apidoc_remove_old`.
97+
9598
:code-py:`'separate_modules'`
9699
See :confval:`apidoc_separate_modules`.
97100

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

130133
Follow symbolic links.
131134

135+
.. confval:: apidoc_remove_old
136+
:type: :code-py:`bool`
137+
:default: :code-py:`True`
138+
139+
Remove existing files in the output directory that are not created anymore.
140+
132141
.. confval:: apidoc_separate_modules
133142
:type: :code-py:`bool`
134143
:default: :code-py:`False`

sphinx/ext/apidoc/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def setup(app: Sphinx) -> ExtensionMetadata:
3737
)
3838
app.add_config_value('apidoc_max_depth', 4, 'env', types=frozenset({int}))
3939
app.add_config_value('apidoc_follow_links', False, 'env', types=frozenset({bool}))
40+
app.add_config_value('apidoc_remove_old', True, 'env', types=frozenset({bool}))
4041
app.add_config_value(
4142
'apidoc_separate_modules', False, 'env', types=frozenset({bool})
4243
)

sphinx/ext/apidoc/_extension.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
_BOOL_KEYS = frozenset({
2727
'follow_links',
28+
'remove_old',
2829
'separate_modules',
2930
'include_private',
3031
'no_headings',
@@ -220,6 +221,7 @@ def _parse_module_options(
220221
max_depth=max_depth,
221222
quiet=True,
222223
follow_links=bool_options['follow_links'],
224+
remove_old=bool_options['remove_old'],
223225
separate_modules=bool_options['separate_modules'],
224226
include_private=bool_options['include_private'],
225227
no_headings=bool_options['no_headings'],

sphinx/ext/apidoc/_shared.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class ApidocDefaults:
7777
automodule_options: frozenset[str]
7878
max_depth: int
7979
follow_links: bool
80+
remove_old: bool
8081
separate_modules: bool
8182
include_private: bool
8283
no_headings: bool
@@ -91,6 +92,7 @@ def from_config(cls, config: Config, /) -> Self:
9192
automodule_options=frozenset(config.apidoc_automodule_options),
9293
max_depth=config.apidoc_max_depth,
9394
follow_links=config.apidoc_follow_links,
95+
remove_old=config.apidoc_remove_old,
9496
separate_modules=config.apidoc_separate_modules,
9597
include_private=config.apidoc_include_private,
9698
no_headings=config.apidoc_no_headings,

0 commit comments

Comments
 (0)