A tool to automatically detect and fix outdated line numbers in Sphinx literalinclude directives.
When using literalinclude directives in Sphinx documentation, you often specify line numbers to include specific portions of code:
.. literalinclude:: /path/to/config.yaml
:lines: 10-25
:emphasize-lines: 15-18However, when the source files change (lines are added or removed), these line numbers become outdated, potentially showing the wrong code or breaking the documentation build.
This tool:
- Scans RST files for
literalincludedirectives with line specifications - Uses git history to detect when source files changed after the RST files
- Identifies directives where line changes affect the specified range
- Optionally fixes the line numbers automatically
pip install envoy.docs.literalincludeCheck for outdated directives (dry run):
literalinclude-check /path/to/repoCheck specific directories:
literalinclude-check /path/to/repo --dirs docs apiFix outdated directives:
literalinclude-check /path/to/repo --fixList all literalinclude directives:
literalinclude-check /path/to/repo --listJSON output:
literalinclude-check /path/to/repo --json- Discovery: Finds all RST files in specified directories (default:
docsandapi) - Parsing: Extracts
literalincludedirectives with their options::lines:- Line ranges to include:emphasize-lines:- Lines to emphasize- Source file path
- Git Analysis: For each directive:
- Checks when the RST file was last modified
- Checks when the source file was last modified
- If source changed after RST, analyzes the diff
- Detection: Flags directives as outdated if:
- Lines were added/removed in the source file
- Changes occurred at or before the maximum line number referenced
- Fixing: Updates the line numbers in RST files to match current source
- Requires a git repository
- Best-effort fixing - may not always determine correct new line numbers
- Currently focused on
:lines:and:emphasize-lines:options - Does not handle
:start-after:and:end-before:markers yet
Apache License 2.0