Patchwork [6,of,6] hggettext: work around broken path parsing osx10.6/py2.6

login
register
mail settings
Submitter Ryan McElroy
Date Oct. 2, 2015, 9:33 p.m.
Message ID <71e79cc6500433446f61.1443821627@waste.org>
Download mbox | patch
Permalink /patch/10747/
State Rejected
Headers show

Comments

Ryan McElroy - Oct. 2, 2015, 9:33 p.m.
# HG changeset patch
# User timeless@mozdev.org
# Date 1443813853 14400
#      Fri Oct 02 15:24:13 2015 -0400
# Node ID 71e79cc6500433446f61bd81baba22eca72b9e43
# Parent  39577d4520aba911ffc5f2b37e851cada61017d7
hggettext: work around broken path parsing osx10.6/py2.6

issue4879

Patch

diff --git a/i18n/hggettext b/i18n/hggettext
--- a/i18n/hggettext
+++ b/i18n/hggettext
@@ -22,6 +22,22 @@ 
 
 import os, sys, inspect
 
+inspectgetfile = inspect.getfile
+def fixedgetfile(func):
+    return os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), '..', inspectgetfile(func)))
+
+def monkeygetfile(func):
+    try:
+        inspect.getfile = inspectgetfile
+        inspect.getsource(func)
+        return inspect.getfile(func)
+    except IOError:
+        inspect.getfile = fixedgetfile
+        return inspect.getfile(func)
+    finally:
+        inspect.getfile = monkeygetfile
+
+inspect.getfile = monkeygetfile
 
 def escape(s):
     # The order is important, the backslash must be escaped first
diff --git a/tests/test-i18n.t b/tests/test-i18n.t
--- a/tests/test-i18n.t
+++ b/tests/test-i18n.t
@@ -47,3 +47,10 @@ 
   $ python check-translation.py *.po
   $ python check-translation.py --doctest
   $ cd $TESTTMP
+
+Check hggettext
+
+  $ hggettext="$TESTDIR/../i18n/hggettext"
+  $ cd "$TESTDIR"/..
+  $ $hggettext hgext/*.py > /dev/null
+  $ cd $TESTTMP