[Distutils] Finding only activated eggs in Environment()

Phillip J. Eby pje at telecommunity.com
Tue Nov 22 18:09:10 CET 2005


At 10:27 AM 11/22/2005 -0600, Ian Bicking wrote:
>Phillip J. Eby wrote:
>>At 05:27 PM 11/21/2005 -0800, Rob Cakebread wrote:
>>
>>>I'm using pkg_resources.Environment() to get a list of all
>>>eggs.
>>>
>>>Besides making a list of activated eggs with
>>>pkg_resources.working_set
>>>and comparing it with pkg_resources.Environment, is there
>>>a way to check if an individual egg is activated?
>>
>>if someDist in working_set:
>>     # a distribution w/same location/version/pyversion/etc.
>>     # is in there
>
>Relatedly, how do I get all the distributions, not just the active 
>ones?  I added a command to Paste Script for display information about 
>entry points, but it only gets the active distributions.

# scan all sys.path dirs for all eggs (slow)
env = pkg_resources.Environment()

for project_name in env:
     # iterate over distributions for this project
     # in *descending* version order, newest to oldest
     for dist in env[project_name]:
         # etc.

Since an enviroment can contain multiple versions of the same egg, you'll 
probably want to limit yourself to the first (i.e. highest-versioned) 
distribution for each project, if your intent is to list available entry 
points.



More information about the Distutils-SIG mailing list