
Chris.Nelson at SIXNET
Dec 5, 2011, 8:17 AM
Post #13 of 14
(378 views)
Permalink
|
|
Re: Re: Stupid question about enabling components
[In reply to]
|
|
On 12/05/2011 09:51 AM, Olemis Lang wrote: > On Mon, Dec 5, 2011 at 9:37 AM, Chris Nelson<Chris.Nelson [at] sixnet> wrote: >> >> On 12/05/2011 09:06 AM, Olemis Lang wrote: >>> >>> On Mon, Dec 5, 2011 at 7:57 AM, Chris Nelson<Chris.Nelson [at] sixnet> wrote: >>> I think you are missing the point here that ExtensionOption offers a >>> way to instantiate Components by relying on Python descriptors magic . >>> Hence that's not the way to go if you want to list the entries under >>> [components] section in trac.ini . I mentioned before you have >>> basically two ways to go : >>> >>> - Use `env.config` object so as to read information in trac.ini file directly >>> - Use `ComponentMeta._registry` to list the classes implementing a >>> given interface >>> (review the code for `ExtensionPoint.extensions` method for further details ;) >>> and then invoke `ComponentManager.is_component_enabled` so as to >>> know whether that particular class is enabled/disabled in that particular >>> Trac environment. >> >> >> I understand there are several ways to do this. If I wanted multiple listeners or processors or whatever, I could use an ExtensionPoint and iterate over all the enabled implementations. But what I want is a configurable single handler. I believe that the way to do that is an ExtensionOption. I've used that successfully for functions in my own plugin but when I try to instantiate an implementation in another plugin, it fails. >> >> The class TeamCalendar is implemented in the module calendar.py in the plugin teamcalendar but when I pass "teamcalendar.calendar.TeamCalendar' to ExtensionOption, it fails to find the class. >> >> Cannot find an implementation of the "IResourceCalendar" interface >> named "teamcalendar.calendar.TeamCalendar". Please update the >> option TracPM.calendar in trac.ini. >> >> How can I find the real name of the class? >> > > In that case you should use trac.config.ExtensionOption descriptors , > rather than defining extension points > ;) I'm not using an ExtensionPoint. I mention that only because I understand that is a way to have pluggable interfaces. I don't know what a "trac.config.ExtensionOption descriptor" is. My trac.ini says: [TracPM] ... calendar = teamcalendar.calendar.TeamCalendar and my code says: cal = ExtensionOption('TracPM', 'calendar', IResourceCalendar, 'SimpleCalendar') and I see: Cannot find an implementation of the "IResourceCalendar" interface named "teamcalendar.calendar.TeamCalendar". Please update the option TracPM.calendar in trac.ini. If I remove the trac.ini entry, and change the code to: cal = ExtensionOption('TracPM', 'calendar', IResourceCalendar, 'teamcalendar.calendar.TeamCalendar') I get the same error. If I try to import teamcalendar.calendar.TeamCalendar into tracjsgantt/tracpm.py and change to: cal = TeamCalendar(self.env) TracJSGantt won't even load. The page says: No macro or processor named 'TracJSGanttChart' found and my trac.log says: 2011-12-05 11:14:14,029 Trac[loader] ERROR: Skipping "tracjsgantt = tracjsgantt": (can't import "ImportError: cannot import name IResourceCalendar") I don't know what's missing! Chris -- Christopher Nelson, Software Engineering Manager SIXNET - Solutions for Your Industrial Networking Challenges 331 Ushers Road, Ballston Lake, NY 12019 Tel: +1.518.877.5173, Fax: +1.518.877.8346 www.sixnet.com -- You received this message because you are subscribed to the Google Groups "Trac Users" group. To post to this group, send email to trac-users [at] googlegroups To unsubscribe from this group, send email to trac-users+unsubscribe [at] googlegroups For more options, visit this group at http://groups.google.com/group/trac-users?hl=en.
|