Skip to content

Commit

Permalink
Merge pull request #213 from alexeyklyukin/bugfix/entrypoints-templates
Browse files Browse the repository at this point in the history
Fix minor issues with pluggable templates.
  • Loading branch information
jmcs committed May 12, 2016
2 parents fa5f9c6 + 98af416 commit 5db4b24
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions senza/templates/__init__.py
@@ -1,9 +1,13 @@
from types import ModuleType
from types import ModuleType, FunctionType
import pkg_resources


def get_template_description(name, module: ModuleType):
return '{}: {}'.format(name, module.__doc__.strip())
return '{}: {}'.format(name, (module.__doc__ or "").strip())


def has_functions(module, names):
return all(isinstance(getattr(module, function_name, None), FunctionType) for function_name in names)


def get_templates() -> dict:
Expand All @@ -19,5 +23,8 @@ def get_templates() -> dict:
# ignore bad entry points
continue
else:
template_modules[e.name] = module
# make sure the entry point resolves to a module with the essential interface functions
if (isinstance(module, ModuleType) and
has_functions(module, ('gather_user_variables', 'generate_definition'))):
template_modules[e.name] = module
return template_modules

0 comments on commit 5db4b24

Please sign in to comment.