Opened 14 years ago
Closed 14 years ago
#9851 closed defect (fixed)
ExtensionPoint is missing certain components
Reported by: | 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 Component
s 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 , 14 years ago
follow-up: 7 comment:2 by , 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 , 14 years ago
Keywords: | documentation added |
---|---|
Milestone: | → 0.13 |
Owner: | set to |
Severity: | normal → minor |
comment:4 by , 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 , 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:7 by , 14 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
… 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.
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'ssetup.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 specifyingmyplugin.module.*
), theMyImpl
component should indeed be called. If yourtrac.ini
only enables theMyTestComponent
, thenMyImpl
should not be called.So AFAICT, this is working as expected, but maybe I missed your point?