def get_plugin_name_by_path(self, path): """Get the plugin name by the plugin file path :param path: The path to the python plugin file. :type path: str :return: Returns the plugin name. :rtype: str """ self._get_plugin_module_by_path(path) _, _, mod_name, _ = get_path_parts_tuple(path) return mod_name
def _load_plugin_modules(self): for plugin_path in self._plugins: try: mod_dir, mod_file, mod_name, mod_ext = get_path_parts_tuple(plugin_path) append_sys_path(mod_dir) imp_mod = importlib.import_module(mod_name) self._plugin_modules[plugin_path] = imp_mod except ImportError as ie: print("ERROR: Error importing module '{}'!".format(plugin_path)) sys.exit("ERROR: {}".format(ie)) except Exception as e: print("ERROR: Unknown error loading plugin module '{}'".format(plugin_path)) sys.exit("ERROR: {}".format(e))
def test_get_path_parts_tuple(): d, f, n, e = path.get_path_parts_tuple('/foo/bar/baz.py') assert d == '/foo/bar' assert f == 'baz.py' assert n == 'baz' assert e == '.py'