Commit 58217442 authored by PJ Eby's avatar PJ Eby

Added "AvailableDistributions" class that finds and indexes usable

distributions; this replaces the previous "iter_distributions()" API.
Added basic platform support to Distribution and AvailableDistributions so
that platform-independent distros as well as local platform-compatible
distros are acceptable.  The actual platform scheme is currently delegated
to distutils.util.get_platform(), but needs to be replaced with a better
scheme of some kind, especially for OS X.

--HG--
branch : setuptools
extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041004
parent ac8607b2
This diff is collapsed.
...@@ -10,7 +10,7 @@ from distutils.dir_util import create_tree, remove_tree, ensure_relative,mkpath ...@@ -10,7 +10,7 @@ from distutils.dir_util import create_tree, remove_tree, ensure_relative,mkpath
from distutils.sysconfig import get_python_version from distutils.sysconfig import get_python_version
from distutils.errors import * from distutils.errors import *
from distutils import log from distutils import log
from pkg_resources import parse_requirements from pkg_resources import parse_requirements, get_platform
class bdist_egg(Command): class bdist_egg(Command):
...@@ -75,9 +75,9 @@ class bdist_egg(Command): ...@@ -75,9 +75,9 @@ class bdist_egg(Command):
if self.bdist_dir is None: if self.bdist_dir is None:
bdist_base = self.get_finalized_command('bdist').bdist_base bdist_base = self.get_finalized_command('bdist').bdist_base
self.bdist_dir = os.path.join(bdist_base, 'egg') self.bdist_dir = os.path.join(bdist_base, 'egg')
self.set_undefined_options('bdist', if self.plat_name is None:
('dist_dir', 'dist_dir'), self.plat_name = get_platform()
('plat_name', 'plat_name')) self.set_undefined_options('bdist',('dist_dir', 'dist_dir'))
def write_stub(self, resource, pyfile): def write_stub(self, resource, pyfile):
......
...@@ -4,21 +4,53 @@ import pkg_resources, sys ...@@ -4,21 +4,53 @@ import pkg_resources, sys
class DistroTests(TestCase): class DistroTests(TestCase):
def testEmptyiter(self): def testCollection(self):
# empty path should produce no distributions # empty path should produce no distributions
self.assertEqual(list(iter_distributions(path=[])), []) ad = AvailableDistributions([])
self.assertEqual(list(ad), [])
self.assertEqual(len(ad),0)
self.assertEqual(ad.get('FooPkg'),None)
self.failIf('FooPkg' in ad)
ad.add(Distribution.from_filename("FooPkg-1.3_1.egg"))
ad.add(Distribution.from_filename("FooPkg-1.4-py2.4-win32.egg"))
ad.add(Distribution.from_filename("FooPkg-1.2-py2.4.egg"))
# Name is in there now
self.failUnless('FooPkg' in ad)
# But only 1 package
self.assertEqual(list(ad), ['foopkg'])
self.assertEqual(len(ad),1)
# Distributions sort by version
self.assertEqual(
[dist.version for dist in ad['FooPkg']], ['1.4','1.3-1','1.2']
)
# Removing a distribution leaves sequence alone
ad.remove(ad['FooPkg'][1])
self.assertEqual(
[dist.version for dist in ad.get('FooPkg')], ['1.4','1.2']
)
# And inserting adds them in order
ad.add(Distribution.from_filename("FooPkg-1.9.egg"))
self.assertEqual(
[dist.version for dist in ad['FooPkg']], ['1.9','1.4','1.2']
)
def checkFooPkg(self,d): def checkFooPkg(self,d):
self.assertEqual(d.name, "FooPkg") self.assertEqual(d.name, "FooPkg")
self.assertEqual(d.key, "foopkg") self.assertEqual(d.key, "foopkg")
self.assertEqual(d.version, "1.3-1") self.assertEqual(d.version, "1.3-1")
self.assertEqual(d.py_version, "2.4") self.assertEqual(d.py_version, "2.4")
self.assertEqual(d.platform, "win32")
self.assertEqual(d.parsed_version, parse_version("1.3-1")) self.assertEqual(d.parsed_version, parse_version("1.3-1"))
def testDistroBasics(self): def testDistroBasics(self):
d = Distribution( d = Distribution(
"/some/path", "/some/path",
name="FooPkg",version="1.3-1",py_version="2.4" name="FooPkg",version="1.3-1",py_version="2.4",platform="win32"
) )
self.checkFooPkg(d) self.checkFooPkg(d)
self.failUnless(d.installed_on(["/some/path"])) self.failUnless(d.installed_on(["/some/path"]))
...@@ -26,11 +58,20 @@ class DistroTests(TestCase): ...@@ -26,11 +58,20 @@ class DistroTests(TestCase):
d = Distribution("/some/path") d = Distribution("/some/path")
self.assertEqual(d.py_version, sys.version[:3]) self.assertEqual(d.py_version, sys.version[:3])
self.assertEqual(d.platform, None)
def testDistroParse(self): def testDistroParse(self):
d = Distribution.from_filename("FooPkg-1.3_1-py2.4-win32.egg") d = Distribution.from_filename("FooPkg-1.3_1-py2.4-win32.egg")
self.checkFooPkg(d) self.checkFooPkg(d)
...@@ -107,7 +148,7 @@ class ParseTests(TestCase): ...@@ -107,7 +148,7 @@ class ParseTests(TestCase):
0.79.9999+0.80.0pre2-3 0.79.9999+0.80.0pre2-2 0.79.9999+0.80.0pre2-3 0.79.9999+0.80.0pre2-2
0.77.2-1 0.77.1-1 0.77.0-1 0.77.2-1 0.77.1-1 0.77.0-1
""".split() """.split()
for p,v1 in enumerate(torture): for p,v1 in enumerate(torture):
for v2 in torture[p+1:]: for v2 in torture[p+1:]:
c(v2,v1) c(v2,v1)
......
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