On Mar 7, 2007, at 12:57 PM, robinbryce wrote:

>
> Hi,
>
> On the tw trunk; The engine manager currently unconditionally loads
> all "python.templating.engines" entry points::
>
> toscawidgets.view.py
>         for entrypoint in
> iter_entry_points("python.templating.engines"):
>             engine_factory = entrypoint.load()
>             self._factories[entrypoint.name] = engine_factory
>
> pkg_resources yields entry points in distribution order - as defined
> by "first on path" to "last on path"
>
>  AFAICT; If two modules define the same entry point, for example
> 'genshi', then the *last* distribution to define the entry point wins.
> I propose that this should be changed to *first wins" and the above
> entrypoint.load() should be guarded::
>
>     if entrypoint.name not in self._factories:
>         engine_factory = entrypoint.load()
>         self._factories[entrypoint.name] = engine_factory
>
> Typically the application can arrange to control its PYTHONPATH and,
> in extremes, the contents of pkg_resources.working_set.entries. The
> above change would allow an application to intercept engine
> instantiation in a relatively painless way.
>
> A specific motivation for wanting this change is the way Genshi 0.3.6
> implements its plugin::
>
>     class AbstractTemplateEnginePlugin(object):
>         """Implementation of the plugin API."""
>
>         template_class = None
>         extension = None
>
>         def __init__(self, extra_vars_func=None, options=None):
>             if options is None:
>                 options = {}
>             # TODO get loader_args from the options dict
>
>             self.loader = TemplateLoader(auto_reload=True)
>             self.options = options
>             self.get_extra_vars = extra_vars_func
>
> In particular; it does not seek to obtain the 'search_path' used for
> Xinlcuded documents from options and I need this.
>
> Perhaps there is a broader question here; What is the "right
> thing"(tm) wrt treatment of multiply defined package entry points that
> represent extensions to specific areas of functionality ?
>
> Thoughts anyone ?

I guess you want to load the genshi template plugin from a specific  
version of Genshi, right? If that is the case I've made a patch that  
adds a method to the EngineManager to load the entrypoint from a  
specific distribution. To use it you'll need to subclass the specific  
HostFramework class you're using and, instead of letting the EM  
initialize itself with "load_all", call  
"load_engine_from_distribution" instead with the distribution you  
need plus extra options if needed. You could also do something like  
this after the EM is initialized (that is, after the  
toscawidgets.mods.XXX module you're using is imported):

from toscawidgets import framework
options = {'search_path' : 'foo'}
framework.engines.load_engine_from_distribution("Genshi == 0.3.6",  
"genshi", options)

Try out the attached patch and if it's fine I'll commit it when I  
have a chance.

Alberto


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears Trunk" group.
To post to this group, send email to turbogears-trunk@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears-trunk?hl=en
-~----------~----~----~----~------~----~------~--~---

Attachment: load_from_dist.diff.gz
Description: GNU Zip compressed data

Reply via email to