summaryrefslogtreecommitdiff
path: root/tools/docs/sphinx-pre-install
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab+huawei@kernel.org>2025-09-18 13:54:51 +0200
committerJonathan Corbet <corbet@lwn.net>2025-09-18 11:18:39 -0600
commit82c294d453c0f065133da064f92a121500cc5643 (patch)
treeec7ca26fe0eb9145014b15d3c2ace32bf8e678ba /tools/docs/sphinx-pre-install
parent08e14bc17eca275352f00defb17506799b99626c (diff)
downloadlinux-next-82c294d453c0f065133da064f92a121500cc5643.tar.gz
linux-next-82c294d453c0f065133da064f92a121500cc5643.zip
tools/docs,scripts: sphinx-*: prevent sphinx-build crashes
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 <mchehab+huawei@kernel.org> Message-ID: <1d0afad8fe3d83182be3a08eb00dd71322e23e69.1758196090.git.mchehab+huawei@kernel.org> Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Diffstat (limited to 'tools/docs/sphinx-pre-install')
-rwxr-xr-xtools/docs/sphinx-pre-install14
1 files changed, 13 insertions, 1 deletions
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.
"""
import argparse
+import locale
import os
import re
import subprocess
@@ -422,8 +423,19 @@ class MissingCheckers(AncillaryMethods):
"""
Gets sphinx-build version.
"""
+ env = 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:
+ locale.setlocale(locale.LC_ALL, '')
+ except Exception:
+ env["LC_ALL"] = "C"
+ env["LANG"] = "C"
+
try:
- result = self.run([cmd, "--version"],
+ result = self.run([cmd, "--version"], env=env,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True, check=True)