Edgewall Software
Modify

Opened 16 years ago

Closed 16 years ago

Last modified 16 years ago

#7757 closed defect (wontfix)

add ComponentManager to the list of exportable core names

Reported by: techtonik <techtonik@…> 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)

export.cmpmgr.diff (395 bytes ) - added by techtonik <techtonik@…> 16 years ago.

Download all attachments as: .zip

Change History (6)

by techtonik <techtonik@…>, 16 years ago

Attachment: export.cmpmgr.diff added

comment:1 by Emmanuel Blot, 16 years ago

What is the rationale / use case to do so ?

comment:2 by techtonik <techtonik@…>, 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 Christian Boos, 16 years ago

Resolution: wontfix
Status: newclosed

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 techtonik <techtonik@…>, 16 years ago

If it is not the ComponentManager then what should I write if I need to use a component?

comment:5 by Christian Boos, 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.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The ticket will remain with no owner.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from (none) 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.