D7953: hgdemandimport: disable on Python 3.5

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Tue Jan 21 07:48:25 UTC 2020


indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  The demand importer functionality isn't working at all on Python 3.5.
  I'm not sure what's wrong.
  
  Since it isn't working, let's disable it completely.
  
    $ HGRCPATH= hyperfine -w 1 -r 50 -- "~/.pyenv/versions/3.5.9/bin/python ./hg version" \
      "HGDEMANDIMPORT=disable ~/.pyenv/versions/3.5.9/bin/python ./hg version"
    Benchmark #1: ~/.pyenv/versions/3.5.9/bin/python ./hg version
      Time (mean ± σ):     163.7 ms ±   2.2 ms    [User: 148.5 ms, System: 15.7 ms]
      Range (min … max):   161.0 ms … 170.2 ms    50 runs
    
    Benchmark #2: HGDEMANDIMPORT=disable ~/.pyenv/versions/3.5.9/bin/python ./hg version
      Time (mean ± σ):     164.3 ms ±   1.4 ms    [User: 148.2 ms, System: 16.6 ms]
      Range (min … max):   161.4 ms … 169.8 ms    50 runs

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D7953

AFFECTED FILES
  hgdemandimport/demandimportpy3.py
  tests/test-demandimport.py

CHANGE DETAILS

diff --git a/tests/test-demandimport.py b/tests/test-demandimport.py
--- a/tests/test-demandimport.py
+++ b/tests/test-demandimport.py
@@ -22,6 +22,10 @@
 if sys.flags.optimize:
     sys.exit(80)
 
+# The demand importer doesn't work on Python 3.5.
+if sys.version_info[0:2] == (3, 5):
+    sys.exit(80)
+
 if ispy3:
     from importlib.util import _LazyModule
 
diff --git a/hgdemandimport/demandimportpy3.py b/hgdemandimport/demandimportpy3.py
--- a/hgdemandimport/demandimportpy3.py
+++ b/hgdemandimport/demandimportpy3.py
@@ -36,6 +36,12 @@
 
 _deactivated = False
 
+# Python 3.5's LazyLoader doesn't work for some reason.
+# https://bugs.python.org/issue26186 is a known issue with extension
+# importing. But it appears to not have a meaningful effect with
+# Mercurial.
+_supported = sys.version_info[0:2] >= (3, 6)
+
 
 class _lazyloaderex(importlib.util.LazyLoader):
     """This is a LazyLoader except it also follows the _deactivated global and
@@ -51,15 +57,9 @@
                 super().exec_module(module)
 
 
-# This is 3.6+ because with Python 3.5 it isn't possible to lazily load
-# extensions. See the discussion in https://bugs.python.org/issue26186 for more.
-if sys.version_info[0:2] >= (3, 6):
-    _extensions_loader = _lazyloaderex.factory(
-        importlib.machinery.ExtensionFileLoader
-    )
-else:
-    _extensions_loader = importlib.machinery.ExtensionFileLoader
-
+_extensions_loader = _lazyloaderex.factory(
+    importlib.machinery.ExtensionFileLoader
+)
 _bytecode_loader = _lazyloaderex.factory(
     importlib.machinery.SourcelessFileLoader
 )
@@ -97,6 +97,9 @@
 
 
 def enable():
+    if not _supported:
+        return
+
     sys.path_hooks.insert(0, _makefinder)
 
 



To: indygreg, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list