author Pulkit Goyal <7895pulkit@gmail.com>
Tue, 10 Apr 2018 18:56:19 +0530
changeset 45393 2d00058ac2f8d9ddb7c2cb6f7ee40cc2319275ba
parent 39339 3cfc9070245fbaa8c4c010327f24d579a416370f
child 45878 f833f93cc0266141e53374c19e1dc7376fedcc36
child 45915 8f8f425925dbb1b18a01a096e74abefbbe9742b7
child 45945 be85b9d5969444e6e7acec1ae2ea1b4a07c6a950
permissions -rw-r--r--
py3: use bytes instead of str in isinstance() We deal with bytes internally and things should be bytes Differential Revision: https://phab.mercurial-scm.org/D3215

# 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

import os
import sys

if sys.version_info[0] >= 3:
    from . import demandimportpy3 as demandimport
    from . import demandimportpy2 as demandimport

# Extensions can add to this list if necessary.
ignore = [
    # ImportError during pkg_resources/__init__.py:fixup_namespace_package
    'nt', # pathlib2 tests the existence of built-in 'nt' module
    'win32com.shell', # 'appdirs' tries to import win32com.shell
    '_winreg', # 2.7 mimetypes needs immediate ImportError
    # imported by tarfile, not available under Windows
    # imported by profile, itself imported by hotshot.stats,
    # not available under Windows
    # this trips up many extension authors
    # setuptools' pkg_resources.py expects "from __main__ import x" to
    # raise ImportError if x not defined
    '_ssl', # conditional imports in the stdlib, issue1964
    '_sre', # issue4920
    'sqlalchemy.events', # has import-time side effects (issue5085)
    # setuptools 8 expects this module to explode early when not on windows
    'urwid.command_map', # for pudb

_pypy = '__pypy__' in sys.builtin_module_names

if _pypy:
        # _ctypes.pointer is shadowed by "from ... import pointer" (PyPy 5)


# Re-export.
isenabled = demandimport.isenabled
disable = demandimport.disable
deactivated = demandimport.deactivated

def enable():
    # chg pre-imports modules so do not enable demandimport for it
    if ('CHGINTERNALMARK' not in os.environ
        and os.environ.get('HGDEMANDIMPORT') != 'disable'):