#7757 closed defect (wontfix)
add ComponentManager to the list of exportable core names
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | normal | Milestone: | |
Component: | general | Version: | |
Severity: | normal | Keywords: | |
Cc: | Branch: | ||
Release Notes: | |||
API Changes: | |||
Internal Changes: |
Description
from trac.core import * cmp_mgr = ComponentManager()
Traceback (most recent call last): File "C:\test.py", line 3, in <module> cmp_mgr = ComponentManager() NameError: name 'ComponentManager' is not defined
Attachments (1)
Change History (6)
by , 16 years ago
Attachment: | export.cmpmgr.diff added |
---|
comment:1 by , 16 years ago
comment:2 by , 16 years ago
Well, to use component you need to instantiate it with ComponentManager() supplied as an argument. From TracDev/ComponentArchitecture#Puttingittogether
comp_mgr = ComponentManager() todo_list = TodoList(comp_mgr) todo_list.add('Make coffee', 'Really need to make some coffee') todo_list.add('Bug triage', 'Double-check that all known issues were addressed')
Strange it is not exported by default.
comment:3 by , 16 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
The example above is a bit biaised, as it's meant to illustrate the component architecture itself (independently of Trac). In the context of Trac plugins, the need for a ComponentManager should be rare enough that asking you to explicitly import it should be OK.
from trac.core import ComponentManager
This always works, regardless of what's listed in __all__
.
comment:4 by , 16 years ago
If it is not the ComponentManager then what should I write if I need to use a component?
comment:5 by , 16 years ago
You only need to use a ComponentManager when you don't already have one. In Trac, the Environment class inherits from the ComponentManager class, so in practice you rely on the environment for this. Also note that it's the environment which takes care about loading the plugins, the enabling/disabling logic from the .ini file, and all what you're used to in Trac plugins. So using directly a ComponentManager is most probably not what you wanted to do ;-)
In your patch on #781, you came across this need because at the versioncontrol/cache level, there's no Environment. I suggest that you take a look at what's currently being done in #7723 and see how you could adapt your idea on that basis.
What is the rationale / use case to do so ?