[Distutils] pakage index __getitem__
Phillip J. Eby
pje at telecommunity.com
Sun Mar 18 01:25:47 CET 2007
At 07:01 PM 3/17/2007 -0400, Jim Fulton wrote:
>I want to get a list of all of the distributions I can find that
>satisfy a requirement. I've found the following works:
>
> index.obtain(requirement)
> dists = [d for d in index[requirement.project_name] if d in
>requirement]
>
>where index is a setuptools.package_index.PackageIndex.
>
>Is there a better way?
There are other ways, but the above is the simplest and most direct way,
given your use case. Normally, performing a resolve() or require() on a
working set will end up invoking obtain() indirectly, if a requirement
can't otherwise be met -- this allows network access to be lazy, so it's
not done unless it's really needed.
> The obtain call seems to be necessary to
>initialize the index for the given project.
Yes - Environment normally calls 'obtain()' in response to a 'best_match()'
operation, which is in turn called by a WorkingSet's 'resolve()'
method. The idea is that you can subclass Environment (in this case, to
create a PackageIndex) and override 'obtain()' to find packages in
locations that are not part of the working set used to create the Environment.
More information about the Distutils-SIG
mailing list