From: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
To: Jonathan Corbet <corbet@lwn.net>,
Linux Doc Mailing List <linux-doc@vger.kernel.org>
Cc: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>,
"Akira Yokosawa" <akiyks@gmail.com>,
"Mauro Carvalho Chehab" <mchehab+huawei@kernel.org>,
linux-kernel@vger.kernel.org
Subject: [PATCH v7 24/24] tools/docs: sphinx-build-wrapper: add support to run inside venv
Date: Wed, 17 Sep 2025 14:15:18 +0200 [thread overview]
Message-ID: <8372cc28d0f91a133da98c5cb8b005c3dbffdc23.1758111077.git.mchehab+huawei@kernel.org> (raw)
In-Reply-To: <cover.1758111077.git.mchehab+huawei@kernel.org>
Sometimes, it is desired to run Sphinx from a virtual environment.
Add a command line parameter to automatically build Sphinx from
such environment.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
tools/docs/sphinx-build-wrapper | 33 ++++++++++++++++++++++++++++++---
1 file changed, 30 insertions(+), 3 deletions(-)
diff --git a/tools/docs/sphinx-build-wrapper b/tools/docs/sphinx-build-wrapper
index 103b0044bb0b..6ed3d58ec277 100755
--- a/tools/docs/sphinx-build-wrapper
+++ b/tools/docs/sphinx-build-wrapper
@@ -69,6 +69,7 @@ from jobserver import JobserverExec # pylint: disable=C0413,C0411,E0401
#
# Some constants
#
+VENV_DEFAULT = "sphinx_latest"
MIN_PYTHON_VERSION = PythonVersion("3.7").version
PAPER = ["", "a4", "letter"]
@@ -171,8 +172,10 @@ class SphinxBuilder:
if not verbose:
self.sphinxopts += ["-q"]
- def __init__(self, builddir, verbose=False, n_jobs=None, interactive=None):
+ def __init__(self, builddir, venv=None, verbose=False, n_jobs=None,
+ interactive=None):
"""Initialize internal variables"""
+ self.venv = venv
self.verbose = None
#
@@ -220,6 +223,21 @@ class SphinxBuilder:
self.get_sphinx_extra_opts(n_jobs)
+ #
+ # If venv command line argument is specified, run Sphinx from venv
+ #
+ if venv:
+ bin_dir = os.path.join(venv, "bin")
+ if not os.path.isfile(os.path.join(bin_dir, "activate")):
+ sys.exit(f"Venv {venv} not found.")
+
+ # "activate" virtual env
+ self.env["PATH"] = bin_dir + ":" + self.env["PATH"]
+ self.env["VIRTUAL_ENV"] = venv
+ if "PYTHONHOME" in self.env:
+ del self.env["PYTHONHOME"]
+ print(f"Setting venv to {venv}")
+
def run_sphinx(self, sphinx_build, build_args, *args, **pwargs):
"""
Executes sphinx-build using current python3 command.
@@ -254,7 +272,12 @@ class SphinxBuilder:
if self.n_jobs:
n_jobs = str(self.n_jobs)
- cmd = [sys.executable, sphinx_build]
+ if self.venv:
+ cmd = ["python"]
+ else:
+ cmd = [sys.executable,]
+
+ cmd += [sphinx_build]
cmd += [f"-j{n_jobs}"]
cmd += self.sphinxopts
cmd += build_args
@@ -772,12 +795,16 @@ def main():
parser.add_argument('-i', '--interactive', action='store_true',
help="Change latex default to run in interactive mode")
+ parser.add_argument("-V", "--venv", nargs='?', const=f'{VENV_DEFAULT}',
+ default=None,
+ help=f'If used, run Sphinx from a venv dir (default dir: {VENV_DEFAULT})')
+
args = parser.parse_args()
PythonVersion.check_python(MIN_PYTHON_VERSION, show_alternatives=True,
bail_out=True)
- builder = SphinxBuilder(builddir=args.builddir,
+ builder = SphinxBuilder(builddir=args.builddir, venv=args.venv,
verbose=args.verbose, n_jobs=args.jobs,
interactive=args.interactive)
--
2.51.0
prev parent reply other threads:[~2025-09-17 12:15 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-17 12:14 [PATCH v7 00/24] Split sphinx call logic from docs Makefile Mauro Carvalho Chehab
2025-09-17 12:14 ` [PATCH v7 01/24] scripts/jobserver-exec: move the code to a class Mauro Carvalho Chehab
2025-09-17 12:14 ` [PATCH v7 02/24] scripts/jobserver-exec: move its class to the lib directory Mauro Carvalho Chehab
2025-09-17 12:14 ` [PATCH v7 03/24] scripts/jobserver-exec: add a help message Mauro Carvalho Chehab
2025-09-17 12:14 ` [PATCH v7 04/24] scripts: check-variable-fonts.sh: convert to Python Mauro Carvalho Chehab
2025-09-17 12:14 ` [PATCH v7 05/24] tools/docs: check-variable-fonts.py: split into a lib and an exec file Mauro Carvalho Chehab
2025-09-17 12:15 ` [PATCH v7 06/24] check-variable-fonts.py: add a helper to display instructions Mauro Carvalho Chehab
2025-09-17 12:15 ` [PATCH v7 07/24] scripts: sphinx-pre-install: move it to tools/docs Mauro Carvalho Chehab
2025-09-17 12:15 ` [PATCH v7 08/24] tools/docs: sphinx-pre-install: drop a debug print Mauro Carvalho Chehab
2025-09-17 12:15 ` [PATCH v7 09/24] tools/docs: sphinx-pre-install: allow check for alternatives and bail out Mauro Carvalho Chehab
2025-09-17 12:15 ` [PATCH v7 10/24] tools/docs: python_version: move version check from sphinx-pre-install Mauro Carvalho Chehab
2025-09-17 12:15 ` [PATCH v7 11/24] tools/docs: sphinx-build-wrapper: add a wrapper for sphinx-build Mauro Carvalho Chehab
2025-09-18 12:07 ` Akira Yokosawa
2025-09-18 13:58 ` Mauro Carvalho Chehab
2025-09-17 12:15 ` [PATCH v7 12/24] docs: parallel-wrapper.sh: remove script Mauro Carvalho Chehab
2025-09-17 12:15 ` [PATCH v7 13/24] docs: Makefile: document latex/PDF PAPER= parameter Mauro Carvalho Chehab
2025-09-17 12:15 ` [PATCH v7 14/24] docs: Makefile: document FONTS_CONF_DENY_VF= parameter Mauro Carvalho Chehab
2025-09-17 12:15 ` [PATCH v7 15/24] tools/docs: sphinx-build-wrapper: add an argument for LaTeX interactive mode Mauro Carvalho Chehab
2025-09-17 12:15 ` [PATCH v7 16/24] tools/docs: sphinx-build-wrapper: allow building PDF files in parallel Mauro Carvalho Chehab
2025-09-17 12:15 ` [PATCH v7 17/24] tools/docs,scripts: sphinx-*: prevent sphinx-build crashes Mauro Carvalho Chehab
2025-09-17 12:15 ` [PATCH v7 18/24] tools/docs: sphinx-build-wrapper: Fix output for duplicated names Mauro Carvalho Chehab
2025-09-17 12:15 ` [PATCH v7 19/24] docs: add support to build manpages from kerneldoc output Mauro Carvalho Chehab
2025-09-17 12:15 ` [PATCH v7 20/24] tools: kernel-doc: add a see also section at man pages Mauro Carvalho Chehab
2025-09-17 12:15 ` [PATCH v7 21/24] scripts: kdoc_parser.py: warn about Python version only once Mauro Carvalho Chehab
2025-09-17 12:15 ` [PATCH v7 22/24] tools/docs: sphinx-build-wrapper: move rust doc builder to wrapper Mauro Carvalho Chehab
2025-09-17 12:15 ` [PATCH v7 23/24] tools/docs: sphinx-* break documentation bulds on openSUSE Mauro Carvalho Chehab
2025-09-17 12:15 ` Mauro Carvalho Chehab [this message]
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=8372cc28d0f91a133da98c5cb8b005c3dbffdc23.1758111077.git.mchehab+huawei@kernel.org \
--to=mchehab+huawei@kernel.org \
--cc=akiyks@gmail.com \
--cc=corbet@lwn.net \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®