[Distutils] Optimizing easy-install upgrade
Phillip J. Eby
pje at telecommunity.com
Thu Jun 22 00:27:27 CEST 2006
At 05:37 PM 6/21/2006 -0400, Jim Fulton wrote:
>Suppose I have the directory:
>
> /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
>
>and then run easy install telling it to install something I already have:
>
> [jim at ds9 ~]$ /usr/local/python/2.4/bin/easy_install -d tmp/dist -mxU
> demoneeded==1.1
The -U option means "always search PyPI".
>I have some scripts that invoke easy_setup and I'd like to try to
>do some of this logic myself. Given a requirement, I'd like to
>get the specifiers and decide myself whether to invoke easy_install.
>I have 2 problems:
>
>- I don't want to parse the requirement myself, but, rather,
> use Requirement.parse. If I use Requirement.parse, I can use
> the specs attribute to get the specifiers, however, this
> attribute isn't documented. Should I assume that it is
> private? Or is it safe to use.
Why do that when you can just ask the Requirement whether it matches a
particular version? The __contains__ method of Requirement objects accepts
a version string, distribution object, or parsed version number you can use.
(For that matter, you can query an Environment or WorkingSet for the
distributions whose versions you want to check.)
More information about the Distutils-SIG
mailing list