[PATCH 3 of 8 demandimport-py3] demandimport: move to separate package

Siddharth Agarwal sid0 at fb.com
Sun May 21 16:47:58 EDT 2017


# HG changeset patch
# User Siddharth Agarwal <sid0 at fb.com>
# Date 1495393853 25200
#      Sun May 21 12:10:53 2017 -0700
# Node ID 3af6014ae4e910c30de7b9ed16ce0e9130ccc270
# Parent  2fc0a078b9f1dfa17420b90895d02d4574618c11
demandimport: move to separate package

In Python 3, demand loading is per-package. Keeping demandimport in the
mercurial package would disable demand loading for any modules in
mercurial.

diff --git a/contrib/import-checker.py b/contrib/import-checker.py
--- a/contrib/import-checker.py
+++ b/contrib/import-checker.py
@@ -25,7 +25,9 @@ allowsymbolimports = (
 )
 
 # Whitelist of symbols that can be directly imported.
-directsymbols = ()
+directsymbols = (
+    'demandimport',
+)
 
 # Modules that must be aliased because they are commonly confused with
 # common variables and can create aliasing and readability issues.
diff --git a/hgdemandimport/__init__.py b/hgdemandimport/__init__.py
new file mode 100644
--- /dev/null
+++ b/hgdemandimport/__init__.py
@@ -0,0 +1,23 @@
+# hgdemandimport - global demand-loading of modules for Mercurial
+#
+# Copyright 2017 Facebook Inc.
+#
+# This software may be used and distributed according to the terms of the
+# GNU General Public License version 2 or any later version.
+
+'''demandimport - automatic demand-loading of modules'''
+
+# This is in a separate package from mercurial because in Python 3,
+# demand loading is per-package. Keeping demandimport in the mercurial package
+# would disable demand loading for any modules in mercurial.
+
+from __future__ import absolute_import
+
+from . import demandimportpy2 as demandimport
+
+# Re-export.
+ignore = demandimport.ignore
+isenabled = demandimport.isenabled
+enable = demandimport.enable
+disable = demandimport.disable
+deactivated = demandimport.deactivated
diff --git a/mercurial/demandimport.py b/hgdemandimport/demandimportpy2.py
rename from mercurial/demandimport.py
rename to hgdemandimport/demandimportpy2.py
diff --git a/mercurial/__init__.py b/mercurial/__init__.py
--- a/mercurial/__init__.py
+++ b/mercurial/__init__.py
@@ -9,6 +9,10 @@ from __future__ import absolute_import
 
 import sys
 
+# Allow 'from mercurial import demandimport' to keep working.
+import hgdemandimport
+demandimport = hgdemandimport
+
 __all__ = []
 
 # Python 3 uses a custom module loader that transforms source code between
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -587,7 +587,8 @@ packages = ['mercurial',
             'mercurial.pure',
             'hgext', 'hgext.convert', 'hgext.fsmonitor',
             'hgext.fsmonitor.pywatchman', 'hgext.highlight',
-            'hgext.largefiles', 'hgext.zeroconf', 'hgext3rd']
+            'hgext.largefiles', 'hgext.zeroconf', 'hgext3rd',
+            'hgdemandimport']
 
 common_depends = ['mercurial/bitmanipulation.h',
                   'mercurial/compat.h',
@@ -793,7 +794,7 @@ setup(name='mercurial',
       package_data=packagedata,
       cmdclass=cmdclass,
       distclass=hgdist,
-      options={'py2exe': {'packages': ['hgext', 'email']},
+      options={'py2exe': {'packages': ['hgdemandimport', 'hgext', 'email']},
                'bdist_mpkg': {'zipdist': False,
                               'license': 'COPYING',
                               'readme': 'contrib/macosx/Readme.html',


More information about the Mercurial-devel mailing list