Oh, excellent. Exactly what I wanted; I feel truly spoiled :-D

[sending this for the second time - no idea what happened to last
nights reply]

The patch applied perfectly and works a charm. I noticed that you
don't make any attempt to clear out cached templates in
_initialize_engine. Think this is the right thing to do; this kind of
customization is really a "during startup or certainly before first
render" feature.

> 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

Yes, for a variety of reasons I have my own start_extentions entry
point. Which, amongst other things, completely by passes tg.config.
With your patch the following worked perfectly::


        framework =toscawidgets.framework = self.widget_framework =
TurbogearsHost(
                environ=dict(turbogears_config =
self.turbogears_config)
                )
        framework.engines.load_all(self.turbogears_config)
        framework.engines.load_engine_from_distribution(
                'MyApp', 'genshi',
                engine_options, stdvars=stdvars)
        framework.engines.load_engine_from_distribution(
                'MyApp', 'genshi-markup',
                engine_options)

Initialization of the genshi plugin (In Genshi 0.3.6) is the thing I
actually want to intercept. There is a minimal wrapper in 'MyApp' that
supliments the existing options handling to forward loader options to
TemplateLoader.

I'm running with tg.defaultview set to "genshi" but temporarily switch
it back to "kid" while turbogears is importing; in order to let the tg
widgets find there legacy templates. Once tg is up I do::

        turbogears.view.base.engines['genshi'] = self.genshi
        turbogears.view.base.engines['genshi-markup'] = self.genshi

And now I have my Pony :-)

Again: Thankyou!

Best Regards,
Robin



On Mar 7, 4:56 pm, Alberto Valverde <[EMAIL PROTECTED]> wrote:
> 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
>
>  load_from_dist.diff.gz
> 1KDownload


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to