From nobody Fri Oct 3 12:14:28 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 B823126B95B; Mon, 1 Sep 2025 14:42:37 +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=1756737757; cv=none; b=Rs+CoGHZgfawDP/cpfILw17RYvcFfTwGkuPzfx06lD15fIPqPxVqAdE3KNK1yzuvzhQ6iqkzoBFFvZRjoPOnZ5n0sZh7QuRNyE3uLOuxfgHVS0A/O1WKKqhlhCKn+qKS7iCAHVgTakxa/GunDAVElqh1YTN1sFzO03PYbxrSyt4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756737757; c=relaxed/simple; bh=ZEp9+mn+IvGFaAL1/6SmTvhHmWgFvhI6q4G7xcQM/xs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=sR491C9JvIslnTcSJDadqZXzmodlTdiobLkTjJnJy1WuFRnK1jTNo4Rt4xsHdHyWuMDh3iNiYWFzoU+uSXFRaCY5fCcmHvVJAZHISuX1FJNs7gGb4rWheMf2dUsDo8l35XsP8F1VNtmn/h6RcHMlZzgmdA334rhxu4bIxhgifik= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ikH7m5Em; 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="ikH7m5Em" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69BCBC4CEFE; Mon, 1 Sep 2025 14:42:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756737757; bh=ZEp9+mn+IvGFaAL1/6SmTvhHmWgFvhI6q4G7xcQM/xs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ikH7m5Emu714Nfhi3ZbC9KQHZVFq1oNDyVYPmvlDuOEqzM55TGuFlrmEUuQmsdnxu pj/sVxTc7y968ZSwK++zCgNo9gfVHvgIxV4kQq82WYUuq/OBkk3OjpoUwB9/VbX8RJ jaoQTpLaSe8akbGajBfl8DCGXymD4zYeyViTwT6rguC2mh8muATeublmHsmYrXk9WW bkrBTk5hrHtkachcj4Pb2dZgskvb7RhPG36YMNI+8EF9PfoRMNuMFa4icvoXFUG+x0 4CSRicAzDugMxcjDEFrw1HQ3TqyGAzVXWIJQlqMMPz1D5HUZEktwReCo+u8tKwX19X KMN0CfO/NCKMg== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1ut5jv-00000003G3c-2qSZ; Mon, 01 Sep 2025 16:42:35 +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 v3 08/15] tools/docs: sphinx-build-wrapper: add support to run inside venv Date: Mon, 1 Sep 2025 16:42:24 +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 | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/tools/docs/sphinx-build-wrapper b/tools/docs/sphinx-build-wrap= per index e9c522794fbe..9c5df50fb99d 100755 --- a/tools/docs/sphinx-build-wrapper +++ b/tools/docs/sphinx-build-wrapper @@ -63,6 +63,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 @@ -114,8 +115,9 @@ class SphinxBuilder: =20 return path =20 - def __init__(self, verbose=3DFalse, n_jobs=3DNone): + def __init__(self, venv=3DNone, verbose=3DFalse, n_jobs=3DNone): """Initialize internal variables""" + self.venv =3D venv self.verbose =3D None =20 # @@ -192,6 +194,21 @@ class SphinxBuilder: =20 self.env =3D os.environ.copy() =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 and setting @@ -206,7 +223,10 @@ class SphinxBuilder: =20 cmd =3D [] =20 - cmd.append(sys.executable) + if self.venv: + cmd.append("python") + else: + cmd.append(sys.executable) =20 cmd.append(sphinx_build) =20 @@ -528,11 +548,16 @@ def main(): parser.add_argument('-j', '--jobs', type=3Djobs_type, help=3D"Sets number of jobs to use with sphinx-bui= ld") =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) =20 - builder =3D SphinxBuilder(verbose=3Dargs.verbose, n_jobs=3Dargs.jobs) + builder =3D SphinxBuilder(venv=3Dargs.venv, verbose=3Dargs.verbose, + n_jobs=3Dargs.jobs) =20 builder.build(args.target, sphinxdirs=3Dargs.sphinxdirs, conf=3Dargs.c= onf, theme=3Dargs.theme, css=3Dargs.css, paper=3Dargs.paper) --=20 2.51.0