On 6/17/07, Ian Bicking <[EMAIL PROTECTED]> wrote:
> Noah Slater wrote:
> > Hello,
> >
> > When creating a configuration file, the documentation gives this as an 
> > example:
> > use = egg:Paste#urlmap
> >
> >
> > What does egg:Paste#urlmap point to? From the documentation it says:
> >
> > "egg:Paste#urlmap means to use the composite application named urlmap
> > from the Paste package"
> >
> > What is the "Paste" package, on my system there is a "paste" python
> > package - so there seems to be a difference in capitalisation here.

Paste is the external package you easy_install, which is now called a
"distribution".  'paste' is the package you import.  A package can be
built up from multiple distributions (Paste, PasteDeploy, PasteScript)
if it has been declared a "namespace package".  A distribution has
entry points listed in EGG-INFO/entry_points.txt.  The relevant one in
Paste is in section "[paste.composite_factory"], and is "urlmap =
paste.urlmap:urlmap_factory".   This says that "Paste#urlmap" means
"look in the Paste distribution, import a module 'paste.urlmap', and
call a function 'urlmap_factory'".   The section is the "entry point
group", a name agreed upon by the cooperating distributions.

I think the code is using some combination of
pkg_resources.iter_entry_points() and
pkg_resources.load_entry_point().  pkg_resources is a module that
comes with setuptools.  iter_entry_points looks in all installed eggs
for matching entry points; in this case it finds "urlmap".
load_entry_point calls the function indicated by the entry point and
returns a Python object.

The advantage of eggs is indirection and multi-versioning.  The caller
does not want to know it has to call some obscure function like
paste.urlmap.urlmap_factory.  What if the function name changes later,
do all applications have to change their code?  No, each application
invokes the generic name, and pkg_resources links the generic name to
the actual function.  Maybe you don't know what the distribution is
called, or maybe two distributions define the same entry point
("genshi") and for some reason you prefer one distribution over
another.  Say there's a major bug in the default distribution and it's
unmaintained, and a third party made a better version in a different
distribution.  So they make a distribution with a different name but
the same entry point, so you just uninstall one distribution and
install the other, and presto, your application starts using the other
distribution's object without you having to change your config file.

-- 
Mike Orr <[EMAIL PROTECTED]>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to