[Distutils] setuptools and ordering...

Phillip J. Eby pje at telecommunity.com
Thu Mar 2 05:50:43 CET 2006


At 06:19 PM 2/25/2006 +0200, Iwan Vosloo wrote:
>Or, I'd have to write code that builds the dependency tree (of
>Distributions) and then flatten it into a list that would make
>sense. And THEN search for entry points in that order.  I don't
>suppose something like this exists?

Not really.  I'd probably do something like:

def flatten(dists, ws=pkg_resources.working_set, memo=None):
     if memo is None:
         memo = {}
     for dist in dists:
         if dist in memo:
             continue
         memo[dist] = True
         predecessors = ws.resolve(dist.as_requirement())
         for d in flatten(predecessors, ws, memo):
             yield d
         yield dist

Calling "flatten(working_set)" would then yield every distribution (at most 
once) in an ordering guaranteed to have dependency targets before the 
distributions that depend on them.

Once you've got the distributions in that order, you can then do as you 
wish with their entry points.



More information about the Distutils-SIG mailing list