[PATCH 3 of 3] py3: make demandimport available on Python3 (RFC)

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Sun Mar 12 01:48:00 EST 2017


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1489300851 -32400
#      Sun Mar 12 15:40:51 2017 +0900
# Node ID fc455e59df8e6d451273105cb903e081ba646af6
# Parent  737dc31682bf11ddcd2d1523e67fcd11b53ce876
py3: make demandimport available on Python3 (RFC)

Before this patch, demandimport isn't available on Python3, because
code transformation forces demandimport.py to treat string literals in
it as bytes, even though all system I/F used in demandimport.py
require unicode argument on Python3.

To make demandimport available on Python3, this patch adds "control
comment" to make code transformation use "u" prefix for string
literals in demandimport.py.

This patch also omits preventing "hg" command on Python3 from enabling
demandimport.

FYI, enabling demandimport decreases number of files actually imported
at "hg version" from 132 to 42,

diff --git a/hg b/hg
--- a/hg
+++ b/hg
@@ -28,8 +28,7 @@ if libdir != '@' 'LIBDIR' '@':
 
 # enable importing on demand to reduce startup time
 try:
-    if sys.version_info[0] < 3:
-        from mercurial import demandimport; demandimport.enable()
+    from mercurial import demandimport; demandimport.enable()
 except ImportError:
     sys.stderr.write("abort: couldn't find mercurial libraries in [%s]\n" %
                      ' '.join(sys.path))
diff --git a/mercurial/demandimport.py b/mercurial/demandimport.py
--- a/mercurial/demandimport.py
+++ b/mercurial/demandimport.py
@@ -5,6 +5,8 @@
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
+# :hgct: default-string-literal-prefix u
+
 '''
 demandimport - automatic demandloading of modules
 
diff --git a/tests/test-check-code.t b/tests/test-check-code.t
--- a/tests/test-check-code.t
+++ b/tests/test-check-code.t
@@ -10,7 +10,7 @@ New errors are not allowed. Warnings are
   $ hg locate -X contrib/python-zstandard -X hgext/fsmonitor/pywatchman |
   > sed 's-\\-/-g' | xargs "$check_code" --warnings --per-file=0 || false
   Skipping i18n/polib.py it has no-che?k-code (glob)
-  mercurial/demandimport.py:312:
+  mercurial/demandimport.py:314:
    >     if os.environ.get('HGDEMANDIMPORT') != 'disable':
    use encoding.environ instead (py3)
   mercurial/encoding.py:54:


More information about the Mercurial-devel mailing list