def test_get_plugins_path_and_load(self): savu_path = os.path.split(savu.__path__[0])[0] plugin_path = os.path.join(savu_path, "plugin_examples") os.environ["SAVU_PLUGINS_PATH"] = plugin_path pu.get_plugins_paths() plugin = pu.load_plugin("example_median_filter") self.assertEqual(plugin.name, "ExampleMedianFilter") os.environ["SAVU_PLUGINS_PATH"] = ""
def __init__(self, options): class_name = "savu.core.transports." + options["transport"] \ + "_transport" cu.add_base(self, cu.import_class(class_name)) self._transport_control_setup(options) self.exp = None self.options = options # add all relevent locations to the path pu.get_plugins_paths()
def __init__(self, options, name='PluginRunner'): class_name = "savu.core.transports." + options["transport"] \ + "_transport" cu.add_base(self, cu.import_class(class_name)) super(PluginRunner, self).__init__() # ********* transport function *********** self._transport_initialise(options) self.options = options # add all relevent locations to the path pu.get_plugins_paths() self.exp = Experiment(options)
def populate_plugins(): """ Loads plugins from plugin paths. Almost identical to the function in scripts.config_generator """ def _add_module(loader, module_name): if module_name not in sys.modules: try: loader.find_module(module_name).load_module(module_name) except Exception: pass # load all the plugins plugins_path = pu.get_plugins_paths() savu_path = plugins_path[-1].split('savu')[0] savu_plugins = plugins_path[-1:] local_plugins = plugins_path[0:-1] + [savu_path + 'plugins_examples'] # load local plugins for loader, module_name, is_pkg in pkgutil.walk_packages(local_plugins): _add_module(loader, module_name) # load savu plugins for loader, module_name, is_pkg in pkgutil.walk_packages(savu_plugins): if module_name.split('savu.plugins')[0] == '': _add_module(loader, module_name)
def populate_plugins(error_mode=False, examples=False): # load all the plugins plugins_paths = pu.get_plugins_paths(examples=examples) failed_imports = {} for path, name in plugins_paths.items(): for finder, module_name, is_pkg in pkgutil.walk_packages([path], name): if not is_pkg: _load_module(finder, module_name, failed_imports, error_mode)
def main(): print("Starting Savu Config tool (please wait for prompt)") comp = Completer() # we want to treat '/' as part of a word, so override the delimiters readline.set_completer_delims(' \t\n;') readline.parse_and_bind("tab: complete") readline.set_completer(comp.complete) # load all the packages in the plugins directory to register classes plugins_path = pu.get_plugins_paths() for loader, module_name, is_pkg in pkgutil.walk_packages(plugins_path): try: # if the module is in savu, but not a plugin, then ignore if "savu" in module_name.split('.'): if "plugins" not in module_name.split('.'): continue # setup.py is included in this list which should also be ignored if module_name in ["setup", "savu.plugins.utils"]: continue if module_name not in sys.modules: loader.find_module(module_name).load_module(module_name) except Exception as e: pass # set up things input_string = "startup" content = Content("") while True: input_string = raw_input(">>> ").strip() if len(input_string) == 0: command = 'help' arg = "" else: command = input_string.split()[0] arg = ' '.join(input_string.split()[1:]) # try to run the command if command in commands.keys(): content = commands[command](content, arg) else: print("I'm sorry, thats not a command I recognise, try help") if content.is_finished(): break # write the history to the histoy file readline.write_history_file(histfile) print("Thanks for using the application")
def populate_plugins(dawn=True): # load all the plugins plugins_path = pu.get_plugins_paths() savu_path = plugins_path[-1].split('savu')[0] savu_plugins = plugins_path[-1:] local_plugins = plugins_path[0:-1] + [savu_path + 'plugins_examples'] # load local plugins for loader, module_name, is_pkg in pkgutil.walk_packages(local_plugins): _add_module(loader, module_name) # load savu plugins for loader, module_name, is_pkg in pkgutil.walk_packages(savu_plugins): if module_name.split('savu.plugins')[0] == '': _add_module(loader, module_name) if dawn: _dawn_setup()
def populate_plugins(dawn=False, error_mode=False, examples=False): # load all the plugins plugins_path = pu.get_plugins_paths(examples=examples) savu_plugins = plugins_path[-1:] local_plugins = plugins_path[0:-1] failed_imports = {} # load local plugins for loader, module_name, is_pkg in pkgutil.walk_packages(local_plugins): _add_module(failed_imports, loader, module_name, error_mode) # load savu plugins for loader, module_name, is_pkg in pkgutil.walk_packages(savu_plugins): if module_name.split('savu.plugins')[0] == '': _add_module(failed_imports, loader, module_name, error_mode) if dawn: _dawn_setup() return failed_imports
def populate_plugins(): # load all the plugins plugins_path = pu.get_plugins_paths() savu_path = plugins_path[-1].split('savu')[0] savu_plugins = plugins_path[-1:] local_plugins = plugins_path[0:-1] + [savu_path + 'plugins_examples'] # load local plugins for loader, module_name, is_pkg in pkgutil.walk_packages(local_plugins): _add_module(loader, module_name) # load savu plugins for loader, module_name, is_pkg in pkgutil.walk_packages(savu_plugins): if module_name.split('savu.plugins')[0] == '': _add_module(loader, module_name) for plugin in pu.dawn_plugins.keys(): p = pu.plugins[plugin]() pu.dawn_plugins[plugin]['input rank'] = \ du.get_pattern_rank(p.get_plugin_pattern()) pu.dawn_plugins[plugin]['description'] = p.__doc__.split(':param')[0] params = _get_dawn_parameters(p) pu.dawn_plugin_params[plugin] = params
def populate_plugins(): """ Loads plugins from plugin paths. Almost identical to the function in scripts.config_generator.config_utils """ def _load_module(finder, module_name): if module_name not in sys.modules: try: spec = finder.find_spec(module_name) mod = importlib.util.module_from_spec(spec) sys.modules[spec.name] = mod spec.loader.exec_module(mod) except Exception: pass # load all plugins except example ones plugins_paths = pu.get_plugins_paths(examples=False) for path, name in plugins_paths.items(): for finder, module_name, is_pkg in pkgutil.walk_packages([path], name): if not is_pkg: _load_module(finder, module_name)
def test_get_plugins_paths2(self): n_paths = len(pu.get_plugins_paths()) self._add_to_plugins_path("/tmp/:/dev/:/home/") paths = pu.get_plugins_paths() self.assertEqual(len(paths), n_paths + 3)
def test_get_plugins_paths(self): paths = pu.get_plugins_paths() self.assertEqual(len(paths), 1)
def test_get_plugins_paths2(self): os.environ["SAVU_PLUGINS_PATH"] = "/tmp/" paths = pu.get_plugins_paths() self.assertEqual(len(paths), 2) os.environ["SAVU_PLUGINS_PATH"] = ""
def test_get_plugins_paths3(self): os.environ["SAVU_PLUGINS_PATH"] = "/tmp/:/dev/:/home/" paths = pu.get_plugins_paths() self.assertEqual(len(paths), 4) os.environ["SAVU_PLUGINS_PATH"] = ""
def test_get_plugins_paths(self): n_paths = len(pu.get_plugins_paths()) self._add_to_plugins_path('/tmp') paths = pu.get_plugins_paths() self.assertEqual(len(paths), n_paths + 1)
def test_get_plugins_paths2(self): n_paths = len(pu.get_plugins_paths()) os.environ["SAVU_PLUGINS_PATH"] = "/tmp/:/dev/:/home/" paths = pu.get_plugins_paths() self.assertEqual(len(paths), n_paths + 3) os.environ["SAVU_PLUGINS_PATH"] = ""