python类ImpImporter()的实例源码

find.py 文件源码 项目:snakefood 作者: Shapeways 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def find_dotted(names, parentdir=None):
    """
    Dotted import.  'names' is a list of path components, 'parentdir' is the
    parent directory.
    """
    filename = None
    for name in names:
        mod = ImpImporter(parentdir).find_module(name)
        if not mod:
            break
        filename = mod.get_filename()
        if not filename:
            break
        parentdir = dirname(filename)
    else:
        return filename
infra.py 文件源码 项目:localstack 作者: atlassian 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def load_plugins():
    loaded_files = []
    for module in pkgutil.iter_modules():
        if six.PY3 and not isinstance(module, tuple):
            file_path = '%s/%s/plugins.py' % (module.module_finder.path, module.name)
            if file_path not in loaded_files:
                load_plugin_from_path(file_path)
                loaded_files.append(file_path)
        elif six.PY3 or isinstance(module[0], pkgutil.ImpImporter):
            file_path = '%s/%s/plugins.py' % (module[0].path, module[1])
            if file_path not in loaded_files:
                load_plugin_from_path(file_path)
                loaded_files.append(file_path)


# -----------------
# API ENTRY POINTS
# -----------------
test_pkgutil.py 文件源码 项目:web_ctp 作者: molebot 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test_importer_deprecated(self):
        with self.check_deprecated():
            x = pkgutil.ImpImporter("")
test_pkgutil.py 文件源码 项目:ouroboros 作者: pybee 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def test_importer_deprecated(self):
        with self.check_deprecated():
            x = pkgutil.ImpImporter("")
experiment.py 文件源码 项目:snakefood 作者: Shapeways 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def find_mod(modname, fn):

    print '\n\n\n-----', modname, fn

    mod = ImpImporter().find_module(modname)
    print 'global', mod, mod and mod.get_filename()

    mod = ImpImporter(dirname(fn)).find_module(modname)
    print 'local', mod, mod and mod.get_filename()

    try:
        mod = find_module(modname)
    except ImportError:
        mod = 'ERROR'
    print 'imp global', mod

    try:
        mod = find_module(modname, dirname(fn))
    except ImportError:
        mod = 'ERROR'
    print 'imp local', mod





## print find_module('ctypes.util')
## print find_module('util', '/usr/lib/python2.5/ctypes/__init__.py')
## raise SystemExit
test_pkgutil.py 文件源码 项目:kbe_server 作者: xiaohaoppy 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def test_importer_deprecated(self):
        with self.check_deprecated():
            x = pkgutil.ImpImporter("")
infra.py 文件源码 项目:localstack 作者: localstack 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def load_plugins(scope=None):
    scope = scope or PLUGIN_SCOPE_SERVICES
    if PLUGINS_LOADED.get(scope, None):
        return

    setup_logging()

    loaded_files = []
    result = []
    for module in pkgutil.iter_modules():
        file_path = None
        if six.PY3 and not isinstance(module, tuple):
            file_path = '%s/%s/plugins.py' % (module.module_finder.path, module.name)
        elif six.PY3 or isinstance(module[0], pkgutil.ImpImporter):
            if hasattr(module[0], 'path'):
                file_path = '%s/%s/plugins.py' % (module[0].path, module[1])
        if file_path and file_path not in loaded_files:
            plugin_config = load_plugin_from_path(file_path, scope=scope)
            if plugin_config:
                result.append(plugin_config)
            loaded_files.append(file_path)
    # set global flag
    PLUGINS_LOADED[scope] = result
    return result


# -----------------
# API ENTRY POINTS
# -----------------


问题


面经


文章

微信
公众号

扫码关注公众号