Skip to content

Commit

Permalink
pythongh-108514: Add config & transform to hide old versionmodified i…
Browse files Browse the repository at this point in the history
…n docs
  • Loading branch information
CAM-Gerlach committed Aug 26, 2023
1 parent e407cea commit 6ebea78
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
# Minimum version of sphinx required
needs_sphinx = '3.2'

# Hide versionadded and versionchanged in the output older than this version
min_version_show_changes = '3.6'

# Ignore any .rst files in the includes/ directory;
# they're embedded in pages but not rendered individually.
# Ignore any .rst files in the venv/ directory.
Expand All @@ -76,6 +79,7 @@
if venvdir is not None:
exclude_patterns.append(venvdir + '/*')


nitpick_ignore = [
# Standard C functions
('c:func', 'calloc'),
Expand Down
15 changes: 15 additions & 0 deletions Doc/tools/extensions/pyspecific.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,21 @@ def patch_pairindextypes(app, _env) -> None:
pairindextypes.clear()


def hide_old_versionmodified(app, doctree, fromdocname):
"""Remove versionmodified nodes (added/changed) older than the minimum."""
min_version = app.config.min_version_show_changes
if not min_version:
return
min_version = [int(part) for part in min_version.split(".")]
for node in list(doctree.findall(addnodes.versionmodified)):
if node['type'] in ('versionadded', 'versionchanged'):
node_version = [int(part) for part in node['version'].split(".")]
if node_version < min_version:
node.parent.remove(node)


def setup(app):
app.add_config_value('min_version_show_changes', '', 'html')
app.add_role('issue', issue_role)
app.add_role('gh', gh_issue_role)
app.add_role('source', source_role)
Expand All @@ -717,6 +731,7 @@ def setup(app):
app.add_directive('miscnews', MiscNews)
app.connect('env-check-consistency', patch_pairindextypes)
app.connect('doctree-resolved', process_audit_events)
app.connect('doctree-resolved', hide_old_versionmodified)
app.connect('env-merge-info', audit_events_merge)
app.connect('env-purge-doc', audit_events_purge)
return {'version': '1.0', 'parallel_read_safe': True}

0 comments on commit 6ebea78

Please sign in to comment.