From nobody Thu Oct 9 02:55:52 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 E648018DB26; Sun, 22 Jun 2025 06:02:51 +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=1750572172; cv=none; b=M/67gYjzVFcf9Y1gtK0jJAjHip/fyYKRwX75+YQ0dqjfciss53O9IfbJ/ewfp70PgWeQcwq7fTjtancY1mw5P1YBsFErR1vfmTDWKZCjS78OSM6PIRircTpC/kpizN03LrF71EB0d7pC1JBkt7qL9Hwn30B0ytc7meAMvji9K2A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750572172; c=relaxed/simple; bh=t6WKKzUZ3jaz/IWeMR8qJbIf2p6B9ADIoUTLRFgr0u0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bCcXZqvwLOQJ/lmw9/kuzXLO0ewfYreDvUN11JEY/8SODiEfmM3lJYY7GBnTQz0HL9WvPBF5/zELO0YommEtSOEfP3w25/LXGRYLMrjzdHE7ymWgJ9UeAdwCV7IN5zm03vnPmkXgJA4AakPQpyRQ88JYUq0zOuJ9ruB53KvNBbs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Zv+tUMK4; 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="Zv+tUMK4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2DF52C4CEEA; Sun, 22 Jun 2025 06:02:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1750572171; bh=t6WKKzUZ3jaz/IWeMR8qJbIf2p6B9ADIoUTLRFgr0u0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zv+tUMK4MaP82Jddp8MV7KWBwi2R8LFoL7Byadjyty8Ns5Q1qVoVGrq2CLXwynLrx 0vD/jiGYisidp1O8IFo8oUQOgzaBP0DrVFwoSrNde27cxcN3MOJb9hG6gZFV1FrQsX Q9r7QuzX7kzy11mEzEFqyVb7AciU6j+RFkf8pvlTFLIzLuVEC9VCjyPndNYuiRi9tg J3b8KvfPFzQIevY8cukdHhv0Cu3pACF2NIjL7DDB7Iz+JRV5kPFsdIDc7+O4WkR93+ FEnRDG27G2PPv5wpVrDVDvRV+DPQXzyrmOfhmv/aG7C9Z26Yh7pLmPPMZZLOGqfLeo mqZrmRriudGKg== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uTDmz-00000000o2K-1h1B; Sun, 22 Jun 2025 08:02:49 +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 v3 05/15] scripts: test_doc_build.py: better control its output Date: Sun, 22 Jun 2025 08:02:34 +0200 Message-ID: <76c3a64a87a7493ae607d5c7784b3b829affcaf0.1750571906.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" Now that asyncio is supported, allow userspace to adjust verbosity level and direct the script output to a file. Signed-off-by: Mauro Carvalho Chehab --- scripts/test_doc_build.py | 78 +++++++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 27 deletions(-) diff --git a/scripts/test_doc_build.py b/scripts/test_doc_build.py index 94f2f2d8c3b7..5b9eb2c0bf01 100755 --- a/scripts/test_doc_build.py +++ b/scripts/test_doc_build.py @@ -2,7 +2,7 @@ # SPDX-License-Identifier: GPL-2.0 # Copyright(c) 2025: Mauro Carvalho Chehab # -# pylint: disable=3DR0903,R0913,R0914,R0917 +# pylint: disable=3DR0903,R0912,R0913,R0914,R0917,C0301 =20 """ Install minimal supported requirements for different Sphinx versions @@ -104,9 +104,22 @@ SPHINX_REQUIREMENTS =3D { class AsyncCommands: """Excecute command synchronously""" =20 - stdout =3D None - stderr =3D None - output =3D None + def __init__(self, fp=3DNone): + + self.stdout =3D None + self.stderr =3D None + self.output =3D None + self.fp =3D fp + + def log(self, out, verbose, is_info=3DTrue): + if verbose: + if is_info: + print(out.rstrip("\n")) + else: + print(out.rstrip("\n"), file=3Dsys.stderr) + + if self.fp: + self.fp.write(out.rstrip("\n") + "\n") =20 async def _read(self, stream, verbose, is_info): """Ancillary routine to capture while displaying""" @@ -115,16 +128,10 @@ class AsyncCommands: line =3D await stream.readline() if line: out =3D line.decode("utf-8", errors=3D"backslashreplace") - self.output +=3D out + self.log(out, verbose, is_info) if is_info: - if verbose: - print(out.rstrip("\n")) - self.stdout +=3D out else: - if verbose: - print(out.rstrip("\n"), file=3Dsys.stderr) - self.stderr +=3D out else: break @@ -140,10 +147,8 @@ class AsyncCommands: =20 self.stdout =3D "" self.stderr =3D "" - self.output =3D "" =20 - if verbose: - print("$ ", " ".join(cmd)) + self.log("$ " + " ".join(cmd), verbose) =20 proc =3D await asyncio.create_subprocess_exec(cmd[0], *cmd[1:], @@ -167,7 +172,7 @@ class AsyncCommands: =20 if capture_output: if proc.returncode > 0: - print("Error {proc.returncode}", file=3Dsys.stderr) + self.log(f"Error {proc.returncode}", verbose=3DTrue, is_in= fo=3DFalse) return "" =20 return self.output @@ -192,10 +197,11 @@ class SphinxVenv: self.built_time =3D {} self.first_run =3D True =20 - async def _handle_version(self, args, cur_ver, cur_requirements, pytho= n_bin): + async def _handle_version(self, args, fp, + cur_ver, cur_requirements, python_bin): """Handle a single Sphinx version""" =20 - cmd =3D AsyncCommands() + cmd =3D AsyncCommands(fp) =20 ver =3D ".".join(map(str, cur_ver)) =20 @@ -210,10 +216,11 @@ class SphinxVenv: venv_dir =3D f"Sphinx_{ver}" req_file =3D f"requirements_{ver}.txt" =20 - print(f"\nSphinx {ver} with {python_bin}") + cmd.log(f"\nSphinx {ver} with {python_bin}", verbose=3DTrue) =20 # Create venv - await cmd.run([python_bin, "-m", "venv", venv_dir], check=3DTrue) + await cmd.run([python_bin, "-m", "venv", venv_dir], + verbose=3Dargs.verbose, check=3DTrue) pip =3D os.path.join(venv_dir, "bin/pip") =20 # Create install list @@ -223,7 +230,7 @@ class SphinxVenv: =20 reqs.append(f"Sphinx=3D=3D{ver}") =20 - await cmd.run([pip, "install"] + reqs, check=3DTrue, verbose=3DTru= e) + await cmd.run([pip, "install"] + reqs, check=3DTrue, verbose=3Darg= s.verbose) =20 # Freeze environment result =3D await cmd.run([pip, "freeze"], verbose=3DFalse, check= =3DTrue) @@ -248,10 +255,11 @@ class SphinxVenv: await cmd.run(["make", "cleandocs"], env=3Denv, check=3DTrue) make =3D ["make"] + args.make_args + ["htmldocs"] =20 - print(f". {bin_dir}/activate") - print(" ".join(make)) - print("deactivate") - await cmd.run(make, env=3Denv, check=3DTrue) + if args.verbose: + print(f". {bin_dir}/activate") + await cmd.run(make, env=3Denv, check=3DTrue, verbose=3DTrue) + if args.verbose: + print("deactivate") =20 end_time =3D time.time() elapsed_time =3D end_time - start_time @@ -264,7 +272,7 @@ class SphinxVenv: =20 self.built_time[ver] =3D f"{hours:02d}:{minutes:02d}:{seconds:= 02d}" =20 - print(f"Finished doc build for Sphinx {ver}. Elapsed time: {se= lf.built_time[ver]}") + cmd.log(f"Finished doc build for Sphinx {ver}. Elapsed time: {= self.built_time[ver]}", verbose=3DTrue) =20 async def run(self, args): """ @@ -272,6 +280,15 @@ class SphinxVenv: on a loop. """ =20 + if args.log: + fp =3D open(args.log, "w", encoding=3D"utf-8") + if not args.verbose: + args.verbose =3D False + else: + fp =3D None + if not args.verbose: + args.verbose =3D True + cur_requirements =3D {} python_bin =3D MINIMAL_PYTHON_VERSION =20 @@ -290,7 +307,7 @@ class SphinxVenv: if cur_ver > args.max_version: break =20 - await self._handle_version(args, cur_ver, cur_requirements, + await self._handle_version(args, fp, cur_ver, cur_requirements, python_bin) =20 if args.make: @@ -299,6 +316,8 @@ class SphinxVenv: for ver, elapsed_time in sorted(self.built_time.items()): print(f"\tSphinx {ver} elapsed time: {elapsed_time}") =20 + if fp: + fp.close() =20 def parse_version(ver_str): """Convert a version string into a tuple.""" @@ -311,7 +330,7 @@ async def main(): =20 parser =3D argparse.ArgumentParser(description=3D"Build docs for diffe= rent sphinx_versions.") =20 - parser.add_argument('-v', '--version', help=3D'Sphinx single version', + parser.add_argument('-V', '--version', help=3D'Sphinx single version', type=3Dparse_version) parser.add_argument('--min-version', "--min", help=3D'Sphinx minimal v= ersion', type=3Dparse_version) @@ -328,6 +347,11 @@ async def main(): parser.add_argument('-i', '--wait-input', help=3D'Wait for an enter before going to the next= version', action=3D'store_true') + parser.add_argument('-v', '--verbose', + help=3D'Verbose all commands', + action=3D'store_true') + parser.add_argument('-l', '--log', + help=3D'Log command output on a file') =20 args =3D parser.parse_args() =20 --=20 2.49.0