Edgewall Software
Modify

Opened 14 years ago

Closed 14 years ago

#9851 closed defect (fixed)

ExtensionPoint is missing certain components

Reported by: Sebastian Krysmanski <sebastian@…> Owned by: Christian Boos
Priority: normal Milestone: 1.0
Component: general Version: 0.12.1
Severity: minor Keywords: documentation
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description

As far as I understand it an ExtensionPoint should contain all Components that are implementing the ExtensionPoint's Interface. However, it seems that components that are initiated after the component containing the extension point has been initiated don't get included in the extension point.

Consider the following code:

class IMyInterface(Interface):
  def do_something(self):
    """ Does something """

# This component *is not* registered via trac.ini [components]
class MyImpl(Component):
  implements(IMyInterface)
  def do_something(self):
    print "Hello World"

# This component *is* registered via trac.ini [components]
class MyTestComponent(Component):
  eps = ExtensionPoint(IMyInterface)

  def __init__(self):
    # Initiate MyImpl component
    self.remember = MyImpl(self.env)

  # This method is being called from somewhere
  def some_method(self):
    for ep in eps:
      ep.do_something()

So when calling some_method() (from MyTestComponent) the extension point MyImpl isn't used (no "Hello World" is being printed) although it has already been initiated.

So the question is whether this is working as intended or whether this needs to be fixed. In the former case this should be documented somewhere.

Attachments (0)

Change History (7)

comment:1 by Remy Blank, 14 years ago

Components are not registered in trac.ini, they are merely enabled or disabled. Registration happens when the module containing the component is loaded. This can happen either due to a plugin's setup.py specifying the module in the [trac.plugins] entry points, or because the module is imported explicitly.

In your example, assuming all the code is in a single module, and all the components are enabled in trac.ini (either explicitly or by specifying myplugin.module.*), the MyImpl component should indeed be called. If your trac.ini only enables the MyTestComponent, then MyImpl should not be called.

So AFAICT, this is working as expected, but maybe I missed your point?

comment:2 by Christian Boos, 14 years ago

Hey, another collision ;-) I'm glad you came back safely home, Remy ;-)


This works as intended: registration happens during import time:

By declaring to implement the interface, it transparently registers itself as an extension of the TodoList class. in TracDev/ComponentArchitecture#Pluggingintoanextensionpoint

When iterating over an extension point, one get only the subset of activated components. In the case of the Environment as ComponentManager, this corresponds to the rules detailed in Environment.is_component_enabled.

But you're right, the documentation could be improved to make this clearer, especially in the recent api/trac_core doc, which doesn't yet talk about activation.

comment:3 by Christian Boos, 14 years ago

Keywords: documentation added
Milestone: 0.13
Owner: set to Christian Boos
Severity: normalminor

comment:4 by Remy Blank, 14 years ago

I have updated Sebastian's paragraph about this in TracDev/ComponentArchitecture@17. Feel free to improve it if it's still not clear enough.

comment:5 by Sebastian Krysmanski <sebastian@…>, 14 years ago

I've condensed the paragraph again (see TracDev/ComponentArchitecture#Declaringanextensionpoint@18) so that it just explains that only enabled components can be used in extension points. I hope it's still correct and I didn't remove any important information.

comment:6 by Remy Blank, 14 years ago

Looks good to me, thanks.

in reply to:  2 comment:7 by Christian Boos, 14 years ago

Resolution: fixed
Status: newclosed

… the documentation could be improved to make this clearer, especially in the recent api/trac_core doc, which doesn't yet talk about activation.

Done in r10544.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Christian Boos.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Christian Boos to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.