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',