aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2015-01-04 13:25:28 -0500
committerJason R. Coombs <jaraco@jaraco.com>2015-01-04 13:25:28 -0500
commit23d5e4a81a61c5e6617fa69fd0b2bc440fa20c45 (patch)
treedf3a695608a8278a4e0dc4a5d6c7987a656484cd
parent880ccea0220509bfaf483a50beefc128299a5b03 (diff)
downloadexternal_python_setuptools-23d5e4a81a61c5e6617fa69fd0b2bc440fa20c45.tar.gz
external_python_setuptools-23d5e4a81a61c5e6617fa69fd0b2bc440fa20c45.tar.bz2
external_python_setuptools-23d5e4a81a61c5e6617fa69fd0b2bc440fa20c45.zip
Test the report method
-rw-r--r--pkg_resources/__init__.py33
-rw-r--r--pkg_resources/tests/test_resources.py6
-rwxr-xr-xsetuptools/command/easy_install.py5
3 files changed, 33 insertions, 11 deletions
diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py
index bcee9d28..0846c0ac 100644
--- a/pkg_resources/__init__.py
+++ b/pkg_resources/__init__.py
@@ -317,8 +317,34 @@ class ResolutionError(Exception):
def __repr__(self):
return self.__class__.__name__+repr(self.args)
+
class VersionConflict(ResolutionError):
- """An already-installed version conflicts with the requested version"""
+ """
+ An already-installed version conflicts with the requested version.
+
+ Should be initialized with the installed Distribution, the requested
+ Requirement, and optionally a list of dists that required the installed
+ Distribution.
+ """
+
+ @property
+ def dist(self):
+ return self.args[0]
+
+ @property
+ def req(self):
+ return self.args[1]
+
+ @property
+ def required_by(self):
+ return self.args[2] if len(self.args) > 2 else []
+
+ def report(self):
+ template = "{self.dist} is installed but {self.req} is required"
+ if self.required_by:
+ template += " by {self.required_by}"
+ return template.format(**locals())
+
class DistributionNotFound(ResolutionError):
"""A requested distribution was not found"""
@@ -763,9 +789,8 @@ class WorkingSet(object):
to_activate.append(dist)
if dist not in req:
# Oops, the "best" so far conflicts with a dependency
- tmpl = "%s is installed but %s is required by %s"
- args = dist, req, list(required_by.get(req, []))
- raise VersionConflict(tmpl % args)
+ dependent_req = list(required_by.get(req, []))
+ raise VersionConflict(dist, req, dependent_req)
# push the new requirements onto the stack
new_requirements = dist.requires(req.extras)[::-1]
diff --git a/pkg_resources/tests/test_resources.py b/pkg_resources/tests/test_resources.py
index 79961e6c..5cf3a657 100644
--- a/pkg_resources/tests/test_resources.py
+++ b/pkg_resources/tests/test_resources.py
@@ -175,8 +175,8 @@ class TestDistro:
with pytest.raises(VersionConflict) as vc:
ws.resolve(parse_requirements("Foo==1.2\nFoo!=1.2"), ad)
- msg = 'Foo 0.9 is installed but Foo==1.2 is required by []'
- assert str(vc).endswith(msg)
+ msg = 'Foo 0.9 is installed but Foo==1.2 is required'
+ assert vc.value.report() == msg
def testDistroDependsOptions(self):
d = self.distRequires("""
@@ -218,7 +218,7 @@ class TestWorkingSet:
ws.find(req)
msg = 'Foo 1.2 is installed but Foo<1.2 is required'
- assert str(vc).endswith(msg)
+ assert vc.value.report() == msg
class TestEntryPoints:
diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py
index 02ce7636..d05f4c65 100755
--- a/setuptools/command/easy_install.py
+++ b/setuptools/command/easy_install.py
@@ -703,10 +703,7 @@ Please make the appropriate changes for your system and try again.
"Could not find required distribution %s" % e.args
)
except VersionConflict as e:
- raise DistutilsError(
- "Installed distribution %s conflicts with requirement %s"
- % e.args
- )
+ raise DistutilsError(e.report())
if self.always_copy or self.always_copy_from:
# Force all the relevant distros to be copied or activated
for dist in distros: