Skip to contentSkip to conversation

Add the sphinx-copybutton extension

PATCH Applied Antonin Godard 1 participant 2 messages Dec 19, 2025 – Jan 5

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Add the sphinx-copybutton extension

This extension adds a copy button to code-blocks.

It was added to the buildtools tarballs for documentation with commit ebf14a6dc1a5 ("python3-sphinx-copybutton: add recipe") in OE-Core, so the the Autobuilder can use it.

Add it as a requirement in the docs, including in Ubuntu requirements. According to https://pkgs.org/download/python3-sphinx-copybutton this packages is provided under "python3-sphinx-copybutton" on all the versions of Ubuntu we support.

---
Changes in v2:
- Suggested by Quentin: set copybutton_prompt_text to "$ " in
conf.py so dollar signs at line beginnings are not copied.
- Link to v1: https://patch.msgid.link/[email protected]

---
 documentation/Pipfile                                    | 1 +
 documentation/conf.py                                    | 4 ++++
 documentation/tools/host_packages_scripts/pip3_docs.sh   | 2 +-
 documentation/tools/host_packages_scripts/ubuntu_docs.sh | 2 +-
 4 files changed, 7 insertions(+), 2 deletions(-)
documentation/Pipfile +1 -0
index 7ee1d22905..1fa2df31e7 100644
@@ -9,6 +9,7 @@ verify_ssl = true
 sphinx = "*"
 sphinx-rtd-theme = "*"
 pyyaml = "*"
+sphinx-copybutton = "*"
 
 [requires]
 python_version = "3"
documentation/conf.py +4 -0
index c07b6c4199..3d04f90572 100644
@@ -66,6 +66,7 @@ extensions = [
     'sphinx.ext.autosectionlabel',
     'sphinx.ext.extlinks',
     'sphinx.ext.intersphinx',
+    'sphinx_copybutton',
     'yocto-vars'
 ]
 autosectionlabel_prefix_document = True
@@ -123,6 +124,9 @@ intersphinx_mapping = {
 # Suppress "WARNING: unknown mimetype for ..."
 suppress_warnings = ['epub.unknown_project_files']
 
+# sphinx-copybutton configuration
+copybutton_prompt_text = "$ "
+
 # -- Options for HTML output -------------------------------------------------
 
 # The theme to use for HTML and HTML Help pages.  See the documentation for
documentation/tools/host_packages_scripts/pip3_docs.sh +1 -1
index fd6ad98053..907ecec55c 100644
@@ -1 +1 @@
-sudo pip3 install sphinx sphinx_rtd_theme pyyaml
+sudo pip3 install sphinx sphinx_rtd_theme pyyaml sphinx-copybutton
documentation/tools/host_packages_scripts/ubuntu_docs.sh +1 -1
index 67bb810946..c322b61e42 100644
@@ -1 +1 @@
-sudo apt install git librsvg2-bin locales make python3-saneyaml python3-sphinx-rtd-theme sphinx
+sudo apt install git librsvg2-bin locales make python3-saneyaml python3-sphinx-rtd-theme python3-sphinx-copybutton sphinx

---
base-commit: d84d916d4fc505e8386693306b6a90b0064c0518
change-id: 20251217-sphinx-copybutton-40e213333b4a

author Applied
#1 lore raw
Quoted 6 lines · Antonin Godard

This extension adds a copy button to code-blocks.

It was added to the buildtools tarballs for documentation with commit ebf14a6dc1a5 ("python3-sphinx-copybutton: add recipe") in OE-Core, so the the Autobuilder can use it.

Quoted 6 lines

Add it as a requirement in the docs, including in Ubuntu requirements. According to https://pkgs.org/download/python3-sphinx-copybutton this packages is provided under "python3-sphinx-copybutton" on all the versions of Ubuntu we support.

[...]

Applied, thanks!

[1/1] Add the sphinx-copybutton extension

      commit: d5fb3c5e262d2c0cfe98f00734f403c2dd6340bc

Best regards,