From: Trevor Woerner <twoerner@gmail.com>
To: docs@lists.yoctoproject.org
Subject: [PATCH 5/7] sphinx: add a lexer for pydevshell sessions
Date: Wed, 25 Nov 2026 10:45:33 -0500 [thread overview]
Message-ID: <20261125154535.3486104-6-twoerner@gmail.com> (raw)
In-Reply-To: <20261125154535.3486104-1-twoerner@gmail.com>
The development manual shows a session in BitBake's Python development
shell, and no lexer reads it: console wants a prompt ending in $, #, or
%, pycon wants >>>, and both mark the whole block as program output,
which the theme greys. The prompt cannot be changed to suit them either,
since devshell.bbclass is what sets it.
Teach a session lexer the prompt instead, with Python inside it, so the
expressions the reader types are highlighted as Python and the results
are not.
AI-Generated: codex/claude-opus 5.5 (xhigh)
Signed-off-by: Trevor Woerner <twoerner@gmail.com>
---
documentation/conf.py | 3 +-
documentation/sphinx/pydevshell-lexer.py | 48 ++++++++++++++++++++++++
2 files changed, 50 insertions(+), 1 deletion(-)
create mode 100644 documentation/sphinx/pydevshell-lexer.py
diff --git a/documentation/conf.py b/documentation/conf.py
index f89926549d20..3a7e3c920fc4 100644
--- a/documentation/conf.py
+++ b/documentation/conf.py
@@ -83,7 +83,8 @@ extensions = [
'bitbake-lexer',
'bitbake-placeholder',
'scc-lexer',
- 'wks-lexer'
+ 'wks-lexer',
+ 'pydevshell-lexer'
]
# current_version = "dev"
diff --git a/documentation/sphinx/pydevshell-lexer.py b/documentation/sphinx/pydevshell-lexer.py
new file mode 100644
index 000000000000..a0dd7c9fa684
--- /dev/null
+++ b/documentation/sphinx/pydevshell-lexer.py
@@ -0,0 +1,48 @@
+"""Lexer for ``bitbake -c pydevshell`` sessions.
+
+The development manual shows a session in BitBake's Python development
+shell: expressions typed at a ``pydevshell> `` prompt with their results
+beneath. No existing lexer reads it. ``console`` is a shell session and
+wants a prompt ending in ``$``, ``#``, or ``%``; ``pycon`` wants ``>>>``.
+Both mark the whole block as program output, which the theme renders in
+grey, so the block ends up dimmer than the prose around it and no better
+told apart.
+
+The prompt is not ours to change: ``devshell.bbclass`` sets
+``ps1 = "pydevshell> "``, so what the manual shows is what the reader
+sees. That leaves teaching a lexer the prompt as the only way to render
+one of these correctly.
+
+``ShellSessionBaseLexer`` does the work once ``_ps1rgx`` matches: it
+splits the typed line from its output and hands the typed part to an inner
+lexer, which here is Python.
+"""
+import re
+
+from pygments.lexers.python import PythonLexer
+from pygments.lexers.shell import ShellSessionBaseLexer
+
+__version__ = '1.0'
+
+
+class PyDevShellSessionLexer(ShellSessionBaseLexer):
+ """A session in BitBake's Python development shell."""
+
+ name = 'BitBake pydevshell session'
+ aliases = ['pydevshell']
+ filenames = []
+ mimetypes = []
+ url = 'https://docs.yoctoproject.org/dev-manual/python-development-shell.html'
+
+ _innerLexerCls = PythonLexer
+ _ps1rgx = re.compile(r'^(pydevshell> )(.*\n?)')
+ _ps2 = '... '
+
+
+def setup(app):
+ app.add_lexer('pydevshell', PyDevShellSessionLexer)
+ return {
+ 'version': __version__,
+ 'parallel_read_safe': True,
+ 'parallel_write_safe': True,
+ }
--
2.50.0.173.g8b6f19ccfc3a
next prev parent reply other threads:[~2026-11-25 15:45 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 15:45 [PATCH 0/7] sphinx: carry lexers for the languages the manuals show Trevor Woerner
2026-11-25 15:45 ` [PATCH 1/7] sphinx: carry a BitBake lexer as a local extension Trevor Woerner
2026-11-25 15:45 ` [PATCH 2/7] sphinx: add a lexer for BitBake with placeholders Trevor Woerner
2026-11-25 15:45 ` [PATCH 3/7] sphinx: add a lexer for kernel metadata SCC files Trevor Woerner
2026-11-25 15:45 ` [PATCH 4/7] sphinx: add a lexer for wic kickstart files Trevor Woerner
2026-11-25 15:45 ` Trevor Woerner [this message]
2026-11-25 15:45 ` [PATCH 6/7] sphinx: read a bare "#" in a console block as output Trevor Woerner
2026-11-25 15:45 ` [PATCH 7/7] sphinx: mark placeholders in console and plain-text examples Trevor Woerner
2026-11-26 16:33 ` [docs] [PATCH 0/7] sphinx: carry lexers for the languages the manuals show Antonin Godard
2026-11-26 22:26 ` Trevor Woerner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261125154535.3486104-6-twoerner@gmail.com \
--to=twoerner@gmail.com \
--cc=docs@lists.yoctoproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox