[PATCH 3 of 6] i18n: ignore doctest part to avoid warning at "make update-pot"

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Tue Aug 15 12:19:03 EDT 2017


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1502605216 -32400
#      Sun Aug 13 15:20:16 2017 +0900
# Node ID 1d204d17d51eb143f1ef66426cec1831cd8c93bf
# Parent  abd0f3801a00bf7d3e5a74de796ec68d97d3e9dd
# Available At https://bitbucket.org/foozy/mercurial-wip
#              hg pull https://bitbucket.org/foozy/mercurial-wip -r 1d204d17d51e
# EXP-Topic i18n-fix-update-pot-issues
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.

diff --git a/i18n/hggettext b/i18n/hggettext
--- a/i18n/hggettext
+++ b/i18n/hggettext
@@ -24,6 +24,7 @@ from __future__ import absolute_import, 
 
 import inspect
 import os
+import re
 import sys
 
 
@@ -60,9 +61,15 @@ def poentry(path, lineno, s):
             '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:


More information about the Mercurial-devel mailing list