Patchwork [5,of,8,demandimport-py3] demandimport: move ignore list to __init__.py

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

Comments

Siddharth Agarwal - May 21, 2017, 8:48 p.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1495393853 25200
#      Sun May 21 12:10:53 2017 -0700
# Node ID 24d81489a7dcac5a68b846dca4928c0e22a312a1
# Parent  55240ad4c7fc14d01256df4bbae1d5ef9d609cc6
demandimport: move ignore list to __init__.py

We're going to use the same ignore list for Python 3.

Patch

diff --git a/hgdemandimport/__init__.py b/hgdemandimport/__init__.py
--- a/hgdemandimport/__init__.py
+++ b/hgdemandimport/__init__.py
@@ -13,10 +13,57 @@ 
 
 from __future__ import absolute_import
 
+import sys
+
 from . import demandimportpy2 as demandimport
 
+# Extensions can add to this list if necessary.
+ignore = [
+    '__future__',
+    '_hashlib',
+    # ImportError during pkg_resources/__init__.py:fixup_namespace_package
+    '_imp',
+    '_xmlplus',
+    'fcntl',
+    'nt', # pathlib2 tests the existence of built-in 'nt' module
+    'win32com.gen_py',
+    'win32com.shell', # 'appdirs' tries to import win32com.shell
+    '_winreg', # 2.7 mimetypes needs immediate ImportError
+    'pythoncom',
+    # imported by tarfile, not available under Windows
+    'pwd',
+    'grp',
+    # imported by profile, itself imported by hotshot.stats,
+    # not available under Windows
+    'resource',
+    # this trips up many extension authors
+    'gtk',
+    # setuptools' pkg_resources.py expects "from __main__ import x" to
+    # raise ImportError if x not defined
+    '__main__',
+    '_ssl', # conditional imports in the stdlib, issue1964
+    '_sre', # issue4920
+    'rfc822',
+    'mimetools',
+    'sqlalchemy.events', # has import-time side effects (issue5085)
+    # setuptools 8 expects this module to explode early when not on windows
+    'distutils.msvc9compiler',
+    '__builtin__',
+    'builtins',
+    'urwid.command_map', # for pudb
+    ]
+
+_pypy = '__pypy__' in sys.builtin_module_names
+
+if _pypy:
+    ignore.extend([
+        # _ctypes.pointer is shadowed by "from ... import pointer" (PyPy 5)
+        '_ctypes.pointer',
+    ])
+
+demandimport.init(ignore)
+
 # Re-export.
-ignore = demandimport.ignore
 isenabled = demandimport.isenabled
 enable = demandimport.enable
 disable = demandimport.disable
diff --git a/hgdemandimport/demandimportpy2.py b/hgdemandimport/demandimportpy2.py
--- a/hgdemandimport/demandimportpy2.py
+++ b/hgdemandimport/demandimportpy2.py
@@ -265,46 +265,11 @@  def _demandimport(name, globals=None, lo
 
         return mod
 
-ignore = [
-    '__future__',
-    '_hashlib',
-    # ImportError during pkg_resources/__init__.py:fixup_namespace_package
-    '_imp',
-    '_xmlplus',
-    'fcntl',
-    'nt', # pathlib2 tests the existence of built-in 'nt' module
-    'win32com.gen_py',
-    'win32com.shell', # 'appdirs' tries to import win32com.shell
-    '_winreg', # 2.7 mimetypes needs immediate ImportError
-    'pythoncom',
-    # imported by tarfile, not available under Windows
-    'pwd',
-    'grp',
-    # imported by profile, itself imported by hotshot.stats,
-    # not available under Windows
-    'resource',
-    # this trips up many extension authors
-    'gtk',
-    # setuptools' pkg_resources.py expects "from __main__ import x" to
-    # raise ImportError if x not defined
-    '__main__',
-    '_ssl', # conditional imports in the stdlib, issue1964
-    '_sre', # issue4920
-    'rfc822',
-    'mimetools',
-    'sqlalchemy.events', # has import-time side effects (issue5085)
-    # setuptools 8 expects this module to explode early when not on windows
-    'distutils.msvc9compiler',
-    '__builtin__',
-    'builtins',
-    'urwid.command_map', # for pudb
-    ]
+ignore = []
 
-if _pypy:
-    ignore.extend([
-        # _ctypes.pointer is shadowed by "from ... import pointer" (PyPy 5)
-        '_ctypes.pointer',
-    ])
+def init(ignorelist):
+    global ignore
+    ignore = ignorelist
 
 def isenabled():
     return builtins.__import__ == _demandimport