On 06/01/2010 09:42 PM, Sean O'Connor wrote:
I've been generally thinking about putting together a package of
reusable tools to implement common "patterns" for reusable apps.
  Included in this would be this type of auto-discovery system as well
as a registration pattern.

Auto-discovery and registration: setuptools entry points can be used for this. That at least is an existing (partial) solution.

I'm already using it in a django project where I've got a couple of packages that can register a render-something-on-a-map method. In the one location where I need it I can then just ask setuptools (well, pkg_resources) for a list of methods and call them.

Just for the idea, here's a snippet from a setup.py:

      entry_points={
          'lizard_map.layer_method': [
            'shapefile_layer = lizard_map.layers:shapefile_layer',
            ]
          },

And afterwards iterate through all the entry points and call them (or do something else with them):

for entrypoint in pkg_resources.iter_entry_points(
    group="lizard_map.layer_method"):
    method = entrypoint.load()
    method("some argument)


Some longer explanation: http://tinyurl.com/ylf3kjb


Reinout


--
Reinout van Rees - rein...@vanrees.org - http://reinout.vanrees.org
Programmer at http://www.nelen-schuurmans.nl
"Military engineers build missiles. Civil engineers build targets"

--
You received this message because you are subscribed to the Google Groups "Django 
developers" group.
To post to this group, send email to django-develop...@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to