* [PATCH v3 0/4] sphinx: add lexers for wic kickstart files and pydevshell sessions
@ 2026-11-27 12:05 Trevor Woerner
2026-11-27 12:05 ` [PATCH v3 1/4] sphinx: add a lexer for wic kickstart files Trevor Woerner
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Trevor Woerner @ 2026-11-27 12:05 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, and the changes that tag the manuals' examples to use them.
changes in v3:
- tag the existing kickstart and pydevshell examples with the new lexers
- make the pydevshell lexer recognise the "... " continuation prompt
changes in v2:
- keep only these two lexers
- rebase on master
Trevor Woerner (4):
sphinx: add a lexer for wic kickstart files
docs: use the wks lexer for the kickstart examples
sphinx: add a lexer for pydevshell sessions
dev-manual: use the pydevshell lexer for the session example
documentation/conf.py | 4 +-
.../dev-manual/python-development-shell.rst | 4 +-
documentation/dev-manual/wic.rst | 6 +-
documentation/ref-manual/kickstart.rst | 16 +++--
documentation/ref-manual/variables.rst | 8 ++-
documentation/sphinx/pydevshell-lexer.py | 51 ++++++++++++++++
documentation/sphinx/wks-lexer.py | 60 +++++++++++++++++++
7 files changed, 136 insertions(+), 13 deletions(-)
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] 5+ messages in thread
* [PATCH v3 1/4] sphinx: add a lexer for wic kickstart files
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 ` Trevor Woerner
2026-11-27 12:05 ` [PATCH v3 2/4] docs: use the wks lexer for the kickstart examples Trevor Woerner
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Trevor Woerner @ 2026-11-27 12:05 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 v3:
- no change
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] 5+ messages in thread
* [PATCH v3 2/4] docs: use the wks lexer for the kickstart examples
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 ` Trevor Woerner
2026-11-27 12:05 ` [PATCH v3 3/4] sphinx: add a lexer for pydevshell sessions Trevor Woerner
2026-11-27 12:05 ` [PATCH v3 4/4] dev-manual: use the pydevshell lexer for the session example Trevor Woerner
3 siblings, 0 replies; 5+ messages in thread
From: Trevor Woerner @ 2026-11-27 12:05 UTC (permalink / raw)
To: docs
The wic kickstart examples in the manuals are tagged shell or text, or
left to the default language. Tag them wks so their statements and
options are highlighted as kickstart.
AI-Generated: codex/claude-opus 5.5 (xhigh)
Signed-off-by: Trevor Woerner <twoerner@gmail.com>
---
changes in v3:
- new: tag the kickstart examples wks, as asked in review
---
documentation/dev-manual/wic.rst | 6 +++---
documentation/ref-manual/kickstart.rst | 16 ++++++++++------
documentation/ref-manual/variables.rst | 8 ++++++--
3 files changed, 19 insertions(+), 11 deletions(-)
diff --git a/documentation/dev-manual/wic.rst b/documentation/dev-manual/wic.rst
index 85160bbdf1a0..07e165abeb11 100644
--- a/documentation/dev-manual/wic.rst
+++ b/documentation/dev-manual/wic.rst
@@ -343,7 +343,7 @@ Mode that uses the ``directdisk`` file:
Here are the actual partition language commands used in the
``genericx86.wks`` file to generate an image:
-.. code-block:: shell
+.. code-block:: wks
# short-description: Create an EFI disk image for genericx86*
# long-description: Creates a partitioned EFI disk image for genericx86* machines
@@ -403,7 +403,7 @@ implementation, it looks for the plugin with the same name as the
partition. For example, if the partition is set up using the following
command in a kickstart file:
-.. code-block:: shell
+.. code-block:: wks
part /boot --source bootimg_pcbios --ondisk sda --label boot --active --align 1024
@@ -598,7 +598,7 @@ changes all instances of "``--ondisk sda``" to "``--ondisk sdb``". The
example changes the following two lines and leaves the remaining lines
untouched:
-.. code-block:: shell
+.. code-block:: wks
part /boot --source bootimg_pcbios --ondisk sdb --label boot --active --align 1024
part / --source rootfs --ondisk sdb --fstype=ext4 --label platform --align 1024 --use-uuid
diff --git a/documentation/ref-manual/kickstart.rst b/documentation/ref-manual/kickstart.rst
index 8d5e9f317b06..c2b7d6aa1102 100644
--- a/documentation/ref-manual/kickstart.rst
+++ b/documentation/ref-manual/kickstart.rst
@@ -57,7 +57,9 @@ Command: part
-------------
This command creates a partition on the system and uses the
-following syntax::
+following syntax:
+
+.. code-block:: wks
part [mntpoint]
@@ -85,7 +87,9 @@ must also provide one of the ``--ondrive``, ``--ondisk``, or
be disabled in custom configurations.
Here is an example that uses "/" as the mountpoint. The command uses
-``--ondisk`` to force the partition onto the ``sdb`` disk::
+``--ondisk`` to force the partition onto the ``sdb`` disk:
+
+.. code-block:: wks
part / --source rootfs --ondisk sdb --fstype=ext3 --label platform --align 1024
@@ -275,7 +279,7 @@ The ``include`` directive can be used to include a WKS file into another. The
only argument to this command is the path to the file to include, relative to
the current file. For example:
-.. code-block:: shell
+.. code-block:: wks
include common.wks.inc
@@ -298,7 +302,7 @@ variable expansion mechanism:
:term:`wic` command-line utility, not :term:`BitBake`. However, the syntax to
reference these variables is the same. For example:
- .. code-block:: text
+ .. code-block:: wks
:caption: Snippet from ``mkefidisk.wks``
bootloader --ptable gpt --timeout=5 --append="rootfstype=ext4 console=${KERNEL_CONSOLE} console=tty0"
@@ -321,7 +325,7 @@ variable expansion mechanism:
This means that the :term:`WICVARS` list has no effect anymore: those
variables are expanded by :term:`BitBake` directly. For example:
- .. code-block:: text
+ .. code-block:: wks
:caption: Snippet from ``efi-uki-bootdisk.wks.in``
part /boot --source bootimg_efi --sourceparams="loader=${EFI_PROVIDER}" --label boot --active ...
@@ -331,7 +335,7 @@ variable expansion mechanism:
This also means that ``.wks.in`` files can contain inline Python expressions.
Here is a made up example:
- .. code-block:: text
+ .. code-block:: wks
part / --source rootfs --fstype=ext4 --label root --align ${@4 * 1024} --size 5G
diff --git a/documentation/ref-manual/variables.rst b/documentation/ref-manual/variables.rst
index 2e01d04228ce..15ff5be2380a 100644
--- a/documentation/ref-manual/variables.rst
+++ b/documentation/ref-manual/variables.rst
@@ -4318,7 +4318,9 @@ system and gives an overview of their function and contents.
You can also specify the target by label, UUID or partition name if multiple
extra partitions coexist. Let's take the following example. This would be
- the WKS file for the image currently being built::
+ the WKS file for the image currently being built:
+
+ .. code-block:: wks
part --source extra_partition --fstype=ext4 --label foo
part --source extra_partition --fstype=ext4 --uuid e7d0824e-cda3-4bed-9f54-9ef5312d105d
@@ -12173,7 +12175,9 @@ system and gives an overview of their function and contents.
The resulting binary can be flashed using :doc:`WIC </dev-manual/wic>` or
any other flashing method at the environment offset, overriding any
existing environment if one is present. Below is an example of a WKS file
- to flash the binary::
+ to flash the binary:
+
+ .. code-block:: wks
part --source rawcopy --sourceparams="file=u-boot-initial-env-sd.bin" --ondisk sda --no-table --offset 4096k
--
2.50.0.173.g8b6f19ccfc3a
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v3 3/4] sphinx: add a lexer for pydevshell sessions
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
2026-11-27 12:05 ` [PATCH v3 4/4] dev-manual: use the pydevshell lexer for the session example Trevor Woerner
3 siblings, 0 replies; 5+ messages in thread
From: Trevor Woerner @ 2026-11-27 12:05 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 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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v3 4/4] dev-manual: use the pydevshell lexer for the session example
2026-11-27 12:05 [PATCH v3 0/4] sphinx: add lexers for wic kickstart files and pydevshell sessions Trevor Woerner
` (2 preceding siblings ...)
2026-11-27 12:05 ` [PATCH v3 3/4] sphinx: add a lexer for pydevshell sessions Trevor Woerner
@ 2026-11-27 12:05 ` Trevor Woerner
3 siblings, 0 replies; 5+ messages in thread
From: Trevor Woerner @ 2026-11-27 12:05 UTC (permalink / raw)
To: docs
The pydevshell session example is left to the default language. Tag it
pydevshell so the prompt and the Python typed at it are highlighted, and
the results are not.
AI-Generated: codex/claude-opus 5.5 (xhigh)
Signed-off-by: Trevor Woerner <twoerner@gmail.com>
---
changes in v3:
- new: tag the session example pydevshell, as asked in review
---
documentation/dev-manual/python-development-shell.rst | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/documentation/dev-manual/python-development-shell.rst b/documentation/dev-manual/python-development-shell.rst
index 034100ae8799..76167f5bacf4 100644
--- a/documentation/dev-manual/python-development-shell.rst
+++ b/documentation/dev-manual/python-development-shell.rst
@@ -13,7 +13,9 @@ specified target. Then a new terminal is opened. Additionally, key
Python objects and code are available in the same way they are to
BitBake tasks, in particular, the data store 'd'. So, commands such as
the following are useful when exploring the data store and running
-functions::
+functions:
+
+.. code-block:: pydevshell
pydevshell> d.getVar("STAGING_DIR")
'/media/build1/bitbake-builds/build/tmp/sysroots'
--
2.50.0.173.g8b6f19ccfc3a
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-27 12:05 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH v3 3/4] sphinx: add a lexer for pydevshell sessions Trevor Woerner
2026-11-27 12:05 ` [PATCH v3 4/4] dev-manual: use the pydevshell lexer for the session example Trevor Woerner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox