[Python-Dev] PEP 376 proposed changes for basic plugins support

P.J. Eby pje at telecommunity.com
Mon Aug 2 23:02:11 CEST 2010


At 05:08 PM 8/2/2010 +0200, Éric Araujo wrote:
>I wonder if functions in pkgutil or importlib could allow one to 
>iterate over the plugins (i.e. submodules and subpackages of the 
>namespace package) without actually loading then.

See pkgutil.walk_packages(), available since 2.5.

It has to load __init__.py files, especially because of namespace 
packages, but it doesn't load any non-package modules.

That being said, using namespace packages for plugins kind of defeats 
the true purpose of namespace packages, which is to give developers 
private package namespaces they can use across multiple projects, 
like zope.*, peak.*, twisted.*, etc., thereby avoiding naming 
conflicts in the root package namespace.

Granted, you can always re-nest namespaces and do something like 
someproject.plugins.mynamehere.myplugin, but with entry points you 
can just register something in mynamehere.mysomeprojectplugin, and 
flat is better than nested.  ;-)  (Plus, you can include information 
about the individual plugins/features residing in that module in the 
metadata, and avoid importing until/unless you need that feature.)



More information about the Python-Dev mailing list