[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <da30965e88d5b3ec6a69414b6d19546ee7f0e24a.1758018030.git.mchehab+huawei@kernel.org>
Date: Tue, 16 Sep 2025 12:22:57 +0200
From: Mauro Carvalho Chehab <mchehab+huawei@...nel.org>
To: Jonathan Corbet <corbet@....net>,
Linux Doc Mailing List <linux-doc@...r.kernel.org>
Cc: Mauro Carvalho Chehab <mchehab+huawei@...nel.org>,
Mauro Carvalho Chehab <mchehab+huawei@...nel.org>,
linux-kernel@...r.kernel.org
Subject: [PATCH v6 21/21] tools/docs: sphinx-build-wrapper: add support to run inside venv
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@...nel.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 90ad0b22b472..b611dbe250f9 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"]
@@ -179,8 +180,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
#
@@ -230,6 +233,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.
@@ -264,7 +282,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
@@ -748,12 +771,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
Powered by blists - more mailing lists