diff mbox series

[v4,1/3] use a venv for installing packages with pip

Message ID 20260216-fix-make-multi-target-v4-1-749e588cb7f5@cherry.de
State Under Review
Headers show
Series migrate Debian/Ubuntu to pip packages for docs + fix epub and latexpdf targets not finding glob images | expand

Commit Message

Quentin Schulz Feb. 16, 2026, 11:26 a.m. UTC
From: Quentin Schulz <quentin.schulz@cherry.de>

In a few commits, we'll migrate Debian/Ubuntu to use pip packages.
However, Debian rejects pip commands outside of virtual environments.

It is generally best practice to use virtual environments with pip, so
let's migrate distros that currently use pip to use virtual environments
as well.

Because BitBake is a Python project and requires a few Python packages
that we currently install with distro package managers, if we were to
ignore system packages when creating the virtual environment the user
would either be able to build the docs or run BitBake. Let's include the
system packages in the virtual env so that isn't an issue.

Signed-off-by: Quentin Schulz <quentin.schulz@cherry.de>
---
 documentation/tools/containerfiles/Containerfile.dnf    | 6 ++++++
 documentation/tools/containerfiles/Containerfile.zypper | 7 +++++++
 documentation/tools/host_packages_scripts/pip3_docs.sh  | 4 +++-
 3 files changed, 16 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/documentation/tools/containerfiles/Containerfile.dnf b/documentation/tools/containerfiles/Containerfile.dnf
index fd47fde34..01e838ef9 100644
--- a/documentation/tools/containerfiles/Containerfile.dnf
+++ b/documentation/tools/containerfiles/Containerfile.dnf
@@ -9,6 +9,12 @@  ARG PIP3=pip3_docs.sh
 
 ENV TEXTOOLDIR=/opt/docs-build-tex-tools
 ENV PATH="$PATH:$TEXTOOLDIR/tl/bin/x86_64-linux"
+# RUN . /tmp/yocto-venv/bin/activate doesn't work because env variables set in
+# RUN don't persist, so set up the virtualenv manually.
+# Unsetting env variables in Containerfile is difficult, so we hope it works
+# fine without doing that for PYTHONHOME (see activate script content).
+ENV VIRTUAL_ENV=/tmp/yocto-venv
+ENV PATH="$VIRTUAL_ENV/bin:$PATH"
 
 # relative to the location of the dockerfile
 COPY --chmod=777 ${ESSENTIAL} /temp/host_packages_essential.sh
diff --git a/documentation/tools/containerfiles/Containerfile.zypper b/documentation/tools/containerfiles/Containerfile.zypper
index 3850b9ff9..204185efd 100644
--- a/documentation/tools/containerfiles/Containerfile.zypper
+++ b/documentation/tools/containerfiles/Containerfile.zypper
@@ -13,6 +13,13 @@  COPY --chmod=777 ${DOCS} /temp/host_packages_docs.sh
 COPY --chmod=777 ${DOCS_PDF} /temp/host_packages_docs_pdf.sh
 COPY --chmod=777 ${PIP3} /temp/pip3_docs.sh
 
+# RUN . /tmp/yocto-venv/bin/activate doesn't work because env variables set in
+# RUN don't persist, so set up the virtualenv manually.
+# Unsetting env variables in Containerfile is difficult, so we hope it works
+# fine without doing that for PYTHONHOME (see activate script content).
+ENV VIRTUAL_ENV=/tmp/yocto-venv
+ENV PATH="$VIRTUAL_ENV/bin:$PATH"
+
 # Zypper doesn't have environment variables to specify whether to run in
 # non-interactive mode like Debian does with DEBIAN_FRONTEND and piping yes to
 # the scripts doesn't need to be enough as well, so let's force all zypper calls
diff --git a/documentation/tools/host_packages_scripts/pip3_docs.sh b/documentation/tools/host_packages_scripts/pip3_docs.sh
index 907ecec55..9aa7f16fb 100644
--- a/documentation/tools/host_packages_scripts/pip3_docs.sh
+++ b/documentation/tools/host_packages_scripts/pip3_docs.sh
@@ -1 +1,3 @@ 
-sudo pip3 install sphinx sphinx_rtd_theme pyyaml sphinx-copybutton
+python3 -m venv --clear --system-site-packages /tmp/yocto-venv
+. /tmp/yocto-venv/bin/activate
+python3 -m pip install sphinx sphinx_rtd_theme pyyaml sphinx-copybutton