Yocto Project Documentation
 help / color / mirror / Atom feed
From: Trevor Woerner <twoerner@gmail.com>
To: docs@lists.yoctoproject.org
Subject: [PATCH v3 3/4] sphinx: add a lexer for pydevshell sessions
Date: Fri, 27 Nov 2026 07:05:27 -0500	[thread overview]
Message-ID: <20261127120528.837051-4-twoerner@gmail.com> (raw)
In-Reply-To: <20261127120528.837051-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>
---
changes in v3:
- recognise the "... " continuation prompt (_ps2) without a backslash on
  the line before

changes in v2:
- rebase on master, where conf.py no longer lists the dropped lexers
---
 documentation/conf.py                    |  3 +-
 documentation/sphinx/pydevshell-lexer.py | 51 ++++++++++++++++++++++++
 2 files changed, 53 insertions(+), 1 deletion(-)
 create mode 100644 documentation/sphinx/pydevshell-lexer.py

diff --git a/documentation/conf.py b/documentation/conf.py
index 8992496f7569..7d0e103042fd 100644
--- a/documentation/conf.py
+++ b/documentation/conf.py
@@ -52,7 +52,8 @@ extensions = [
     'sphinx_copybutton',
     'sphinxcontrib.rsvgconverter',
     'yocto-vars',
-    '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..9e8a48e1f73e
--- /dev/null
+++ b/documentation/sphinx/pydevshell-lexer.py
@@ -0,0 +1,51 @@
+"""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?)')
+    # devshell.bbclass prompts "... " while a statement is incomplete, as
+    # Python's own console does, without a backslash on the line before.
+    _ps2 = '... '
+    _bare_continuation = True
+
+
+def setup(app):
+    app.add_lexer('pydevshell', PyDevShellSessionLexer)
+    return {
+        'version': __version__,
+        'parallel_read_safe': True,
+        'parallel_write_safe': True,
+    }
-- 
2.50.0.173.g8b6f19ccfc3a


  parent reply	other threads:[~2026-11-27 12:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 12:05 [PATCH v3 0/4] sphinx: add lexers for wic kickstart files and pydevshell sessions Trevor Woerner
2026-11-27 12:05 ` [PATCH v3 1/4] sphinx: add a lexer for wic kickstart files Trevor Woerner
2026-11-27 12:05 ` [PATCH v3 2/4] docs: use the wks lexer for the kickstart examples Trevor Woerner
2026-11-27 12:05 ` Trevor Woerner [this message]
2026-11-27 12:05 ` [PATCH v3 4/4] dev-manual: use the pydevshell lexer for the session example 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=20261127120528.837051-4-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