[Distutils] setuptools: bug in run_script

Phillip J. Eby pje at telecommunity.com
Sun Sep 25 23:23:01 CEST 2005


At 01:00 PM 9/25/2005 -0500, Ian Bicking wrote:
>Ben Bangert encountered a problem where
>pkg_resources.WorkingSet.run_script didn't work; from line 407:
>
>         self.require(requires)[0].run_script(script_name, ns)
>
>If all the packages are already loaded for some reason, then
>self.require() returns [].
>
>I don't really understand how we got in this state -- that apparently
>packages are available before they are being required.

That's actually normal, for packages that are already on sys.path (via 
easy-install.pth).  What's not normal is that require() should never return 
[].  As it turns out, it's a bug in an optimization I added for 0.6a3 that 
avoids creating an Environment if all requirements can be satisfied from 
the working set.  It ends up not adding the relevant packages to the list 
it returns.  Here's a patch to fix it until I get a bugfix release out:

Index: pkg_resources.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/setuptools/pkg_resources.py,v
retrieving revision 1.72
diff -u -r1.72 pkg_resources.py
--- pkg_resources.py    24 Sep 2005 19:48:28 -0000      1.72
+++ pkg_resources.py    25 Sep 2005 18:57:07 -0000
@@ -463,7 +463,7 @@

          requirements = list(requirements)[::-1]  # set up the stack
          processed = {}  # set of processed requirements
-        best = dict([(d.key,d) for d in self])  # key -> dist
+        best = {}  # key -> dist
          to_activate = []

          while requirements:
@@ -471,20 +471,20 @@
              if req in processed:
                  # Ignore cyclic or redundant dependencies
                  continue
-
              dist = best.get(req.key)
              if dist is None:
                  # Find the best distribution and add it to the map
-                if env is None:
-                    env = Environment(self.entries)
-                dist = best[req.key] = env.best_match(req, self, installer)
+                dist = self.by_key.get(req.key)
                  if dist is None:
-                    raise DistributionNotFound(req)  # XXX put more info here
+                    if env is None:
+                        env = Environment(self.entries)
+                    dist = best[req.key] = env.best_match(req, self, 
installer)
+                    if dist is None:
+                        raise DistributionNotFound(req)  # XXX put more 
info here
                  to_activate.append(dist)
              elif dist not in req:
                  # Oops, the "best" so far conflicts with a dependency
                  raise VersionConflict(dist,req) # XXX put more info here
-
              requirements.extend(dist.requires(req.extras)[::-1])
              processed[req] = True



More information about the Distutils-SIG mailing list