コード例 #1
0
def ReloadModules():
    """Force reload of the modules
    This way Salome does not have to be reopened
    when something in the modules is changed
    Very helpful (and only needed) for developing
    """

    logger.debug("Starting to reload modules")

    def ReloadListOfModules(list_modules):
        for module_name in list_modules:
            module_name = 'kratos_salome_plugin.' + module_name # forcing that only things from the "kratos_salome_plugin" folder can be imported
            the_module = __import__(module_name, fromlist=[module_name[-1]])
            importlib.reload(the_module)

    # first reload the real modules then the "__init__.py" files (some "__init__.py"s depend on other files but not vise-versa!)
    ReloadListOfModules(MODULE_RELOAD_ORDER)
    # the order overall should not matter since the "__init__.py"s don't (really should not) depend on each other
    ReloadListOfModules(utilities.GetInitModulesInDirectory(utilities.GetPluginPath()))

    # check the list
    # Note: performing the checks after reloading, this way Salome does not have to be closed for changing the list (bcs we are also reloading MODULE_RELOAD_ORDER)
    for module_name in MODULE_RELOAD_ORDER:
        if MODULE_RELOAD_ORDER.count(module_name) > 1:
            raise Exception('Module "{}" exists multiple times in the module reload order list!'.format(module_name))

    for module_name in utilities.GetPythonModulesInDirectory(utilities.GetPluginPath()):
        if module_name not in MODULE_RELOAD_ORDER and module_name != "salome_plugins":
            raise Exception('The python file "{}" was not added to the list for reloading modules!'.format(module_name))

    logger.debug("Successfully reloaded modules")
コード例 #2
0
    def test_CheckOrderModulesReloadPlugin(self):
        # make sure all modules are specified in the module reload list
        order_module_reload = MODULE_RELOAD_ORDER
        self.assertFalse(
            "salome_plugins" in order_module_reload
        )  # "salome_plugins" is the main file of the plugin and must not be reloaded!

        self.assertEqual(len(order_module_reload), len(
            set(order_module_reload)))  # check for duplicated entries

        all_modules = utils.GetPythonModulesInDirectory(utils.GetPluginPath())

        self.assertListEqual(
            sorted(all_modules), sorted(order_module_reload)
        )  # sort here, bcs order does not matter for only checking the contents
コード例 #3
0
 def test_GetPluginPath(self):
     # make sure the path points to the "plugins" folder, aka ends with "plugin"
     self.assertEqual(
         os.path.split(utils.GetPluginPath())[1], "kratos_salome_plugin")