Commit cbbc6e76 authored by PJ Eby's avatar PJ Eby

Ensure that WorkingSet.resolve() (and therefore require() as well)

returns a list of the relevant distributions, even if they are found in
the working set rather than the environment.  This fixes some problems
in the 0.6a3 release.

--HG--
branch : setuptools
extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041256
parent 20e9f30c
...@@ -463,7 +463,7 @@ class WorkingSet(object): ...@@ -463,7 +463,7 @@ class WorkingSet(object):
requirements = list(requirements)[::-1] # set up the stack requirements = list(requirements)[::-1] # set up the stack
processed = {} # set of processed requirements processed = {} # set of processed requirements
best = dict([(d.key,d) for d in self]) # key -> dist best = {} # key -> dist
to_activate = [] to_activate = []
while requirements: while requirements:
...@@ -471,20 +471,20 @@ class WorkingSet(object): ...@@ -471,20 +471,20 @@ class WorkingSet(object):
if req in processed: if req in processed:
# Ignore cyclic or redundant dependencies # Ignore cyclic or redundant dependencies
continue continue
dist = best.get(req.key) dist = best.get(req.key)
if dist is None: if dist is None:
# Find the best distribution and add it to the map # Find the best distribution and add it to the map
if env is None: dist = self.by_key.get(req.key)
env = Environment(self.entries)
dist = best[req.key] = env.best_match(req, self, installer)
if dist is None: 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) to_activate.append(dist)
elif dist not in req: elif dist not in req:
# Oops, the "best" so far conflicts with a dependency # Oops, the "best" so far conflicts with a dependency
raise VersionConflict(dist,req) # XXX put more info here raise VersionConflict(dist,req) # XXX put more info here
requirements.extend(dist.requires(req.extras)[::-1]) requirements.extend(dist.requires(req.extras)[::-1])
processed[req] = True processed[req] = True
......
...@@ -1488,6 +1488,9 @@ File/Path Utilities ...@@ -1488,6 +1488,9 @@ File/Path Utilities
Release Notes/Change History Release Notes/Change History
---------------------------- ----------------------------
0.6a4
* Fix a bug in ``WorkingSet.resolve()`` that was introduced in 0.6a3.
0.6a3 0.6a3
* Added ``safe_extra()`` parsing utility routine, and use it for Requirement, * Added ``safe_extra()`` parsing utility routine, and use it for Requirement,
EntryPoint, and Distribution objects' extras handling. EntryPoint, and Distribution objects' extras handling.
......
...@@ -123,7 +123,6 @@ class DistroTests(TestCase): ...@@ -123,7 +123,6 @@ class DistroTests(TestCase):
def testResolve(self): def testResolve(self):
ad = Environment([]); ws = WorkingSet([]) ad = Environment([]); ws = WorkingSet([])
# Resolving no requirements -> nothing to install # Resolving no requirements -> nothing to install
self.assertEqual( list(ws.resolve([],ad)), [] ) self.assertEqual( list(ws.resolve([],ad)), [] )
...@@ -131,7 +130,6 @@ class DistroTests(TestCase): ...@@ -131,7 +130,6 @@ class DistroTests(TestCase):
self.assertRaises( self.assertRaises(
DistributionNotFound, ws.resolve, parse_requirements("Foo"), ad DistributionNotFound, ws.resolve, parse_requirements("Foo"), ad
) )
Foo = Distribution.from_filename( Foo = Distribution.from_filename(
"/foo_dir/Foo-1.2.egg", "/foo_dir/Foo-1.2.egg",
metadata=Metadata(('depends.txt', "[bar]\nBaz>=2.0")) metadata=Metadata(('depends.txt', "[bar]\nBaz>=2.0"))
...@@ -139,10 +137,12 @@ class DistroTests(TestCase): ...@@ -139,10 +137,12 @@ class DistroTests(TestCase):
ad.add(Foo) ad.add(Foo)
# Request thing(s) that are available -> list to activate # Request thing(s) that are available -> list to activate
self.assertEqual( for i in range(3):
list(ws.resolve(parse_requirements("Foo"), ad)), [Foo] targets = list(ws.resolve(parse_requirements("Foo"), ad))
) self.assertEqual(targets, [Foo])
map(ws.add,targets)
ws = WorkingSet([]) # reset
# Request an extra that causes an unresolved dependency for "Baz" # Request an extra that causes an unresolved dependency for "Baz"
self.assertRaises( self.assertRaises(
DistributionNotFound, ws.resolve,parse_requirements("Foo[bar]"), ad DistributionNotFound, ws.resolve,parse_requirements("Foo[bar]"), ad
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment