Python plugins, third round
Lalo Martins
lalo at exoweb.net
Tue Jun 14 03:19:36 BST 2005
Ok, after private discussion with Aaron, I have a counter-proposal. But
maybe it's a better idea to release 0.0.5 with either the current system
or the one I just posted, and work on this one as a 0.0.6 feature (if we
agree it's a good idea).
Background
-----------
So we both worry that this mad plugin loading may slow down bzr too
much. He wants to limit that by loading them on-demand, which would
require a very strict naming convention or something like that. I was
more prone to simplifying the plugins so that they could load fast.
The idea
---------
Well, after years of working with Zope, I developed a deep appreciation
for "explicit is better than implicit" and a strong distaste for
software that depends on naming conventions to work right. (Just in
case someone plans to misunderstand me - these two are not related,
they're two separate things that lead me to this idea.)
So I was thinking. Why do we need to automagically search plugins at
all? I'd prefer the user to be personally aware of any and all plugins
he is loaded.
Also, if plugin loading is made explicit, it may allow on-demand
loading, because then we know what kind of functionality is implemented
by each plugin.
So what I'm proposing is an explicit plugin system, controlled by
configuration. Better to explain by example; this would be an excerpt
of a configuration file (as we haven't picked a configuration file
format, I'm making one up as I go, which I think people will understand)
-----
plugin /home/lalo/src/baz2bzr/plugin/baz2bzr:
BranchStorage ArchArchiveBranchStorage
Command cmd_convert_from_arch
plugin /home/lalo/src/bzrexport_misc:
Exporter win_installer win_installer.make_win_installer
Exporter deb deb.build_binary_package
plugin /home/lalo/src/bzrchangelog:
Command cmd_make_changelog
-----
Actual loading of the plugin works like, hmm, this pseudocode:
plugin_name, plugin_dir = os.path.split(plugin_path)
plugin_info = imp.find_module(plugin_name, [plugin_dir])
and so on; so the thing in the config file may be a py, pyc, so, pyd,
whatever, you name it, or it may be a package with an __init__.py. In
the example above, I was imagining baz2bzr to be a file (module) and the
others to be packages.
Note the "dotted names" in the bzrexport_misc entry. I'm not sure, in
this case, whether the plugin system should import these modules
on-demand (which would be faster, but less explicit), or if the
__init__.py file on the package should rather be required to import them
so that these names are in the namespace (more explicit, but means you
end up importing 'deb' even when you only want 'win_installer').
best,
Lalo Martins
--
So many of our dreams at first seem impossible,
then they seem improbable, and then, when we
summon the will, they soon become inevitable.
--
http://www.exoweb.net/ mailto:lalo at exoweb.net
GNU: never give up freedom http://www.gnu.org/
More information about the bazaar
mailing list