[Distutils] pkg_resources.iter_entry_points() and pkg_resources.require

Phillip J. Eby pje at telecommunity.com
Thu Oct 13 19:28:35 CEST 2005


At 09:08 AM 10/13/2005 +0200, Elvelind Grandin wrote:
>I'm having a go at using entry points for the plugin system for an app
>I'm working on. All is working good .. exept when the plugins are
>installed localy, then I need to require them before they will turn up
>in iter_entry_points(), which ofcourse breaks everything.
>Is this a good way around this?

Some applications handle plugins by adding every egg in a "plugins" 
directory to the working set, e.g.:

    working_set.add_entry(plugins_dir)
    env = Environment([plugins_dir])
    working_set.require(*env.keys())

This first adds the plugins directory to the directories in the working 
set, so that items in the plugin directory can be found.  It then scans the 
plugin directory to create an environment, which is a table mapping project 
names to available distributions for that project.  Finally, it require()'s 
all the projects that have eggs in the plugins directory.  At this point, 
the working set will be populated with all the plugins, although nothing 
will have been imported.  You can then use iter_entry_points() or any other 
APIs to access your plugins.

The alternative strategy is to require plugins to be installed in a "site" 
directory using easy_install, in which case they will be listed in a .pth 
file and thus be part of the working set as soon as pkg_resources is imported.



More information about the Distutils-SIG mailing list