From nobody Thu Oct 2 14:25:54 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 382E23074AC; Tue, 16 Sep 2025 10:23:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758018219; cv=none; b=uQ06tAaOyk0IMQKj2sENsocITUsaHKxjKVULZKShQjWtkdOgsiz+RFchK8LcSk5/FY3hM70lhXS3NWMQVV5UXPIDCpJJFHV8m3z5ErJmkWvRL6DSBKU5i56nfltcEYgbVQESjaaaGPyKr3c0DQn2CgMUOKuX7deUI/2QUprMfMM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758018219; c=relaxed/simple; bh=bnuRSZ5VgKW9EMMlXkntotHnx/AGBzkicE3rznCRcFo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=CL4SvJHTeqRXQ8ZSSu6hxOFnYV9Ujr//3K33DNevpYlaTa3ewUK5cbSnTgcct68ssrM0v3zKWbm3fgpmketln9U6HbcB25fiJs8mXenwclDTF8d1WJrvCLbYubiQB0VXnPm/E73gOom4YreuMLImZUskBaCe+SNvqGlfNpRGkpw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jRb5xgl7; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jRb5xgl7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1C258C4CEFC; Tue, 16 Sep 2025 10:23:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758018219; bh=bnuRSZ5VgKW9EMMlXkntotHnx/AGBzkicE3rznCRcFo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jRb5xgl7PPXB7EK9MnwOf50HWPqF+ocDRYlkoxRCNngylzFiMF9qxFcSEl7IlK4KM xBJJpM614AGPB5eOK82A3H9GXAbo5pUGG8+DomfsJ7lDOmK8HtSJW5x0fGlEaQbANP fjoYXOSvXgXrrU9XI67Yv+FFupqUI4pwlOSDTaoxlXvugDd0uU6OLes/ekhFKFxGw5 eT/AzIgIIPcRci7mVxHinPJ0scPUCXwFzKYq+yZPZl68Xz23AnHBCn+XMpQ313Hp2F 6SO7vdrVXmAbtKZ9SlUvRTRSgJR4mkcQkQjiDprV/0dp7Kwtw2dp024CV7e30UpwIM ozCVBbbtMGd5A== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uySqT-0000000BBQA-1IE7; Tue, 16 Sep 2025 12:23:33 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , Mauro Carvalho Chehab , linux-kernel@vger.kernel.org Subject: [PATCH v6 21/21] tools/docs: sphinx-build-wrapper: add support to run inside venv Date: Tue, 16 Sep 2025 12:22:57 +0200 Message-ID: X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Content-Type: text/plain; charset="utf-8" Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: Mauro Carvalho Chehab 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 --- 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-wrap= per 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: dis= able=3DC0413,C0411,E0401 # # Some constants # +VENV_DEFAULT =3D "sphinx_latest" MIN_PYTHON_VERSION =3D PythonVersion("3.7").version PAPER =3D ["", "a4", "letter"] =20 @@ -179,8 +180,10 @@ class SphinxBuilder: if not verbose: self.sphinxopts +=3D ["-q"] =20 - def __init__(self, builddir, verbose=3DFalse, n_jobs=3DNone, interacti= ve=3DNone): + def __init__(self, builddir, venv=3DNone, verbose=3DFalse, n_jobs=3DNo= ne, + interactive=3DNone): """Initialize internal variables""" + self.venv =3D venv self.verbose =3D None =20 # @@ -230,6 +233,21 @@ class SphinxBuilder: =20 self.get_sphinx_extra_opts(n_jobs) =20 + # + # If venv command line argument is specified, run Sphinx from venv + # + if venv: + bin_dir =3D 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"] =3D bin_dir + ":" + self.env["PATH"] + self.env["VIRTUAL_ENV"] =3D 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 =3D str(self.n_jobs) =20 - cmd =3D [sys.executable, sphinx_build] + if self.venv: + cmd =3D ["python"] + else: + cmd =3D [sys.executable,] + + cmd +=3D [sphinx_build] cmd +=3D [f"-j{n_jobs}"] cmd +=3D self.sphinxopts cmd +=3D build_args @@ -748,12 +771,16 @@ def main(): parser.add_argument('-i', '--interactive', action=3D'store_true', help=3D"Change latex default to run in interactive= mode") =20 + parser.add_argument("-V", "--venv", nargs=3D'?', const=3Df'{VENV_DEFAU= LT}', + default=3DNone, + help=3Df'If used, run Sphinx from a venv dir (defa= ult dir: {VENV_DEFAULT})') + args =3D parser.parse_args() =20 PythonVersion.check_python(MIN_PYTHON_VERSION, show_alternatives=3DTru= e, bail_out=3DTrue) =20 - builder =3D SphinxBuilder(builddir=3Dargs.builddir, + builder =3D SphinxBuilder(builddir=3Dargs.builddir, venv=3Dargs.venv, verbose=3Dargs.verbose, n_jobs=3Dargs.jobs, interactive=3Dargs.interactive) =20 --=20 2.51.0