From: Trevor Woerner <twoerner@gmail.com>
To: Antonin Godard <antonin.godard@bootlin.com>
Cc: docs@lists.yoctoproject.org
Subject: Re: [docs] [PATCH v2 2/2] sphinx: add a lexer for pydevshell sessions
Date: Fri, 27 Nov 2026 06:57:57 -0500 [thread overview]
Message-ID: <awlwRW2Ot-G0ZqS-@localhost.localdomain> (raw)
In-Reply-To: <DN5UAAGPMBRN.1JXZ9W6JD6NPH@bootlin.com>
On Fri 2026-11-27 @ 09:10:33 AM, Antonin Godard wrote:
> On Thu Nov 26, 2026 at 11:36 PM CET, Trevor Woerner via docs wrote:
> > 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 v2:
> > - rebase on master, where conf.py no longer lists the dropped lexers
> > ---
> > 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 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..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 = '... '
>
> What's _ps2 here and what's its purpose?
It is the continuation prompt (same as in BASH). devshell.bbclass
sets ps1 = "pydevshell> " and ps2 = "... ", and prints the second
while a statement is incomplete, such as the body of a for loop.
ShellSessionBaseLexer uses _ps2 to recognise those lines as typed input
rather than output.
As v2 had it, though, it did nothing useful: the base class only looks
for _ps2 on the line after one ending in a backslash, unless
_bare_continuation is set. v3 sets it, so a continuation line is
highlighted as a prompt followed by Python instead of being shown as
output. The example in the manual has no continuation lines, so its
rendering does not change.
> Antonin
next prev parent reply other threads:[~2026-11-27 11:58 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 22:36 [PATCH v2 0/2] sphinx: add lexers for wic kickstart files and pydevshell sessions Trevor Woerner
2026-11-26 22:36 ` [PATCH v2 1/2] sphinx: add a lexer for wic kickstart files Trevor Woerner
2026-11-26 22:36 ` [PATCH v2 2/2] sphinx: add a lexer for pydevshell sessions Trevor Woerner
2026-11-27 8:10 ` [docs] " Antonin Godard
2026-11-27 11:57 ` Trevor Woerner [this message]
2026-11-27 8:10 ` [docs] [PATCH v2 0/2] sphinx: add lexers for wic kickstart files and " Antonin Godard
2026-11-27 12:03 ` 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=awlwRW2Ot-G0ZqS-@localhost.localdomain \
--to=twoerner@gmail.com \
--cc=antonin.godard@bootlin.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.