diff options
| author | PJ Eby <distutils-sig@python.org> | 2005-05-23 01:56:27 +0000 |
|---|---|---|
| committer | PJ Eby <distutils-sig@python.org> | 2005-05-23 01:56:27 +0000 |
| commit | 2237065782a7ab8265b6127f9352d5f0a9c4fff6 (patch) | |
| tree | 6a94346f805f6489f4f07c16a06bb1c8acf7f765 | |
| parent | 489117c324ea90183cbaf5558222b178ae074bed (diff) | |
| download | python-setuptools-git-2237065782a7ab8265b6127f9352d5f0a9c4fff6.tar.gz | |
Add tests for AvailableDistributions().resolve(). This effectively
completes the core dependency resolution engine; all we need now is a way
to turn sys.path entries into "distribution sources" that can list
Distribution objects for inclusion in an instance of
AvailableDistributions, and the 'require("SomePkg>=2.7")' API will be
usable.
--HG--
branch : setuptools
extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041009
| -rw-r--r-- | pkg_resources.py | 12 | ||||
| -rw-r--r-- | setuptools/tests/test_resources.py | 41 |
2 files changed, 47 insertions, 6 deletions
diff --git a/pkg_resources.py b/pkg_resources.py index 0792adba..1f9be67c 100644 --- a/pkg_resources.py +++ b/pkg_resources.py @@ -250,12 +250,12 @@ class AvailableDistributions(object): if path is None: path = sys.path - requirements = list(requirements)[::1] # set up the stack + requirements = list(requirements)[::-1] # set up the stack processed = {} # set of processed requirements best = {} # key -> dist + to_install = [] while requirements: - req = requirements.pop() if req in processed: # Ignore cyclic or redundant dependencies @@ -268,15 +268,16 @@ class AvailableDistributions(object): dist = best[req.key] = self.best_match(req,path) if dist is None: raise DistributionNotFound(req) # XXX put more info here + to_install.append(dist) - elif dist not in requirement: + elif dist not in req: # Oops, the "best" so far conflicts with a dependency raise VersionConflict(req,dist) # XXX put more info here requirements.extend(dist.depends(req.options)[::-1]) processed[req] = True - return best.values() # return list of distros to install + return to_install # return list of distros to install def obtain(self, requirement): @@ -284,7 +285,6 @@ class AvailableDistributions(object): return None # override this in subclasses - class ResourceManager: """Manage resource extraction and packages""" @@ -418,7 +418,6 @@ def require(*requirements): * get_distro_source() isn't implemented * Distribution.install_on() isn't implemented - * AvailableDistributions.resolve() is untested * AvailableDistributions.scan() is untested There may be other things missing as well, but this definitely won't work @@ -449,6 +448,7 @@ def require(*requirements): + class DefaultProvider: """Provides access to package resources in the filesystem""" diff --git a/setuptools/tests/test_resources.py b/setuptools/tests/test_resources.py index e2135ab1..b6470e4b 100644 --- a/setuptools/tests/test_resources.py +++ b/setuptools/tests/test_resources.py @@ -121,6 +121,47 @@ class DistroTests(TestCase): self.checkDepends(self.distDepends(v), v) + def testResolve(self): + ad = AvailableDistributions([]) + + # Resolving no requirements -> nothing to install + self.assertEqual( list(ad.resolve([],[])), [] ) + + # Request something not in the collection -> DistributionNotFound + self.assertRaises( + DistributionNotFound, ad.resolve, parse_requirements("Foo"), [] + ) + + Foo = Distribution.from_filename( + "/foo_dir/Foo-1.2.egg", + metadata=Metadata(('depends.txt', "[bar]\nBaz>=2.0")) + ) + ad.add(Foo) + + # Request thing(s) that are available -> list to install + self.assertEqual( + list(ad.resolve(parse_requirements("Foo"),[])), [Foo] + ) + + # Request an option that causes an unresolved dependency for "Baz" + self.assertRaises( + DistributionNotFound, ad.resolve,parse_requirements("Foo[bar]"),[] + ) + Baz = Distribution.from_filename( + "/foo_dir/Baz-2.1.egg", metadata=Metadata(('depends.txt', "Foo")) + ) + ad.add(Baz) + + # Install list now includes resolved dependency + self.assertEqual( + list(ad.resolve(parse_requirements("Foo[bar]"),[])), [Foo,Baz] + ) + # Requests for conflicting versions produce VersionConflict + self.assertRaises( + VersionConflict, + ad.resolve, parse_requirements("Foo==1.2\nFoo!=1.2"), [] + ) + def testDistroDependsOptions(self): d = self.distDepends(""" Twisted>=1.5 |
