Yocto Project Documentation
 help / color / mirror / Atom feed
* [PATCH v2 0/2] sphinx: add lexers for wic kickstart files and pydevshell sessions
@ 2026-11-26 22:36 Trevor Woerner
  2026-11-26 22:36 ` [PATCH v2 1/2] sphinx: add a lexer for wic kickstart files Trevor Woerner
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Trevor Woerner @ 2026-11-26 22:36 UTC (permalink / raw)
  To: docs

Lexers for wic kickstart (.wks) files and for sessions in BitBake's
Python development shell, which the manuals show and Pygments does not
cover. No block names either yet, so the rendered manuals do not change.

changes in v2:
- keep only these two lexers
- rebase on master

Trevor Woerner (2):
  sphinx: add a lexer for wic kickstart files
  sphinx: add a lexer for pydevshell sessions

 documentation/conf.py                    |  4 +-
 documentation/sphinx/pydevshell-lexer.py | 48 +++++++++++++++++++
 documentation/sphinx/wks-lexer.py        | 60 ++++++++++++++++++++++++
 3 files changed, 111 insertions(+), 1 deletion(-)
 create mode 100644 documentation/sphinx/pydevshell-lexer.py
 create mode 100644 documentation/sphinx/wks-lexer.py

-- 
2.50.0.173.g8b6f19ccfc3a


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 1/2] sphinx: add a lexer for wic kickstart files
  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 ` 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] [PATCH v2 0/2] sphinx: add lexers for wic kickstart files and " Antonin Godard
  2 siblings, 0 replies; 7+ messages in thread
From: Trevor Woerner @ 2026-11-26 22:36 UTC (permalink / raw)
  To: docs

The manuals show .wks files in several places and have no language for
them, so they are tagged text, tagged shell, or left to the default.
Shell comes closest, because wic splits each line with shlex and expands
${VAR} before parsing, but it does not know the vocabulary: the "part"
opening a line and every option come out as ordinary text.

This extends the bash lexer to mark the statements and long options that
wic's own parser registers.

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/wks-lexer.py | 60 +++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 1 deletion(-)
 create mode 100644 documentation/sphinx/wks-lexer.py

diff --git a/documentation/conf.py b/documentation/conf.py
index d2252d5ab966..8992496f7569 100644
--- a/documentation/conf.py
+++ b/documentation/conf.py
@@ -51,7 +51,8 @@ extensions = [
     'sphinx.ext.intersphinx',
     'sphinx_copybutton',
     'sphinxcontrib.rsvgconverter',
-    'yocto-vars'
+    'yocto-vars',
+    'wks-lexer'
 ]
 
 # current_version = "dev"
diff --git a/documentation/sphinx/wks-lexer.py b/documentation/sphinx/wks-lexer.py
new file mode 100644
index 000000000000..1e5e5ec1e5b9
--- /dev/null
+++ b/documentation/sphinx/wks-lexer.py
@@ -0,0 +1,60 @@
+"""A lexer for wic kickstart (.wks) files.
+
+wic reads a .wks file line by line: a line whose first non-blank
+character is ``#`` is a comment, and every other line is split with
+``shlex.split`` and handed to ``argparse``, after ``${VAR}`` has been
+expanded. The quoting is therefore shell quoting, which is why this
+extends the bash lexer. What the bash lexer cannot do is mark the
+vocabulary: ``part`` is not a shell builtin, so the statement opening
+each line comes out as ordinary text, and so does every ``--option``.
+
+The statements and options below are taken from wic's parser,
+``ksparser.py``, rather than from the manual, so update them from there
+when wic gains one. ``partition`` is not a statement: it was an alias
+while wic bundled pykickstart, and the parser that replaced it in 2016
+kept only ``part``.
+"""
+from pygments.lexer import bygroups, inherit
+from pygments.lexers.shell import BashLexer
+from pygments.token import Comment, Keyword, Name, Text, Whitespace
+
+__version__ = '1.0'
+
+# The subparsers wic registers.
+STATEMENTS = ('part', 'bootloader', 'include')
+
+
+class WksLexer(BashLexer):
+    """wic kickstart."""
+
+    name = 'wic kickstart'
+    aliases = ['wks']
+    filenames = ['*.wks', '*.wks.in']
+    mimetypes = []
+
+    tokens = {
+        'root': [
+            # A statement is only a statement at the start of a line.
+            # Anchoring matters: "include" is also an ordinary word in
+            # "--include-path", and "part" appears inside several option
+            # names, so an unanchored keyword would mark both.
+            (r'^(\s*)(%s)(\b)' % '|'.join(STATEMENTS),
+             bygroups(Whitespace, Keyword, Text)),
+            # Long options carry the meaning on a wic line; bash leaves
+            # them as plain text because it has no notion of them.
+            (r'--[\w-]+', Name.Attribute),
+            # wic tests the first character of the stripped line, so a
+            # comment may be indented and is never trailing.
+            (r'^\s*#.*$', Comment.Single),
+            inherit,
+        ],
+    }
+
+
+def setup(app):
+    app.add_lexer('wks', WksLexer)
+    return {
+        'version': __version__,
+        'parallel_read_safe': True,
+        'parallel_write_safe': True,
+    }
-- 
2.50.0.173.g8b6f19ccfc3a


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 2/2] sphinx: add a lexer for pydevshell sessions
  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 ` Trevor Woerner
  2026-11-27  8:10   ` [docs] " Antonin Godard
  2026-11-27  8:10 ` [docs] [PATCH v2 0/2] sphinx: add lexers for wic kickstart files and " Antonin Godard
  2 siblings, 1 reply; 7+ messages in thread
From: Trevor Woerner @ 2026-11-26 22:36 UTC (permalink / raw)
  To: docs

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 = '... '
+
+
+def setup(app):
+    app.add_lexer('pydevshell', PyDevShellSessionLexer)
+    return {
+        'version': __version__,
+        'parallel_read_safe': True,
+        'parallel_write_safe': True,
+    }
-- 
2.50.0.173.g8b6f19ccfc3a


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [docs] [PATCH v2 0/2] sphinx: add lexers for wic kickstart files and pydevshell sessions
  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 ` Antonin Godard
  2026-11-27 12:03   ` Trevor Woerner
  2 siblings, 1 reply; 7+ messages in thread
From: Antonin Godard @ 2026-11-27  8:10 UTC (permalink / raw)
  To: twoerner, docs

Hi,

On Thu Nov 26, 2026 at 11:36 PM CET, Trevor Woerner via docs wrote:
> Lexers for wic kickstart (.wks) files and for sessions in BitBake's
> Python development shell, which the manuals show and Pygments does not
> cover. No block names either yet, so the rendered manuals do not change.

Thanks! These look good and I've tested them, just one minor comment on patch 2.

In a v3, would you be able to replace the occurrences of wks and pydevshell code
blocks to use your lexers?

Thanks,
Antonin

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [docs] [PATCH v2 2/2] sphinx: add a lexer for pydevshell sessions
  2026-11-26 22:36 ` [PATCH v2 2/2] sphinx: add a lexer for pydevshell sessions Trevor Woerner
@ 2026-11-27  8:10   ` Antonin Godard
  2026-11-27 11:57     ` Trevor Woerner
  0 siblings, 1 reply; 7+ messages in thread
From: Antonin Godard @ 2026-11-27  8:10 UTC (permalink / raw)
  To: twoerner, docs

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?

Antonin

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [docs] [PATCH v2 2/2] sphinx: add a lexer for pydevshell sessions
  2026-11-27  8:10   ` [docs] " Antonin Godard
@ 2026-11-27 11:57     ` Trevor Woerner
  0 siblings, 0 replies; 7+ messages in thread
From: Trevor Woerner @ 2026-11-27 11:57 UTC (permalink / raw)
  To: Antonin Godard; +Cc: docs

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [docs] [PATCH v2 0/2] sphinx: add lexers for wic kickstart files and pydevshell sessions
  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
  0 siblings, 0 replies; 7+ messages in thread
From: Trevor Woerner @ 2026-11-27 12:03 UTC (permalink / raw)
  To: Antonin Godard; +Cc: docs

On Fri 2026-11-27 @ 09:10:31 AM, Antonin Godard wrote:
> Hi,
> 
> On Thu Nov 26, 2026 at 11:36 PM CET, Trevor Woerner via docs wrote:
> > Lexers for wic kickstart (.wks) files and for sessions in BitBake's
> > Python development shell, which the manuals show and Pygments does not
> > cover. No block names either yet, so the rendered manuals do not change.
> 
> Thanks! These look good and I've tested them, just one minor comment on patch 2.
> 
> In a v3, would you be able to replace the occurrences of wks and pydevshell code
> blocks to use your lexers?

Yes, v3 coming up.

In my original plan the "flip" series was rather large and was going to
be sent as one patchset that would flip all of the code-block blocks at
once. I'll add the wks and pydevshell parts now as part of the lexers.

I still need to send a flip patchset as part of the "make bitbake the
default highlight" decision.

> Thanks,
> Antonin

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-11-27 12:03 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox