def _print_plugins(self) -> None: assert log is not None self._log_header(header="Installed Hydra Plugins", filler="*") all_plugins = {p.__name__ for p in Plugins.discover()} for plugin_type in [ ConfigSource, CompletionPlugin, Launcher, Sweeper, SearchPathPlugin, ]: # Mypy false positive? plugins = Plugins.discover(plugin_type) # type: ignore if len(plugins) > 0: Hydra._log_header(header="{}:".format(plugin_type.__name__), prefix="\t", filler="-") for plugin in plugins: log.debug("\t\t{}".format(plugin.__name__)) all_plugins.remove(plugin.__name__) if len(all_plugins) > 0: Hydra._log_header(header="{}:".format("Generic plugins"), prefix="\t", filler="-") for plugin_name in all_plugins: log.debug("\t\t{}".format(plugin_name))
def test_discovery() -> None: """ Tests that this plugin can be discovered via the plugins subsystem when looking for Sweeper :return: """ assert AxSweeper.__name__ in [ x.__name__ for x in Plugins.discover(Sweeper) ]
def _print_plugins(self) -> None: assert log is not None self._log_header(header="Installed Hydra Plugins", filler="*") for plugin_type in [SearchPathPlugin, Sweeper, Launcher]: Hydra._log_header(header="{}:".format(plugin_type.__name__), prefix="\t", filler="-") for plugin in Plugins.discover(plugin_type): log.debug("\t\t{}".format(plugin.__name__))
def test_number_of_imports(tmpdir: Path) -> None: os.environ["TMP_FILE"] = str(tmpdir / "import.log") # Tests that this plugin can be discovered via the plugins subsystem when looking at all Plugins assert "DiscoveryTestPlugin" in [ x.__name__ for x in Plugins.discover(Plugin) ] with Path(os.environ["TMP_FILE"]) as f: txt = str(f.read_text()) assert txt.split("\n").count("imported") == 1
def create_config_search_path( search_path_dir: Optional[str]) -> ConfigSearchPath: from hydra.core.plugins import Plugins from hydra.plugins.search_path_plugin import SearchPathPlugin Plugins.register_config_sources() search_path = ConfigSearchPathImpl() search_path.append("hydra", "pkg://hydra.conf") if search_path_dir is not None: search_path.append("main", search_path_dir) search_path_plugins = Plugins.discover(SearchPathPlugin) for spp in search_path_plugins: plugin = spp() assert isinstance(plugin, SearchPathPlugin) plugin.manipulate_search_path(search_path) return search_path
def get_shell_to_plugin_map( config_loader: ConfigLoader, ) -> DefaultDict[str, List[CompletionPlugin]]: shell_to_plugin: DefaultDict[ str, List[CompletionPlugin]] = defaultdict(list) for clazz in Plugins.discover(CompletionPlugin): assert issubclass(clazz, CompletionPlugin) plugin = clazz(config_loader) shell_to_plugin[plugin.provides()].append(plugin) for shell, plugins in shell_to_plugin.items(): if len(plugins) > 1: raise ValueError( "Multiple plugins installed for {} : {}".format( shell, ",".join([type(plugin).__name__ for plugin in plugins]))) return shell_to_plugin
def test_discovery() -> None: # Tests that this plugin can be discovered via the plugins subsystem when looking for Launchers assert JoblibLauncher.__name__ in [x.__name__ for x in Plugins.discover(Launcher)]
def test_discovery() -> None: # Tests that this plugin can be discovered via the plugins subsystem when looking at all Plugins assert ExamplePlugin.__name__ in [x.__name__ for x in Plugins.discover(Plugin)]
def test_discovery() -> None: # Test that this config source is discoverable when looking at config sources assert ConfigSourceExample.__name__ in [ x.__name__ for x in Plugins.discover(ConfigSource) ]
def test_discovery() -> None: assert core.NevergradSweeper.__name__ in [ x.__name__ for x in Plugins.discover(Sweeper) ]
def test_discover(plugin_type: Type[Plugin], expected: List[str]) -> None: plugins = Plugins.discover(plugin_type) expected_classes = [get_class(c) for c in sorted(expected)] for ex in expected_classes: assert ex in plugins