Enhance/extend bzr-keywords (or any other plugin)

Asked by anurag uniyal

I need to add few more keywords to bzr-keywords plugin, going thru it src it says

# The registry of keywords. Other plugins may wish to add entries to this.
keyword_registry = registry.Registry()

so can i create a small plugin and do something like this

from bzrlib.plugins.keywords import keyword_registry

keyword_registry.register('Revision-Number',
    lambda c:get_revno(c))
keyword_registry.register('Tag',
    lambda c:get_tag(c))

I am not sure I can rely on my plugin code always being called?
or bzrlib.plugins.keywords will correctly import from my plugin?

Where I can see plugin writing and loading documentation?

Question information

Language:
English Edit question
Status:
Solved
For:
Bazaar Edit question
Assignee:
No assignee Edit question
Solved by:
John A Meinel
Solved:
Last query:
Last reply:
Revision history for this message
Best John A Meinel (jameinel) said :
#1

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

anurag uniyal wrote:
> New question #96410 on Bazaar:
> https://answers.launchpad.net/bzr/+question/96410
>
> I need to add few more keywords to bzr-keywords plugin, going thru it src it says
>
> # The registry of keywords. Other plugins may wish to add entries to this.
> keyword_registry = registry.Registry()
>
> so can i create a small plugin and do something like this
>
> from bzrlib.plugins.keywords import keyword_registry
>
> keyword_registry.register('Revision-Number',
> lambda c:get_revno(c))
> keyword_registry.register('Tag',
> lambda c:get_tag(c))
>
> I am not sure I can rely on my plugin code always being called?
> or bzrlib.plugins.keywords will correctly import from my plugin?
>
> Where I can see plugin writing and loading documentation?
>
>

^- this should work.
The code is in "bzrlib/plugin.py". We set bzrlib.plugins.__path__ such
that you should be able to "import bzrlib.plugins.*".

The basic rules are such that:

1) Plugin load order is not guaranteed
2) Plugins should be able to import other plugins that have not been
loaded yet (because of __path__). So if you depend on .keywords, you
should be able to get access to it.
3) All plugins in the path will get loaded eventually.

John
=:->

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAktElYMACgkQJdeBCYSNAAPrpgCffa9EKjq4Cfe+k8kFLrjVhpWa
pjcAnjccXKK8yh+wwjmuqfjeBM0pYbZ/
=2pVT
-----END PGP SIGNATURE-----

Revision history for this message
anurag uniyal (anuraguniyal) said :
#2

Thanks John A Meinel, that solved my question.