"CLI-Anything: Making ALL Software Agent-Native" -- CLI-Hub: https://clianything.cc/
Python
fix: enforce English output for Calibre tools in tests and backend
ChengYeb5dfcaea10be
diff --git a/calibre/agent-harness/cli_anything/calibre/tests/test_full_e2e.py b/calibre/agent-harness/cli_anything/calibre/tests/test_full_e2e.pyindex 8540ef820..af57e64c3 100644--- a/calibre/agent-harness/cli_anything/calibre/tests/test_full_e2e.py+++ b/calibre/agent-harness/cli_anything/calibre/tests/test_full_e2e.py@@ -23,6 +23,13 @@ import zipfilefrom pathlib import Path+def _english_env() -> dict[str, str]:+ """Environment dict that forces Calibre to output in English."""+ env = os.environ.copy()+ env["CALIBRE_OVERRIDE_LANG"] = "en"+ return env++# ── EPUB generation helpers ────────────────────────────────────────────────@@ -151,7 +158,7 @@ class CalibreTestMixin:# Add to libraryresult = subprocess.run([calibredb, "--with-library", cls.lib_dir, "add", cls.epub_path],- capture_output=True, text=True, check=True,+ capture_output=True, text=True, check=True, env=_english_env(),)# Extract the book ID from output "Added book ids: 1"cls.book_id = 1@@ -263,7 +270,7 @@ class TestFormatConversion(CalibreTestMixin, unittest.TestCase):calibredb = shutil.which("calibredb")result = subprocess.run([calibredb, "--with-library", self.lib_dir, "add", epub],- capture_output=True, text=True, check=True,+ capture_output=True, text=True, check=True, env=_english_env(),)# Find the new book IDnew_id = None@@ -296,7 +303,7 @@ class TestFormatConversion(CalibreTestMixin, unittest.TestCase):calibredb = shutil.which("calibredb")r = subprocess.run([calibredb, "--with-library", self.lib_dir, "add", epub],- capture_output=True, text=True, check=True,+ capture_output=True, text=True, check=True, env=_english_env(),)new_id = Nonefor line in r.stdout.splitlines():@@ -334,7 +341,7 @@ class TestFormatConversion(CalibreTestMixin, unittest.TestCase):calibredb = shutil.which("calibredb")r = subprocess.run([calibredb, "--with-library", self.lib_dir, "add", epub],- capture_output=True, text=True, check=True,+ capture_output=True, text=True, check=True, env=_english_env(),)new_id = Nonefor line in r.stdout.splitlines():@@ -390,7 +397,7 @@ class TestCLISubprocess(unittest.TestCase):shutil.rmtree(cls.tmp, ignore_errors=True)def _run(self, args, check=True, env=None):- full_env = os.environ.copy()+ full_env = _english_env()if env:full_env.update(env)return subprocess.run(diff --git a/calibre/agent-harness/cli_anything/calibre/utils/calibre_backend.py b/calibre/agent-harness/cli_anything/calibre/utils/calibre_backend.pyindex 13e8ed48d..fc07bce2e 100644--- a/calibre/agent-harness/cli_anything/calibre/utils/calibre_backend.py+++ b/calibre/agent-harness/cli_anything/calibre/utils/calibre_backend.py@@ -7,11 +7,23 @@ Calibre is a HARD DEPENDENCY. If it is not installed, clear error messages areshown with install instructions."""+import osimport shutilimport subprocessfrom typing import Any+def _english_env() -> dict[str, str]:+ """Return a copy of the current environment with Calibre forced to English.++ This ensures that output strings like 'Added book ids:' are always in+ English regardless of the system locale — critical for reliable parsing.+ """+ env = os.environ.copy()+ env["CALIBRE_OVERRIDE_LANG"] = "en"+ return env++# ── Tool discovery ─────────────────────────────────────────────────────────@@ -87,6 +99,7 @@ def run_calibredb(capture_output=True,text=True,timeout=timeout,+ env=_english_env(),)except subprocess.TimeoutExpired:raise RuntimeError(f"calibredb timed out after {timeout}s: {' '.join(cmd)}")@@ -125,6 +138,7 @@ def run_ebook_convert(capture_output=True,text=True,timeout=timeout,+ env=_english_env(),)except subprocess.TimeoutExpired:raise RuntimeError(f"ebook-convert timed out after {timeout}s")@@ -163,6 +177,7 @@ def run_ebook_meta(capture_output=True,text=True,timeout=timeout,+ env=_english_env(),)except subprocess.TimeoutExpired:raise RuntimeError(f"ebook-meta timed out after {timeout}s")