bzr hooks shows no name for lazy installed hooks

Bug #894609 reported by Neil Martinsen-Burrell
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Bazaar
Fix Released
Medium
Neil Martinsen-Burrell

Bug Description

Consider the very simple plugin:

"""Test plugin"""

from bzrlib.hooks import install_lazy_named_hook

def callable():
    pass

install_lazy_named_hook('bzrlib.branch','Branch.hooks',
                        'post_branch_init', callable, 'My name is mud')

The relevant portion of the output of "bzr hooks" does not include the string "My name is mud" anywhere:

$ BZR_PLUGINS_AT=test@. bzr hooks
BranchHooks:
  automatic_tag_name:
    <no hooks installed>
  open:
    package-branch-up-to-date
  post_branch_init:
    No hook name
    No hook name
    No hook name
  post_change_branch_tip:
...

"No hook name" is shown thrice (for three plugins that install post_branch_init hooks), but I gave a name when I called install_lazy_named_hook. That name not being shown is the bug. The name is also not shown if the plugin calls bzrlib.branch.Branch.hooks.install_named_hook_lazy(). It *is* shown if we call bzrlib.branch.Branch.hooks.install_named_hook().

I can see where Hooks.hook_lazy() can't call name_hook because it doesn't have a callable to use as the key in self._callable_names, but can't we have self._lazy_callable_names with keys of (callback_module, callback_member)? We could try that dict as well in Hooks.get_hook_name().

Tags: hooks

Related branches

Revision history for this message
Martin Pool (mbp) wrote : Re: [Bug 894609] [NEW] bzr hooks shows no name for lazy installed hooks

that makes sense to me

    status confirmed
    importance medium

Changed in bzr:
importance: Undecided → Medium
status: New → Confirmed
Revision history for this message
Neil Martinsen-Burrell (nmb) wrote :

My original idea to keep another dict of names with different keys doesn't work because get_hook_name is called with the fetched callable rather than the (module_name, module_member) tuple. So, to show the hook in "bzr hooks" we are loading the hook, but when we make populate the dict of hook names we are not loading the hook so we can be lazy about it.

Revision history for this message
Martin Pool (mbp) wrote : Re: [Bug 894609] Re: bzr hooks shows no name for lazy installed hooks

I think it would be ok to load the modules when running 'bzr hooks'. It
only really matters that we're lazy about code that's not relevant to the
user's command.

Revision history for this message
Neil Martinsen-Burrell (nmb) wrote :

That is what we currently do. The problem is that at registration time, we can only register the name of lazy hooks under a key of (module_name, module_member). When we go to print them, the only key that we have for them is the callable itself (which has already been dereferenced from the module name and member before calling get_hook_name). Given our layering (the dereferencing can't/shouldn't mutate the list of hook names) and the requirement to not load the callables at registration time, I'm not sure how to proceed.

Revision history for this message
Martin Pool (mbp) wrote :

It seems like the data you need is in _lazy_hooks, and this is just a
question about how to cleanly expose it?

Vincent Ladeuil (vila)
Changed in bzr:
assignee: nobody → Neil Martinsen-Burrell (nmb)
status: Confirmed → In Progress
milestone: none → 2.5b4
Vincent Ladeuil (vila)
Changed in bzr:
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.