def default_plugin_resolver(request): # pragma: no cover res = Resolver() if request.config.getoption("--no-plugins", default=False): from metagraph.plugins import find_plugins res.register(**find_plugins()) else: res.load_plugins_from_environment() return res
def res(): from metagraph.plugins.core.types import Vector from metagraph.plugins.numpy.types import NumpyVectorType @abstract_algorithm("testing.add") def testing_add(a: Vector, b: Vector) -> Vector: # pragma: no cover pass @concrete_algorithm("testing.add", compiler="numba") def compiled_add( a: NumpyVectorType, b: NumpyVectorType) -> NumpyVectorType: # pragma: no cover return a + b @abstract_algorithm("testing.scale") def testing_scale(a: Vector, scale: float) -> Vector: # pragma: no cover pass @concrete_algorithm("testing.scale", compiler="numba") def compiled_scale(a: NumpyVectorType, scale: float) -> NumpyVectorType: # pragma: no cover return a * scale @abstract_algorithm("testing.offset") def testing_offset(a: Vector, *, offset: float) -> Vector: # pragma: no cover pass @concrete_algorithm("testing.offset", compiler="identity_comp") def compiled_offset(a: NumpyVectorType, *, offset: float) -> NumpyVectorType: # pragma: no cover return a + offset registry = PluginRegistry("test_subgraphs_plugin") registry.register(testing_add) registry.register(compiled_add) registry.register(testing_scale) registry.register(compiled_scale) registry.register(testing_offset) registry.register(compiled_offset) resolver = Resolver() # NumbaCompiler will be picked up from environment resolver.load_plugins_from_environment() resolver.register(registry.plugins) return resolver
def test_load_plugins(site_dir): res = Resolver() res.load_plugins_from_environment() def is_from_plugin1(x): if isinstance(x, set): return any(is_from_plugin1(item) for item in x) if hasattr(x, "__wrapped__"): x = x.__wrapped__ return x.__module__.endswith("plugin1") assert len([x for x in res.abstract_types if is_from_plugin1(x)]) == 1 assert len([x for x in res.concrete_types if is_from_plugin1(x)]) == 2 assert len([x for x in res.translators.values() if is_from_plugin1(x)]) == 2 assert len([x for x in res.abstract_algorithms.values() if is_from_plugin1(x)]) == 1 assert len([x for x in res.concrete_algorithms.values() if is_from_plugin1(x)]) == 1 assert "hyperstuff.supercluster" in res.concrete_algorithms