docs(_ext): Add pretty_argparse extension with CLI usage highlighting#1007
Merged
docs(_ext): Add pretty_argparse extension with CLI usage highlighting#1007
Conversation
Add Pygments type stubs to dev and lint dependency groups. Also add sphinxarg.* to mypy ignore_missing_imports.
A comprehensive Sphinx extension that enhances sphinx-argparse output: Features: - Strip ANSI escape codes from argparse help text (FORCE_COLOR support) - Transform "examples:" definition lists into proper doc sections - Nest category-specific examples under parent Examples section - Custom Pygments lexer (cli-usage) for usage block syntax highlighting - Reorder sections so usage appears before examples CLI usage lexer token types: - Generic.Heading: "usage:" prefix - Name.Tag: long options (--verbose, --no-color) - Name.Attribute: short options (-h, -S) - Name.Variable: option values (socket-path, COMMAND) - Name.Constant: uppercase metavars (FILE, PATH) - Name.Label: positional args and command names - Punctuation: brackets [], parentheses () - Operator: pipe | and equals = Files added: - docs/_ext/pretty_argparse.py: Main extension (680 lines) - docs/_ext/cli_usage_lexer.py: Pygments lexer (116 lines) - tests/docs/_ext/test_pretty_argparse.py: 66 tests (854 lines) - tests/docs/_ext/test_cli_usage_lexer.py: 22 tests (357 lines)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1007 +/- ##
==========================================
+ Coverage 73.27% 77.35% +4.07%
==========================================
Files 26 25 -1
Lines 1860 1722 -138
Branches 352 328 -24
==========================================
- Hits 1363 1332 -31
+ Misses 394 287 -107
Partials 103 103 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Sphinx extension files (pretty_argparse.py, cli_usage_lexer.py) are documentation infrastructure, not core application code. Exclude them from coverage measurement similar to tests/, _vendor/, etc.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A comprehensive Sphinx extension that enhances sphinx-argparse output:
cli-usage) for usage block syntax highlightingCLI usage lexer token types
usage:prefixusage:--verbose,--no-color-h,-Ssocket-path,COMMANDFILE,PATHsession-name[,],(,)Files added
docs/_ext/pretty_argparse.py: Main extension (680 lines)docs/_ext/cli_usage_lexer.py: Pygments lexer (116 lines)tests/docs/_ext/test_pretty_argparse.py: 66 tests (854 lines)tests/docs/_ext/test_cli_usage_lexer.py: 22 tests (357 lines)Test plan
uv run ruff check .passesuv run mypy .passesuv run py.test tests/docs/_ext/passes (88 tests)