From nobody Thu Oct 9 02:55:50 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 70A20271442; Sat, 21 Jun 2025 19:56:01 +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=1750535761; cv=none; b=uHeAOGQtKKl/Yf68gJffVe+K1fsaHwhzRMDSvH2q1D4CgueFMuidpyL8cI477L1LzqrPdOChZ5oEAWKGysjcZdh18mr7R9Cuge0SOGKH8SPhKUmICeDNK9eP1o3OhVu8kzZpAgl91dcDfZQr7vbXaGsr3Pf4b7uVRxcUCBXYM2c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750535761; c=relaxed/simple; bh=wx0BDvaHpPo9dP1wTRMAhz/5i+/h4gNQceHfFlSoK7g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WaNIB1bTuGeqDFgg5qffrATPA5LBcL9k9FZEtzZbclkznnnwzUhQi1rCU4FWgzKhmdwbQ7+etV/u2GHxGhUNMoxFNUtxCktje08Bs8GPh50ZuBkQMZrDnwCr0utbvBEehHdosoUsp0RZHU7tJiy0B+bG3BwkJqv+9w8/ZmkQRvk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Wo72P8NM; 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="Wo72P8NM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A54FEC4CEF3; Sat, 21 Jun 2025 19:56:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1750535760; bh=wx0BDvaHpPo9dP1wTRMAhz/5i+/h4gNQceHfFlSoK7g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Wo72P8NML9fSDBiOqg7Q8/ZKIEgkRZMWfgmN2mC8xxD5frVZNNXOQORHofjU7QFWY GzR5za4Q9246lGGiT+qEU6ASXiG8RdXam7SPdNlUU9eu43Dm9/MzoHfij5YYmTCz4q 67Kf1BG88vvX5bvhC7+fwcxbANTW7tpF9H4VppNCjfWsbhswtf7WXjLwwjFLRXh/ra 3yr0CBacm4ayL/yShin7oCinBWK1GmNP2VVnSFduMCstRaPlSUBiX09riPpzl3rfp7 pVV6Ft5sygSfSvviJDgqQi0Il7leb3VnYQlKzUCPVuvvVJwzrVMg861+BRZkkLuvyx /Yyksai5KIKWg== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uT4Ji-00000000e3k-2bik; Sat, 21 Jun 2025 21:55:58 +0200 From: Mauro Carvalho Chehab To: Linux Doc Mailing List , Jonathan Corbet Cc: Mauro Carvalho Chehab , "Akira Yokosawa" , "Mauro Carvalho Chehab" , linux-kernel@vger.kernel.org Subject: [PATCH v2 03/15] scripts: scripts/test_doc_build.py: add script to test doc build Date: Sat, 21 Jun 2025 21:55:42 +0200 Message-ID: <1858fa581a86a1c684cf1c6044be98d482022251.1750535171.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.49.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" Testing Sphinx backward-compatibility is hard, as per version minimal Python dependency requirements can be a nightmare. Add a script to help automate such checks. Signed-off-by: Mauro Carvalho Chehab --- scripts/test_doc_build.py | 241 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 241 insertions(+) create mode 100755 scripts/test_doc_build.py diff --git a/scripts/test_doc_build.py b/scripts/test_doc_build.py new file mode 100755 index 000000000000..482716fbe91d --- /dev/null +++ b/scripts/test_doc_build.py @@ -0,0 +1,241 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 +# Copyright(c) 2025: Mauro Carvalho Chehab +# +# pylint: disable=3DC0103,R1715 + +""" +Install minimal supported requirements for different Sphinx versions +and optionally test the build. +""" + +import argparse +import os.path +import sys +import time + +from subprocess import run + +# Minimal python version supported by the building system +python_bin =3D "python3.9" + +# Starting from 8.0.2, Python 3.9 becomes too old +python_changes =3D {(8, 0, 2): "python3"} + +# Sphinx versions to be installed and their incremental requirements +sphinx_requirements =3D { + (3, 4, 3): { + "alabaster": "0.7.13", + "babel": "2.17.0", + "certifi": "2025.6.15", + "charset-normalizer": "3.4.2", + "docutils": "0.15", + "idna": "3.10", + "imagesize": "1.4.1", + "Jinja2": "3.0.3", + "MarkupSafe": "2.0", + "packaging": "25.0", + "Pygments": "2.19.1", + "PyYAML": "5.1", + "requests": "2.32.4", + "snowballstemmer": "3.0.1", + "sphinxcontrib-applehelp": "1.0.4", + "sphinxcontrib-devhelp": "1.0.2", + "sphinxcontrib-htmlhelp": "2.0.1", + "sphinxcontrib-jsmath": "1.0.1", + "sphinxcontrib-qthelp": "1.0.3", + "sphinxcontrib-serializinghtml": "1.1.5", + "urllib3": "2.4.0", + }, + (3, 5, 4): {}, + (4, 0, 3): { + "docutils": "0.17.1", + "PyYAML": "5.1", + }, + (4, 1, 2): {}, + (4, 3, 2): {}, + (4, 4, 0): {}, + (4, 5, 0): {}, + (5, 0, 2): {}, + (5, 1, 1): {}, + (5, 2, 3): { + "Jinja2": "3.1.2", + "MarkupSafe": "2.0", + "PyYAML": "5.3.1", + }, + (5, 3, 0): { + "docutils": "0.18.1", + "PyYAML": "5.3.1", + }, + (6, 0, 1): {}, + (6, 1, 3): {}, + (6, 2, 1): { + "PyYAML": "5.4.1", + }, + (7, 0, 1): {}, + (7, 1, 2): {}, + (7, 2, 3): { + "PyYAML": "6.0.1", + "sphinxcontrib-serializinghtml": "1.1.9", + }, + (7, 3, 7): { + "alabaster": "0.7.14", + "PyYAML": "6.0.1", + }, + (7, 4, 7): { + "docutils": "0.20", + "PyYAML": "6.0.1", + }, + (8, 0, 2): {}, + (8, 1, 3): { + "PyYAML": "6.0.1", + "sphinxcontrib-applehelp": "1.0.7", + "sphinxcontrib-devhelp": "1.0.6", + "sphinxcontrib-htmlhelp": "2.0.6", + "sphinxcontrib-qthelp": "1.0.6", + }, + (8, 2, 3): { + "PyYAML": "6.0.1", + "sphinxcontrib-serializinghtml": "1.1.9", + }, +} + + +def parse_version(ver_str): + """Convert a version string into a tuple.""" + + return tuple(map(int, ver_str.split("."))) + + +parser =3D argparse.ArgumentParser(description=3D"Build docs for different= sphinx_versions.") + +parser.add_argument('-v', '--version', help=3D'Sphinx single version', + type=3Dparse_version) +parser.add_argument('--min-version', "--min", help=3D'Sphinx minimal versi= on', + type=3Dparse_version) +parser.add_argument('--max-version', "--max", help=3D'Sphinx maximum versi= on', + type=3Dparse_version) +parser.add_argument('-a', '--make_args', + help=3D'extra arguments for make htmldocs, like SPHINX= DIRS=3Dnetlink/specs', + nargs=3D"*") +parser.add_argument('-w', '--write', help=3D'write a requirements.txt file= ', + action=3D'store_true') +parser.add_argument('-m', '--make', + help=3D'Make documentation', + action=3D'store_true') +parser.add_argument('-i', '--wait-input', + help=3D'Wait for an enter before going to the next ver= sion', + action=3D'store_true') + +args =3D parser.parse_args() + +if not args.make_args: + args.make_args =3D [] + +if args.version: + if args.min_version or args.max_version: + sys.exit("Use either --version or --min-version/--max-version") + else: + args.min_version =3D args.version + args.max_version =3D args.version + +sphinx_versions =3D sorted(list(sphinx_requirements.keys())) + +if not args.min_version: + args.min_version =3D sphinx_versions[0] + +if not args.max_version: + args.max_version =3D sphinx_versions[-1] + +first_run =3D True +cur_requirements =3D {} +built_time =3D {} + +for cur_ver, new_reqs in sphinx_requirements.items(): + cur_requirements.update(new_reqs) + + if cur_ver in python_changes: + python_bin =3D python_changes[cur_ver] + + ver =3D ".".join(map(str, cur_ver)) + + if args.min_version: + if cur_ver < args.min_version: + continue + + if args.max_version: + if cur_ver > args.max_version: + break + + if not first_run and args.wait_input and args.make: + ret =3D input("Press Enter to continue or 'a' to abort: ").strip()= .lower() + if ret =3D=3D "a": + print("Aborted.") + sys.exit() + else: + first_run =3D False + + venv_dir =3D f"Sphinx_{ver}" + req_file =3D f"requirements_{ver}.txt" + + print(f"\nSphinx {ver} with {python_bin}") + + # Create venv + run([python_bin, "-m", "venv", venv_dir], check=3DTrue) + pip =3D os.path.join(venv_dir, "bin/pip") + + # Create install list + reqs =3D [] + for pkg, verstr in cur_requirements.items(): + reqs.append(f"{pkg}=3D=3D{verstr}") + + reqs.append(f"Sphinx=3D=3D{ver}") + + run([pip, "install"] + reqs, check=3DTrue) + + # Freeze environment + result =3D run([pip, "freeze"], capture_output=3DTrue, text=3DTrue, ch= eck=3DTrue) + + # Pip install succeeded. Write requirements file + if args.write: + with open(req_file, "w", encoding=3D"utf-8") as fp: + fp.write(result.stdout) + + if args.make: + start_time =3D time.time() + + # Prepare a venv environment + env =3D os.environ.copy() + bin_dir =3D os.path.join(venv_dir, "bin") + env["PATH"] =3D bin_dir + ":" + env["PATH"] + env["VIRTUAL_ENV"] =3D venv_dir + if "PYTHONHOME" in env: + del env["PYTHONHOME"] + + # Test doc build + run(["make", "cleandocs"], env=3Denv, check=3DTrue) + make =3D ["make"] + args.make_args + ["htmldocs"] + + print(f". {bin_dir}/activate") + print(" ".join(make)) + print("deactivate") + run(make, env=3Denv, check=3DTrue) + + end_time =3D time.time() + elapsed_time =3D end_time - start_time + hours, minutes =3D divmod(elapsed_time, 3600) + minutes, seconds =3D divmod(minutes, 60) + + hours =3D int(hours) + minutes =3D int(minutes) + seconds =3D int(seconds) + + built_time[ver] =3D f"{hours:02d}:{minutes:02d}:{seconds:02d}" + + print(f"Finished doc build for Sphinx {ver}. Elapsed time: {built_= time[ver]}") + +if args.make: + print() + print("Summary:") + for ver, elapsed_time in sorted(built_time.items()): + print(f"\tSphinx {ver} elapsed time: {elapsed_time}") --=20 2.49.0