Skip to content

Commit

Permalink
Merge pull request sphinx-doc#5521 from tk0miya/5493_gettext_crashed_…
Browse files Browse the repository at this point in the history
…with_broken_tmpl

Fix sphinx-doc#5493: gettext: crashed with broken template
  • Loading branch information
tk0miya committed Oct 12, 2018
2 parents 551ce9e + 19e7e6a commit 9158363
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Bugs fixed
* #5492: sphinx-build fails to build docs w/ Python < 3.5.2
* #3704: latex: wrong ``\label`` positioning for figures with a legend
* #5496: C++, fix assertion when a symbol is declared more than twice.
* #5493: gettext: crashed with broken template

Testing
--------
Expand Down
14 changes: 9 additions & 5 deletions sphinx/builders/gettext.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from sphinx.builders import Builder
from sphinx.domains.python import pairindextypes
from sphinx.errors import ThemeError
from sphinx.locale import __
from sphinx.util import split_index_msg, logging, status_iterator
from sphinx.util.console import bold # type: ignore
Expand Down Expand Up @@ -247,11 +248,14 @@ def _extract_from_template(self):

for template in status_iterator(files, __('reading templates... '), "purple", # type: ignore # NOQA
len(files), self.app.verbosity):
with open(template, 'r', encoding='utf-8') as f: # type: ignore
context = f.read()
for line, meth, msg in extract_translations(context):
origin = MsgOrigin(template, line)
self.catalogs['sphinx'].add(msg, origin)
try:
with open(template, 'r', encoding='utf-8') as f: # type: ignore
context = f.read()
for line, meth, msg in extract_translations(context):
origin = MsgOrigin(template, line)
self.catalogs['sphinx'].add(msg, origin)
except Exception as exc:
raise ThemeError('%s: %r' % (template, exc))

def build(self, docnames, summary=None, method='update'):
# type: (Iterable[unicode], unicode, unicode) -> None
Expand Down

0 comments on commit 9158363

Please sign in to comment.