diff --git a/edbob/exceptions.py b/edbob/exceptions.py index 16ce3c5..a5a802e 100644 --- a/edbob/exceptions.py +++ b/edbob/exceptions.py @@ -42,6 +42,18 @@ class ConfigError(Exception): self.msg, self.option, self.section) +class InitError(Exception): + """ + Raised when initialization fails for a given module. + """ + + def __init__(self, module): + self.module = module + + def __str__(self): + return "Module '%s' has no init() function" % self.module.__name__ + + class LoadSpecError(Exception): """ Raised when something obvious goes wrong with :func:`edbob.load_spec()`. diff --git a/edbob/initialization.py b/edbob/initialization.py index e4c8ede..4a93344 100644 --- a/edbob/initialization.py +++ b/edbob/initialization.py @@ -35,6 +35,7 @@ from edbob.configuration import ( default_system_paths, default_user_paths, ) +from edbob.exceptions import InitError __all__ = ['init'] @@ -90,6 +91,8 @@ def init(appname='edbob', *args, **kwargs): for name in modules.split(','): name = name.strip() module = __import__(name, globals(), locals(), fromlist=['init']) + if not hasattr(module, 'init'): + raise InitError(module) getattr(module, 'init')(config) # config.inited.append(name)