From nobody Thu Oct 2 19:30:09 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 B61F1301012; Fri, 12 Sep 2025 11:46:34 +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=1757677594; cv=none; b=NSWBtYkO74blGD5vRjTQH3H2dPBmxWs/dkFVTeQccIruJVlDmzev1gjY0S6BqcnAczNDVmre+bTIaASvORoU2mEbImjkgiiBL0TN20r/NvzowjdWftL23vx+IXLekEGxWyXGoymjyqhS83EQCm1GXIl8b5+LfCtacy0nnqibeGE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757677594; c=relaxed/simple; bh=GdJwj3d3TAyo2Nn7d6rWe+07TNA7IyqQabnELNUF9QU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=tWDSJ5slI+UMx79Avgazbj2JqKb9z9T984COdz1/OoVZ4HbGA3clqAQy2GQmx8aKzlWJg+gMYsRnpo71rCRB9elP/lXSSe1J7iLV7l9K5iLIQ9sdhcGs6CGZQOUkKtem0w4aAkYTTjrsTsu7epPoMR83gCWabhVE9iWJDQpIdL0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Iohms2ZV; 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="Iohms2ZV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6B327C4CEFE; Fri, 12 Sep 2025 11:46:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1757677594; bh=GdJwj3d3TAyo2Nn7d6rWe+07TNA7IyqQabnELNUF9QU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Iohms2ZVziu9HVCHUO/dMqC27ubsm31fr9cCKQdtBpwDn0PIjD5u4lEokaQbOlgo1 xPq/8CKmyJvmYWiPUPis91JDl40so1yyS4ZkBNPEaHqCw9/qrR/LvpMa5uPW6ZUa4f otllbwPAydd8LJyLKewkRLPCI3UwDZP6TRtXVCNUlRu+VpjGZxAXksVfV6APu8HgHC juD+V/ggwajEZYkvzDE5d99KHKNEu/uCh6P5uvZLG5kJQYTOvRGq25gk59xb/kxkJ4 J88kMurM1jV4Pt5fk4gNi9k6h9xVcaXbCH/AGqaG/92tQ9Eld+EP259OjiPb7jjARp eATLATzj2D2EQ== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1ux2Ea-00000008RsL-2lHZ; Fri, 12 Sep 2025 13:46:32 +0200 From: Mauro Carvalho Chehab To: Linux Doc Mailing List Cc: Mauro Carvalho Chehab , Jonathan Corbet , Mauro Carvalho Chehab , linux-kernel@vger.kernel.org Subject: [PATCH v5 07/18] tools/docs: python_version: allow check for alternatives and bail out Date: Fri, 12 Sep 2025 13:46:14 +0200 Message-ID: <9401133759841f7ecb84e6d12f66b5974513dece.1757677427.git.mchehab+huawei@kernel.org> 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 The caller script may not want an automatic execution of the new version. Add two parameters to allow showing alternatives and to bail out if version is incompatible. Signed-off-by: Mauro Carvalho Chehab --- tools/docs/lib/python_version.py | 43 ++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/tools/docs/lib/python_version.py b/tools/docs/lib/python_versi= on.py index 660bfe7d23fa..a9fda2470a26 100644 --- a/tools/docs/lib/python_version.py +++ b/tools/docs/lib/python_version.py @@ -85,10 +85,12 @@ class PythonVersion: may need to update it one day, hopefully on a distant future. """ patterns =3D [ - "python3.[0-9]", "python3.[0-9][0-9]", + "python3.[0-9]", ] =20 + python_cmd =3D [] + # Seek for a python binary newer than min_version for path in os.getenv("PATH", "").split(":"): for pattern in patterns: @@ -96,12 +98,13 @@ class PythonVersion: if os.path.isfile(cmd) and os.access(cmd, os.X_OK): version =3D PythonVersion.get_python_version(cmd) if version >=3D min_version: - return cmd + python_cmd.append((version, cmd)) =20 - return None + return sorted(python_cmd, reverse=3DTrue) =20 @staticmethod - def check_python(min_version): + def check_python(min_version, show_alternatives=3DFalse, bail_out=3DFa= lse, + success_on_error=3DFalse): """ Check if the current python binary satisfies our minimal requireme= nt for Sphinx build. If not, re-run with a newer version if found. @@ -113,18 +116,42 @@ class PythonVersion: =20 python_ver =3D PythonVersion.ver_str(cur_ver) =20 - new_python_cmd =3D PythonVersion.find_python(min_version) - if not new_python_cmd: + available_versions =3D PythonVersion.find_python(min_version) + if not available_versions: print(f"ERROR: Python version {python_ver} is not spported any= more\n") print(" Can't find a new version. This script may fail") return =20 - # 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:] + + # Check possible alternatives + if available_versions: + new_python_cmd =3D available_versions[0][1] + else: + new_python_cmd =3D None + + if show_alternatives: + print("You could run, instead:") + for _, cmd in available_versions: + args =3D [cmd, script_path] + sys.argv[1:] + + cmd_str =3D " ".join(args) + print(f" {cmd_str}") + print() + + if bail_out: + msg =3D f"Python {python_ver} not supported. Bailing out" + if success_on_error: + print(msg, file=3Dsys.stderr) + sys.exit(0) + else: + sys.exit(msg) =20 print(f"Python {python_ver} not supported. Changing to {new_python= _cmd}") =20 + # Restart script using the newer version + args =3D [new_python_cmd, script_path] + sys.argv[1:] + try: os.execv(new_python_cmd, args) except OSError as e: --=20 2.51.0