def _find_impl(cls, role, interface): """ Find relation implementation based on its role and interface. """ # The module has already been discovered and imported. module = 'relations.{}.{}'.format(interface, role) if module not in sys.modules: try: _append_path(hookenv.charm_dir()) _append_path(os.path.join(hookenv.charm_dir(), 'hooks')) importlib.import_module(module) except ImportError: return None return cls._find_subclass(sys.modules[module])
def _relation_module(role, interface): """ Return module for relation based on its role and interface, or None. Prefers new location (reactive/relations) over old (hooks/relations). """ _append_path(hookenv.charm_dir()) _append_path(os.path.join(hookenv.charm_dir(), 'hooks')) base_module = 'relations.{}.{}'.format(interface, role) for module in ('reactive.{}'.format(base_module), base_module): if module in sys.modules: break try: importlib.import_module(module) break except ImportError: continue else: hookenv.log('Unable to find implementation for relation: ' '{} of {}'.format(role, interface), hookenv.ERROR) return None return sys.modules[module]