[Distutils] Requirent specifiers specified? :)

Jim Fulton jim at zope.com
Wed Jun 21 22:52:19 CEST 2006


When specifying a dependencies and when asking for a package with
easy_install, you can specify one or more specifiers.  It's unclear what
the rules are for combining specifiers.

Imagine that I have a collection of eggs like:

   /home/jim/tmp/dist:
   used 92 available 41345796
   -rw-rw-r--  1 jim jim   671 Jun 19 17:43 demoneeded-1.0-py2.4.egg
   -rw-rw-r--  1 jim jim   672 Jun 19 17:46 demoneeded-1.1-py2.4.egg
   -rw-rw-r--  1 jim jim   673 Jun 19 17:46 demoneeded-1.2-py2.4.egg
   -rw-rw-r--  1 jim jim   673 Jun 19 17:46 demoneeded-1.3-py2.4.egg
   -rw-rw-r--  1 jim jim   673 Jun 19 17:46 demoneeded-1.4-py2.4.egg
   -rw-rw-r--  1 jim jim   673 Jun 19 17:46 demoneeded-1.5-py2.4.egg
   -rw-rw-r--  1 jim jim   673 Jun 19 17:46 demoneeded-1.6-py2.4.egg
   -rw-rw-r--  1 jim jim   673 Jun 19 17:46 demoneeded-1.7-py2.4.egg
   -rw-rw-r--  1 jim jim   673 Jun 19 17:46 demoneeded-1.8-py2.4.egg
   -rw-rw-r--  1 jim jim   673 Jun 19 17:46 demoneeded-1.9-py2.4.egg

Now, here are some examples of using the pkg_resources api to fetch a
required distribution:

 >>> import pkg_resources
 >>> e = pkg_resources.Environment(['tmp/dist'])
 >>> ws = pkg_resources.WorkingSet()

 >>> ws.resolve([pkg_resources.Requirement.parse('demoneeded ==1.1, ==1.4')], e)
[demoneeded 1.4 (/home/jim/tmp/dist/demoneeded-1.4-py2.4.egg)]

Here, the specifiers were or-ed. OK.

 >>> ws.resolve([pkg_resources.Requirement.parse('demoneeded >1.1, <1.6')], e)
[demoneeded 1.5 (/home/jim/tmp/dist/demoneeded-1.5-py2.4.egg)]

Here they were and-ed.  This makes sense, from a dwimy point of view. :)
If they were or-ed, I'd expect to get 1.9.

 >>> ws.resolve([pkg_resources.Requirement.parse('demoneeded >1.1, <1.6, ==1.8')], e)
[demoneeded 1.8 (/home/jim/tmp/dist/demoneeded-1.8-py2.4.egg)]

Hm, here the ==1.8 seems to have been or-ed with the result of anding >1.1
and <1.6.

 >>> ws.resolve([pkg_resources.Requirement.parse('demoneeded <1.1, >1.6')], e)
[demoneeded 1.9 (/home/jim/tmp/dist/demoneeded-1.9-py2.4.egg)]
 >>> ws.resolve([pkg_resources.Requirement.parse('demoneeded !=1.8, ==1.8')], e)
[demoneeded 1.9 (/home/jim/tmp/dist/demoneeded-1.9-py2.4.egg)]

I really don't know what's going on with these. :)

Are the rules for combining specifiers specified anywhere?

Jim

-- 
Jim Fulton           mailto:jim at zope.com       Python Powered!
CTO                  (540) 361-1714            http://www.python.org
Zope Corporation     http://www.zope.com       http://www.zope.org


More information about the Distutils-SIG mailing list