From nobody Thu Oct 2 19:30:10 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 E3BA52F28EB; 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=1757677595; cv=none; b=PCxVoXvRP7EqHX+Uu4d/YqsTSpGYZywIap9E9HAMSb8YweNy0KV4aKAk6K6QXMFJPYwZiBlqE8C5Fp44jRZmlVv7MYnIcRf4MyOTCUih1WqGePRadK2VPgYYbnrXRPXbCsZpbOfbkNjrmnHRBUnCYWIQT7ealUGXDPLcBxxAaPs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757677595; c=relaxed/simple; bh=eAJd0e9LXRA7lsTfbTPbNnApZbgApoArzvYu2a/ki8U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=B9r18pzacx2LdUV1hgKftDfJEdjlyZT8XxOtBGoqzpho2EkmOcL6+mJ1EdNdrR1hQm8SYYG2lGR3C0+QwhfJYpxkBPpA9HNCWUV4L0OJV0QKlnPgW2+cE8npBwJDq4TiZGqrk7oh92S01fKgxtqn93qmsXr7Zo07cJgSWIDIRNE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ik5AHNed; 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="ik5AHNed" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 83B1FC16AAE; 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=eAJd0e9LXRA7lsTfbTPbNnApZbgApoArzvYu2a/ki8U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ik5AHNedMz0325kWoYBFF2wMxEUhM5YP51U7KGSS2LMazL7LT3ZKFPsh576RaRoyM C9A5sc60UWfekH/icKIr5F4u6OAbP2adUEkGnTISHSWPKp5/rkktnUfNkDnLek9U/p iAqwDa+CH3S5atBYdb6+32zLfuyiT0x8aZNwQOd5lIvjUFQuiKEZO+hKEBhHmnWxkO ByIoR/1sy19Oj6M7kAXxQALi4p/iCjeMvtuo8NxFeFGneVzwkapDdFUsQ+i98MoG6d Vcpbqk516/e0DT/YGUffZU+4Pvb9/SCfsOD0B9tFHFcvVEwJRtTW3J4mhU3kTPqqZU un0CguTTxmDHg== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1ux2Ea-00000008Rsj-3R7P; 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 13/18] tools/docs,scripts: sphinx-*: prevent sphinx-build crashes Date: Fri, 12 Sep 2025 13:46:20 +0200 Message-ID: <627c01e8f288f8ffdb317c01837b6f92efb3ec1a.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 On a properly set system, LANG and LC_ALL is always defined. However, some distros like Debian, Gentoo and their variants start with those undefioned. When Sphinx tries to set a locale with: locale.setlocale(locale.LC_ALL, '') It raises an exception, making Sphinx fail. This is more likely to happen with test containers. Add a logic to detect and workaround such issue by setting locale to C. Signed-off-by: Mauro Carvalho Chehab --- tools/docs/sphinx-build-wrapper | 11 +++++++++++ tools/docs/sphinx-pre-install | 14 +++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/tools/docs/sphinx-build-wrapper b/tools/docs/sphinx-build-wrap= per index 1ba3afec6e65..465896e628fd 100755 --- a/tools/docs/sphinx-build-wrapper +++ b/tools/docs/sphinx-build-wrapper @@ -45,6 +45,7 @@ the newer version. """ =20 import argparse +import locale import os import shlex import shutil @@ -475,6 +476,16 @@ class SphinxBuilder: if not sphinxdirs: sphinxdirs =3D os.environ.get("SPHINXDIRS", ".") =20 + # + # The sphinx-build tool has a bug: internally, it tries to set + # locale with locale.setlocale(locale.LC_ALL, ''). This causes a + # crash if language is not set. Detect and fix it. + # + try: + locale.setlocale(locale.LC_ALL, '') + except locale.Error: + self.env["LC_ALL"] =3D "C" + # # sphinxdirs can be a list or a whitespace-separated string # diff --git a/tools/docs/sphinx-pre-install b/tools/docs/sphinx-pre-install index d6d673b7945c..663d4e2a3f57 100755 --- a/tools/docs/sphinx-pre-install +++ b/tools/docs/sphinx-pre-install @@ -26,6 +26,7 @@ system pacage install is recommended. """ =20 import argparse +import locale import os import re import subprocess @@ -422,8 +423,19 @@ class MissingCheckers(AncillaryMethods): """ Gets sphinx-build version. """ + env =3D os.environ.copy() + + # The sphinx-build tool has a bug: internally, it tries to set + # locale with locale.setlocale(locale.LC_ALL, ''). This causes a + # crash if language is not set. Detect and fix it. try: - result =3D self.run([cmd, "--version"], + locale.setlocale(locale.LC_ALL, '') + except Exception: + env["LC_ALL"] =3D "C" + env["LANG"] =3D "C" + + try: + result =3D self.run([cmd, "--version"], env=3Denv, stdout=3Dsubprocess.PIPE, stderr=3Dsubprocess.STDOUT, text=3DTrue, check=3DTrue) --=20 2.51.0