当前位置: 首页>>代码示例>>Python>>正文


Python importlib.reload方法代码示例

本文整理汇总了Python中importlib.reload方法的典型用法代码示例。如果您正苦于以下问题:Python importlib.reload方法的具体用法?Python importlib.reload怎么用?Python importlib.reload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在importlib的用法示例。


在下文中一共展示了importlib.reload方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: logged_example_testcase

# 需要导入模块: import importlib [as 别名]
# 或者: from importlib import reload [as 别名]
def logged_example_testcase(name, imported, path):
    """Returns a method for attaching to a unittest.TestCase that imports
    or reloads module 'name' and stores in imported[name].
    Runs top-level code, which is typically a docs example, in the process.

    Returns a method.
    """
    def test(self):
        # pylint: disable=missing-docstring
        # No docstring because it'd be uselessly the same for each example
        filepath = ("".join([path, os.sep, "%s_output.txt" % name])
                    if name not in imported else None)
        with StdoutCaptured(logfilepath=filepath):
            if name not in imported:
                imported[name] = importlib.import_module(name)
            else:
                importlib.reload(imported[name])
        getattr(self, name)(imported[name])
    return test 
开发者ID:convexengineering,项目名称:gpkit,代码行数:21,代码来源:helpers.py

示例2: do_plugin_initialisation_for_tests

# 需要导入模块: import importlib [as 别名]
# 或者: from importlib import reload [as 别名]
def do_plugin_initialisation_for_tests():
    # The next imports and reloading are needed only in tests, since in
    # production none of these modules would be loaded before plugins are
    # setup (not initialised)
    import plenum.server
    import plenum.common

    importlib.reload(plenum.server.replica)
    importlib.reload(plenum.server.consensus.view_change_trigger_service)
    importlib.reload(plenum.server.consensus.view_change_service)
    importlib.reload(plenum.server.consensus.view_change_storages)
    importlib.reload(plenum.server.consensus.ordering_service)
    importlib.reload(plenum.server.consensus.ordering_service_msg_validator)
    importlib.reload(plenum.server.node)
    importlib.reload(plenum.server.catchup.utils)
    importlib.reload(plenum.server.catchup.catchup_rep_service)
    importlib.reload(plenum.server.catchup.cons_proof_service)
    importlib.reload(plenum.server.catchup.ledger_leecher_service)
    importlib.reload(plenum.server.catchup.node_leecher_service)
    importlib.reload(plenum.server.catchup.seeder_service)
    importlib.reload(plenum.server.message_handlers)
    importlib.reload(plenum.server.observer.observable)
    importlib.reload(plenum.common.ledger_manager) 
开发者ID:hyperledger,项目名称:indy-plenum,代码行数:25,代码来源:conftest.py

示例3: reload_materials

# 需要导入模块: import importlib [as 别名]
# 或者: from importlib import reload [as 别名]
def reload_materials(self, shader_filepath):
        reload_shader_names = []
        resource_names = list(self.resources.keys())
        for resource_name in resource_names:
            reload = False
            meta_data = self.resources[resource_name].meta_data
            if meta_data:
                if shader_filepath == meta_data.source_filepath:
                    reload = True
                elif meta_data and hasattr(meta_data, 'include_files'):
                    for include_file in meta_data.include_files:
                        if shader_filepath == include_file:
                            reload = True
                            break
            if reload:
                self.load_resource(resource_name)
                material = self.get_resource_data(resource_name)
                if material and material.shader_name not in reload_shader_names:
                    reload_shader_names.append(material.shader_name)

        for shader_name in reload_shader_names:
            self.resource_manager.material_instance_loader.reload_material_instances(shader_name) 
开发者ID:ubuntunux,项目名称:PyEngine3D,代码行数:24,代码来源:ResourceManager.py

示例4: load_debugtalk_functions

# 需要导入模块: import importlib [as 别名]
# 或者: from importlib import reload [as 别名]
def load_debugtalk_functions() -> Dict[Text, Callable]:
    """ load project debugtalk.py module functions
        debugtalk.py should be located in project root directory.

    Returns:
        dict: debugtalk module functions mapping
            {
                "func1_name": func1,
                "func2_name": func2
            }

    """
    # load debugtalk.py module
    try:
        imported_module = importlib.import_module("debugtalk")
    except Exception as ex:
        logger.error(f"error occurred in debugtalk.py: {ex}")
        sys.exit(1)

    # reload to refresh previously loaded module
    imported_module = importlib.reload(imported_module)
    return load_module_functions(imported_module) 
开发者ID:httprunner,项目名称:httprunner,代码行数:24,代码来源:loader.py

示例5: patch_reload

# 需要导入模块: import importlib [as 别名]
# 或者: from importlib import reload [as 别名]
def patch_reload():
    if sys.version_info[0] >= 3:
        import builtins # Py3
    else:
        import __builtin__ as builtins

    if hasattr(builtins, "reload"):
        sys.builtin_orig_reload = builtins.reload
        builtins.reload = patched_reload(sys.builtin_orig_reload)  # @UndefinedVariable
        try:
            import imp
            sys.imp_orig_reload = imp.reload
            imp.reload = patched_reload(sys.imp_orig_reload)  # @UndefinedVariable
        except:
            pass
    else:
        try:
            import importlib
            sys.importlib_orig_reload = importlib.reload  # @UndefinedVariable
            importlib.reload = patched_reload(sys.importlib_orig_reload)  # @UndefinedVariable
        except:
            pass

    del builtins 
开发者ID:fabioz,项目名称:PyDev.Debugger,代码行数:26,代码来源:_pydev_sys_patch.py

示例6: cancel_patches_in_sys_module

# 需要导入模块: import importlib [as 别名]
# 或者: from importlib import reload [as 别名]
def cancel_patches_in_sys_module():
    sys.exc_info = sys.system_exc_info  # @UndefinedVariable
    if sys.version_info[0] >= 3:
        import builtins # Py3
    else:
        import __builtin__ as builtins

    if hasattr(sys, "builtin_orig_reload"):
        builtins.reload = sys.builtin_orig_reload

    if hasattr(sys, "imp_orig_reload"):
        import imp
        imp.reload = sys.imp_orig_reload

    if hasattr(sys, "importlib_orig_reload"):
        import importlib
        importlib.reload = sys.importlib_orig_reload

    del builtins 
开发者ID:fabioz,项目名称:PyDev.Debugger,代码行数:21,代码来源:_pydev_sys_patch.py

示例7: load_configure_json

# 需要导入模块: import importlib [as 别名]
# 或者: from importlib import reload [as 别名]
def load_configure_json(self, configure_file_path: str) -> None:
        """method for reading and applying json configuration.

        :param configure_file_path: json configure file path
        :return: None
        """
        logging.debug(f"try load configure from json file ({configure_file_path})")

        try:
            with open(configure_file_path) as json_file:
                json_data = json.load(json_file)

            for configure_key, configure_value in json_data.items():
                try:
                    configure_type, configure_value = self.__check_value_type(type(configure_value), configure_value)
                    self.__set_configure(configure_key, configure_type, configure_value)
                except Exception as e:
                    # no configure value
                    logging.debug(f"this is not configure key({configure_key}): {e}")

        except Exception as e:
            exit(f"cannot open json file in ({configure_file_path}): {e}")

        importlib.reload(loopchain.utils) 
开发者ID:icon-project,项目名称:loopchain,代码行数:26,代码来源:configure.py

示例8: test_loading_remote_logging_with_wasb_handler

# 需要导入模块: import importlib [as 别名]
# 或者: from importlib import reload [as 别名]
def test_loading_remote_logging_with_wasb_handler(self):
        """Test if logging can be configured successfully for Azure Blob Storage"""
        from airflow.config_templates import airflow_local_settings
        from airflow.logging_config import configure_logging
        from airflow.utils.log.wasb_task_handler import WasbTaskHandler

        with conf_vars({
            ('logging', 'remote_logging'): 'True',
            ('logging', 'remote_log_conn_id'): 'some_wasb',
            ('logging', 'remote_base_log_folder'): 'wasb://some-folder',
        }):
            importlib.reload(airflow_local_settings)
            configure_logging()

        logger = logging.getLogger('airflow.task')
        self.assertIsInstance(logger.handlers[0], WasbTaskHandler) 
开发者ID:apache,项目名称:airflow,代码行数:18,代码来源:test_logging_config.py

示例9: run

# 需要导入模块: import importlib [as 别名]
# 或者: from importlib import reload [as 别名]
def run(self, args):
        toreload, toremove = set(), set()
        packages = [(p, p.split('.')) for p in args.package]
        for name, module in sys.modules.items():
            path = name.split('.')
            for p, ps in packages:
                if p == name:
                    toreload.add(name)
                elif ps == path[:len(ps)]:
                    toremove.add(name)

        for name in toremove:
            if name not in toreload:
                del sys.modules[name]

        for name in sorted(toreload):
            importlib.reload(sys.modules[name]) 
开发者ID:wapiflapi,项目名称:gxf,代码行数:19,代码来源:reload.py

示例10: walk

# 需要导入模块: import importlib [as 别名]
# 或者: from importlib import reload [as 别名]
def walk(path, parent_dir=None):
        import importlib
        import os

        for entry in os.scandir(path):

            if entry.is_file() and entry.name.endswith(".py"):
                filename, _ = os.path.splitext(entry.name)
                is_init = filename == "__init__"

                if parent_dir:
                    module = parent_dir if is_init else f"{parent_dir}.{filename}"
                else:
                    if is_init:
                        continue
                    module = filename

                importlib.reload(eval(module))

            elif entry.is_dir() and not entry.name.startswith((".", "__")):
                dirname = f"{parent_dir}.{entry.name}" if parent_dir else entry.name
                walk(entry.path, parent_dir=dirname) 
开发者ID:mrachinskiy,项目名称:commotion,代码行数:24,代码来源:__init__.py

示例11: include_dirs_hook

# 需要导入模块: import importlib [as 别名]
# 或者: from importlib import reload [as 别名]
def include_dirs_hook():
        if hasattr(builtins, '__NUMPY_SETUP__'):
            del builtins.__NUMPY_SETUP__
        import numpy
        importlib.reload(numpy)

        ext = Extension('test', [])
        # ext.include_dirs.append(numpy.get_include())
        #iOS: 
        ext.include_dirs.append('../../onIpad/lib/python3.7/site-packages/numpy-1.16.0-py3.7-macosx-10.9-x86_64.egg/numpy/core/include/')
        print("Include dirs found: ", numpy.get_include())
        if not has_include_file(
                ext.include_dirs, os.path.join("numpy", "arrayobject.h")):
            warnings.warn(
                "The C headers for numpy could not be found. "
                "You may need to install the development package")
        #iOS: 
        return ['../../onIpad/lib/python3.7/site-packages/numpy-1.16.0-py3.7-macosx-10.9-x86_64.egg/numpy/core/include/']
        # return [numpy.get_include()] 
开发者ID:holzschu,项目名称:python3_ios,代码行数:21,代码来源:setupext.py

示例12: load_module

# 需要导入模块: import importlib [as 别名]
# 或者: from importlib import reload [as 别名]
def load_module(name):
        """
        Import or reload tutorial module as needed.
        """
        target = 'cherrypy.tutorial.' + name
        if target in sys.modules:
            module = importlib.reload(sys.modules[target])
        else:
            module = importlib.import_module(target)
        return module 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:12,代码来源:test_tutorials.py

示例13: reload_zmirror

# 需要导入模块: import importlib [as 别名]
# 或者: from importlib import reload [as 别名]
def reload_zmirror(self, configs_dict=None):
        self.del_temp_var()

        import config
        importlib.reload(config)

        test_config_names = (name for name in dir(self.C) if name[:2] != '__' and name[-2:] != '__')
        for config_name in test_config_names:
            config_value = getattr(self.C, config_name)
            setattr(config, config_name, config_value)

        if configs_dict is not None:
            for config_name, config_value in configs_dict.items():
                setattr(config, config_name, config_value)

        import zmirror.cache_system as cache_system
        import zmirror.zmirror as zmirror
        importlib.reload(cache_system)
        importlib.reload(zmirror)

        zmirror.app.config['TESTING'] = True

        # 处理有端口号的测试, 在 del_temp_var() 中回滚
        if hasattr(self.C, "my_host_port"):
            port = getattr(self.C, "my_host_port", None)
            my_host_name = getattr(self.C, "my_host_name", "127.0.0.1")
            if port is not None:
                self.C.my_host_name_no_port = my_host_name
                self.C.my_host_name = self.C.my_host_name_no_port + ":" + str(port)
            else:
                self.C.my_host_name_no_port = my_host_name
        elif hasattr(self.C, "my_host_name"):
            self.C.my_host_name_no_port = self.C.my_host_name

        self.client = zmirror.app.test_client()  # type: FlaskClient
        self.app = zmirror.app  # type: Flask
        self.zmirror = zmirror 
开发者ID:aploium,项目名称:zmirror,代码行数:39,代码来源:base_class.py

示例14: test_eth_account_default_kdf

# 需要导入模块: import importlib [as 别名]
# 或者: from importlib import reload [as 别名]
def test_eth_account_default_kdf(acct, monkeypatch):
    assert os.getenv('ETH_ACCOUNT_KDF') is None
    assert acct._default_kdf == 'scrypt'

    monkeypatch.setenv('ETH_ACCOUNT_KDF', 'pbkdf2')
    assert os.getenv('ETH_ACCOUNT_KDF') == 'pbkdf2'

    import importlib
    from eth_account import account
    importlib.reload(account)
    assert account.Account._default_kdf == 'pbkdf2' 
开发者ID:ethereum,项目名称:eth-account,代码行数:13,代码来源:test_accounts.py

示例15: test_exception_is_raised_when_no_settings

# 需要导入模块: import importlib [as 别名]
# 或者: from importlib import reload [as 别名]
def test_exception_is_raised_when_no_settings(client, backend):
    with override_settings(PHONE_VERIFICATION=backend):
        del settings.PHONE_VERIFICATION
        with pytest.raises(ImproperlyConfigured) as exc:
            importlib.reload(phone_verify.services)
            PhoneVerificationService(phone_number="+13478379634")
            assert exc.info == "Please define PHONE_VERIFICATION in settings" 
开发者ID:CuriousLearner,项目名称:django-phone-verify,代码行数:9,代码来源:test_services.py


注:本文中的importlib.reload方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。