From nobody Wed Oct 8 09:26:47 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 D4CBB23FC41; Mon, 30 Jun 2025 21:52:44 +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=1751320364; cv=none; b=EAvc9/1vb0yzabJ4JThs2tq5c1AYf0SlyI056CbdMIFI6R1IR5HQgyrnFclgkw6cYquXJWEac6aWiAYSzNM1AAk2GNkTvLxLMO/tzRQUHHhq3Ag84TJGzH927b81kULsWR/UP77tFCe8dbfq1KKBsdOl+gdQMZzl5fs3MykBHKg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751320364; c=relaxed/simple; bh=QjBAfeS5DM8omDHphHQWuNNvVBS8lHexNOTGjOEFji8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DToYzX3brD+zAk0BRZqnBLBO05PCmxsN0ijwfuVAi6NRANTR8E66Mwv8y4DsU0r/LE6D/GhU6puBmcV3iybHujGyUxHmYf+idUm4ApS8y3u4FlItMUXYbXhiSl7lixESPML2ffgN6mIZHgOoWQBkElVtr0esSVyPOrEGftu32Lc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Pq6PCBZb; 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="Pq6PCBZb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 58B2CC4CEF5; Mon, 30 Jun 2025 21:52:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751320364; bh=QjBAfeS5DM8omDHphHQWuNNvVBS8lHexNOTGjOEFji8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Pq6PCBZbsdYW240cehsEjxo41vfA2bdxPjwxIV2KQxOn7ctwElPjO3twlSSmYyhPy 4vsG7HFfAaTXRHHnJUhaJaGGQKIgtw+2jJVivpEPToCYf+mA8B2FN+8YrvlY87hR20 RqOnYtgLGxPPL064S9Yt2mnKAEfY0hMiklaT2rDZbsWs3XdGH8E6yM1MUXQzIOMGCU 425FkfaH4MntHNW1OTnZ0nSlmICMcy03BUw06hsnN9TTm9YeBUgNEVvF+Tsnn9OdBt JWC8QozYZAfHQIJytPbTH91EoZMNR2oLQiff1ccWysW+xmZ80UPA1BxVYfB0jRKJck 6jXFdTHGHJ7sg== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uWMQc-00000003QWZ-22Q1; Mon, 30 Jun 2025 23:52:42 +0200 From: Mauro Carvalho Chehab To: Linux Doc Mailing List , Jonathan Corbet Cc: Mauro Carvalho Chehab , "Akira Yokosawa" , "Mauro Carvalho Chehab" , "Sai Vishnu M" , linux-kernel@vger.kernel.org Subject: [PATCH 05/15] scripts: sphinx-pre-install: run on a supported version Date: Mon, 30 Jun 2025 23:34:53 +0200 Message-ID: X-Mailer: git-send-email 2.50.0 In-Reply-To: References: 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 Content-Type: text/plain; charset="utf-8" The scripts/sphinx-pre-install is used to detect problems at the system environment and adjust it to build the Kernel documentation. If the version is too old, it won't run, though. Check if the version which started the script is valid. If not, seek for a new one that is compatible with documentation build. Signed-off-by: Mauro Carvalho Chehab --- scripts/sphinx-pre-install.py | 65 ++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/scripts/sphinx-pre-install.py b/scripts/sphinx-pre-install.py index 71d86b230b22..3912359d2bae 100755 --- a/scripts/sphinx-pre-install.py +++ b/scripts/sphinx-pre-install.py @@ -5,6 +5,9 @@ # pylint: disable=3DC0103,C0114,C0115,C0116,C0301 # pylint: disable=3DR0902,R0904,R0912,R0915,R1705,R1710,E1121 =20 +# Note: this script requires at least Python 3.6 to run. +# Don't add changes not compatible with it, it is meant to report +# incompatible python versions. =20 import argparse import os @@ -16,7 +19,6 @@ from glob import glob =20 def parse_version(version): """Convert a major.minor.patch version into a tuple""" -# return tuple(int(x) for x in version.split(".")) =20 =20 @@ -27,6 +29,7 @@ def ver_str(version): =20 =20 RECOMMENDED_VERSION =3D parse_version("3.4.3") +MIN_PYTHON_VERSION =3D parse_version("3.7") =20 =20 class SphinxDependencyChecker: @@ -132,6 +135,65 @@ class SphinxDependencyChecker: # Python not found at the PATH return python_names[-1] =20 + @staticmethod + def get_python_version(cmd): + + result =3D SphinxDependencyChecker.run([cmd, "--version"], + capture_output=3DTrue, text=3D= True) + version =3D result.stdout.strip() + + match =3D re.search(r"(\d+\.\d+\.\d+)", version) + if match: + return parse_version(match.group(1)) + + print(f"Can't parse version {version}") + return (0, 0, 0) + + @staticmethod + def find_python(): + + patterns =3D [ + "python3.[0-9]", + "python3.[0-9][0-9]", + ] + + new_python_cmd =3D None + + # Seek for a python binary newer than MIN_PYTHON_VERSION + for path in os.getenv("PATH", "").split(":"): + for pattern in patterns: + for cmd in glob(os.path.join(path, pattern)): + if os.path.isfile(cmd) and os.access(cmd, os.X_OK): + version =3D SphinxDependencyChecker.get_python_ver= sion(cmd) + if version >=3D MIN_PYTHON_VERSION: + return(cmd) + + @staticmethod + def check_python(): + + cur_ver =3D sys.version_info[:3] + if cur_ver >=3D MIN_PYTHON_VERSION: + return + + python_ver =3D ver_str(cur_ver) + + new_python_cmd =3D SphinxDependencyChecker.find_python() + if not new_python_cmd: + print(f"ERROR: Python version {python_ver} is not spported any= more") + print(f" Can't find a new version. This script may fail") + return + + # Restart script using the newer version + script_path =3D os.path.abspath(sys.argv[0]) + args =3D [new_python_cmd, script_path] + sys.argv[1:] + + print(f"Python {python_ver} not supported. Changing to {new_python= _cmd}") + + try: + os.execv(new_python_cmd, args) + except OSError as e: + sys.exit(f"Failed to restart with {new_python_cmd}: {e}") + @staticmethod def run(*args, **kwargs): """Excecute a command, hiding its output by default""" @@ -1107,6 +1169,7 @@ def main(): =20 checker =3D SphinxDependencyChecker(args) =20 + checker.check_python() checker.check_needs() =20 =20 --=20 2.50.0