summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Pratte <guillaume@guillaumepratte.net>2012-04-21 17:43:54 -0400
committerGuillaume Pratte <guillaume@guillaumepratte.net>2012-04-21 17:43:54 -0400
commit20e1ef7ac5e1c470f2327a5aaa38e75a219ad491 (patch)
tree684ac411406e80140829479596f6f2adef24cd9f
parent1b564162d67761a1107a1802f8e7751f9dda2195 (diff)
downloaddisutils2-20e1ef7ac5e1c470f2327a5aaa38e75a219ad491.tar.gz
#13166: Implement __str__ on Distribution and EggInfoDistribution, use for pysetup list, pysetup graph and installation log
-rw-r--r--CONTRIBUTORS.txt1
-rw-r--r--distutils2/database.py6
-rw-r--r--distutils2/depgraph.py10
-rw-r--r--distutils2/install.py2
-rw-r--r--distutils2/run.py2
-rw-r--r--distutils2/tests/test_database.py21
6 files changed, 31 insertions, 11 deletions
diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt
index cc84676..e33eb16 100644
--- a/CONTRIBUTORS.txt
+++ b/CONTRIBUTORS.txt
@@ -59,6 +59,7 @@ Thanks to:
- Gaƫl Pasgrimaud
- George Peristerakis
- Mathieu Perreault
+- Guillaume Pratte
- Sean Reifschneider
- Antoine Reversat
- Arc Riley
diff --git a/distutils2/database.py b/distutils2/database.py
index 6fb30ce..677ef2b 100644
--- a/distutils2/database.py
+++ b/distutils2/database.py
@@ -161,6 +161,9 @@ class Distribution(object):
return '<Distribution %r %s at %r>' % (
self.name, self.version, self.path)
+ def __str__(self):
+ return "%s %s" % (self.name, self.version)
+
def _get_records(self, local=False):
results = []
record = self.get_distinfo_file('RECORD')
@@ -365,6 +368,9 @@ class EggInfoDistribution(object):
return '<EggInfoDistribution %r %s at %r>' % (
self.name, self.version, self.path)
+ def __str__(self):
+ return "%s %s" % (self.name, self.version)
+
def list_installed_files(self, local=False):
def _md5(path):
diff --git a/distutils2/depgraph.py b/distutils2/depgraph.py
index 30a2528..abaefc2 100644
--- a/distutils2/depgraph.py
+++ b/distutils2/depgraph.py
@@ -71,18 +71,16 @@ class DependencyGraph:
"""
self.missing[distribution].append(requirement)
- def _repr_dist(self, dist):
- return '%r %s' % (dist.name, dist.version)
-
def repr_node(self, dist, level=1):
"""Prints only a subgraph"""
output = []
- output.append(self._repr_dist(dist))
+ output.append(str(dist))
+ # XXX: this code needs cleanup
for other, label in self.adjacency_list[dist]:
- dist = self._repr_dist(other)
+ dist = str(other)
if label is not None:
dist = '%s [%s]' % (dist, label)
- output.append(' ' * level + str(dist))
+ output.append(' ' * level + dist)
suboutput = self.repr_node(other, level + 1)
subs = suboutput.split('\n')
output.extend(subs[1:])
diff --git a/distutils2/install.py b/distutils2/install.py
index ee6b022..20bcacf 100644
--- a/distutils2/install.py
+++ b/distutils2/install.py
@@ -183,7 +183,7 @@ def install_dists(dists, path, paths=None):
installed_dists = []
for dist in dists:
- logger.info('Installing %r %s...', dist.name, dist.version)
+ logger.info('Installing %s...', dist)
try:
_install_dist(dist, path)
installed_dists.append(dist)
diff --git a/distutils2/run.py b/distutils2/run.py
index 27f1fd1..f845dbc 100644
--- a/distutils2/run.py
+++ b/distutils2/run.py
@@ -308,7 +308,7 @@ def _list(dispatcher, args, **kw):
number = 0
for dist in results:
- print '%r %s (from %r)' % (dist.name, dist.version, dist.path)
+ print "%s (from %r)" % (dist, dist.path)
number += 1
if number == 0:
diff --git a/distutils2/tests/test_database.py b/distutils2/tests/test_database.py
index 09db9ef..6975258 100644
--- a/distutils2/tests/test_database.py
+++ b/distutils2/tests/test_database.py
@@ -80,12 +80,14 @@ class CommonDistributionTests(FakeDistsMixin):
attributes are used in test methods. See source code for details.
"""
+ def _get_dist_path(self, distdir):
+ here = os.path.abspath(os.path.dirname(__file__))
+ return os.path.join(here, 'fake_dists', distdir)
+
def test_instantiation(self):
# check that useful attributes are here
name, version, distdir = self.sample_dist
- here = os.path.abspath(os.path.dirname(__file__))
- dist_path = os.path.join(here, 'fake_dists', distdir)
-
+ dist_path = self._get_dist_path(distdir)
dist = self.dist = self.cls(dist_path)
self.assertEqual(dist.path, dist_path)
self.assertEqual(dist.name, name)
@@ -101,6 +103,17 @@ class CommonDistributionTests(FakeDistsMixin):
self.assertIn(self.cls.__name__, repr(dist))
@requires_zlib
+ def test_str(self):
+ name, version, distdir = self.sample_dist
+ dist = self.cls(self._get_dist_path(distdir))
+ self.assertEqual(name, dist.name)
+ # Sanity test: dist.name is unicode,
+ # but str output contains no u prefix.
+ self.assertIsInstance(dist.name, unicode)
+ self.assertEqual(version, dist.version)
+ self.assertEqual(str(dist), self.expected_str_output)
+
+ @requires_zlib
def test_comparison(self):
# tests for __eq__ and __hash__
dist = self.cls(self.dirs[0])
@@ -128,6 +141,7 @@ class TestDistribution(CommonDistributionTests, unittest.TestCase):
cls = Distribution
sample_dist = 'choxie', '2.0.0.9', 'choxie-2.0.0.9.dist-info'
+ expected_str_output = 'choxie 2.0.0.9'
def setUp(self):
super(TestDistribution, self).setUp()
@@ -265,6 +279,7 @@ class TestEggInfoDistribution(CommonDistributionTests,
cls = EggInfoDistribution
sample_dist = 'bacon', '0.1', 'bacon-0.1.egg-info'
+ expected_str_output = 'bacon 0.1'
def setUp(self):
super(TestEggInfoDistribution, self).setUp()