Mercurial > hg-stable
changeset 33838:726dd73df3b9
i18n: ignore doctest part to avoid warning at "make update-pot"
hggettext assumes that backslashes in docstring are always doubled in
original source code, in order to find the location of original
docstring out certainly.
This assumption almost always works as expected. But doctest easily
breaks it, because many of backslashes in doctests aren't doubled.
This mismatching causes "unknown offset in ..." warning at "make
update-pot".
To avoid such warning, this patch ignores doctest part of docstring
before finding the location of original docstring out.
BTW, at this patch, only person() in templatefilters.py has doctest
part, which causes "unknown offset ..." warning.
Therefore, just making backslashes in that doctest doubled can avoid
such warning, too. But forcing doctest writers to double backslashes
in doctest isn't reasonable, IMHO.
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Sun, 13 Aug 2017 15:20:16 +0900 |
parents | 1775f93da25c |
children | ed04d7254a91 |
files | i18n/hggettext |
diffstat | 1 files changed, 7 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/i18n/hggettext Wed Aug 02 01:15:07 2017 +0900 +++ b/i18n/hggettext Sun Aug 13 15:20:16 2017 +0900 @@ -24,6 +24,7 @@ import inspect import os +import re import sys @@ -60,9 +61,15 @@ 'msgid %s\n' % normalize(s) + 'msgstr ""\n') +doctestre = re.compile(r'^ +>>> ', re.MULTILINE) def offset(src, doc, name, default): """Compute offset or issue a warning on stdout.""" + # remove doctest part, in order to avoid backslash mismatching + m = doctestre.search(doc) + if m: + doc = doc[:m.start()] + # Backslashes in doc appear doubled in src. end = src.find(doc.replace('\\', '\\\\')) if end == -1: