diff options
Diffstat (limited to 'jenkins_jobs/registry.py')
-rw-r--r-- | jenkins_jobs/registry.py | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/jenkins_jobs/registry.py b/jenkins_jobs/registry.py index 2c997737..7ac93d77 100644 --- a/jenkins_jobs/registry.py +++ b/jenkins_jobs/registry.py @@ -32,6 +32,7 @@ logger = logging.getLogger(__name__) class ModuleRegistry(object): _entry_points_cache = {} + _component_type_cache = {} def __init__(self, jjb_config, plugins_list=None): self.modules = [] @@ -128,6 +129,17 @@ class ModuleRegistry(object): def set_parser_data(self, parser_data): self.__parser_data = parser_data + def get_component_list_type(self, entry_point): + if entry_point in self._component_type_cache: + return self._component_type_cache[entry_point] + + # pkg_resources.EntryPoint.load() is costly, cache it. + component_list_type = entry_point.load().component_list_type + logging.info("Caching type %s of %s", component_list_type, entry_point) + self._component_type_cache[entry_point] = component_list_type + + return component_list_type + def dispatch(self, component_type, xml_parent, component, template_data={}): """This is a method that you can call from your implementation of Base.gen_xml or component. It allows modules to define a type @@ -154,7 +166,7 @@ class ModuleRegistry(object): ) entry_point = self.modules_by_component_type[component_type] - component_list_type = entry_point.load().component_list_type + component_list_type = self.get_component_list_type(entry_point) if isinstance(component, dict): # The component is a singleton dictionary of name: dict(args) @@ -184,6 +196,7 @@ class ModuleRegistry(object): # Look for a component function defined in an entry point eps = self._entry_points_cache.get(component_list_type) if eps is None: + logging.debug("Caching entrypoints for %s" % component_list_type) module_eps = [] # auto build entry points by inferring from base component_types mod = pkg_resources.EntryPoint( @@ -245,7 +258,7 @@ class ModuleRegistry(object): "name: '{1}'".format(component_type, name) ) - eps[module_ep.name] = module_ep + eps[module_ep.name] = module_ep.load() # cache both sets of entry points self._entry_points_cache[component_list_type] = eps @@ -268,7 +281,7 @@ class ModuleRegistry(object): # the arguments are interpolated into the real defn. self.dispatch(component_type, xml_parent, b, component_data) elif name in eps: - func = eps[name].load() + func = eps[name] func(self, xml_parent, component_data) else: raise JenkinsJobsException( |