Patchwork [7,of,8,demandimport-py3] init: turn on demandimport for Python 3.6 and above

login
register
mail settings
Submitter Siddharth Agarwal
Date May 21, 2017, 8:48 p.m.
Message ID <1bf07f6a0c323a4a842d.1495399682@devvm31800.prn1.facebook.com>
Download mbox | patch
Permalink /patch/20800/
State Accepted
Headers show

Comments

Siddharth Agarwal - May 21, 2017, 8:48 p.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1495396261 25200
#      Sun May 21 12:51:01 2017 -0700
# Node ID 1bf07f6a0c323a4a842d7e76d14e4e893a2b68ca
# Parent  0c781be127ded0349e093e492b507e343bf78676
init: turn on demandimport for Python 3.6 and above

This uses the new demandimport implementation for Python 3 introduced in
previous patches.

This doesn't yet enhance performance because it isn't integrated with the
custom source file loader we use on Python 3. We'll integrate the two in
upcoming patches.

Patch

diff --git a/hg b/hg
--- a/hg
+++ b/hg
@@ -28,8 +28,8 @@  if libdir != '@' 'LIBDIR' '@':
 
 # enable importing on demand to reduce startup time
 try:
-    if sys.version_info[0] < 3:
-        from mercurial import demandimport; demandimport.enable()
+    if sys.version_info[0] < 3 or sys.version_info >= (3, 6):
+        import hgdemandimport; hgdemandimport.enable()
 except ImportError:
     sys.stderr.write("abort: couldn't find mercurial libraries in [%s]\n" %
                      ' '.join(sys.path))