From f8b58e41cd1bb44d576f6b9da9f07b89f3d0a823 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Thu, 27 Apr 2017 00:17:07 +0900 Subject: [PATCH] Fix #3669: gettext builder fails with "ValueError: substring not found" --- CHANGES | 1 + sphinx/builders/gettext.py | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/CHANGES b/CHANGES index 12d67a00a..d6de0d3ad 100644 --- a/CHANGES +++ b/CHANGES @@ -16,6 +16,7 @@ Bugs fixed ---------- * #3661: sphinx-build crashes on parallel build +* #3669: gettext builder fails with "ValueError: substring not found" Testing -------- diff --git a/sphinx/builders/gettext.py b/sphinx/builders/gettext.py index 280f2be99..4da19bd2c 100644 --- a/sphinx/builders/gettext.py +++ b/sphinx/builders/gettext.py @@ -194,14 +194,18 @@ ltz = LocalTimeZone() def should_write(filepath, new_content): if not path.exists(filepath): return True - with open(filepath, 'r', encoding='utf-8') as oldpot: # type: ignore - old_content = oldpot.read() - old_header_index = old_content.index('"POT-Creation-Date:') - new_header_index = new_content.index('"POT-Creation-Date:') - old_body_index = old_content.index('"PO-Revision-Date:') - new_body_index = new_content.index('"PO-Revision-Date:') - return ((old_content[:old_header_index] != new_content[:new_header_index]) or - (new_content[new_body_index:] != old_content[old_body_index:])) + try: + with open(filepath, 'r', encoding='utf-8') as oldpot: # type: ignore + old_content = oldpot.read() + old_header_index = old_content.index('"POT-Creation-Date:') + new_header_index = new_content.index('"POT-Creation-Date:') + old_body_index = old_content.index('"PO-Revision-Date:') + new_body_index = new_content.index('"PO-Revision-Date:') + return ((old_content[:old_header_index] != new_content[:new_header_index]) or + (new_content[new_body_index:] != old_content[old_body_index:])) + except ValueError: + pass + return True