summaryrefslogtreecommitdiff
path: root/pkg_resources
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2015-01-04 13:39:31 -0500
committerJason R. Coombs <jaraco@jaraco.com>2015-01-04 13:39:31 -0500
commit57cf6e93a4506a7c78c549627347fc71098d1e9c (patch)
treebabd62ca6ffade623cd0896b9ab1d07f41d65b60 /pkg_resources
parent9d86d5d259de3009c1b3ea196dcdf6f3b5b1251f (diff)
downloadpython-setuptools-bitbucket-57cf6e93a4506a7c78c549627347fc71098d1e9c.tar.gz
Split out ContextualVersionConflict
Diffstat (limited to 'pkg_resources')
-rw-r--r--pkg_resources/__init__.py29
1 files changed, 18 insertions, 11 deletions
diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py
index 0846c0ac..277da3f9 100644
--- a/pkg_resources/__init__.py
+++ b/pkg_resources/__init__.py
@@ -322,11 +322,12 @@ class VersionConflict(ResolutionError):
"""
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.
+ Should be initialized with the installed Distribution and the requested
+ Requirement.
"""
+ _template = "{self.dist} is installed but {self.req} is required"
+
@property
def dist(self):
return self.args[0]
@@ -335,15 +336,21 @@ class VersionConflict(ResolutionError):
def req(self):
return self.args[1]
+ def report(self):
+ return self._template.format(**locals())
+
+
+class ContextualVersionConflict(VersionConflict):
+ """
+ A VersionConflict that accepts a third parameter, the list of the
+ requirements that required the installed Distribution.
+ """
+
+ _template = VersionConflict._template + ' by {self.required_by}'
+
@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())
+ return self.args[2]
class DistributionNotFound(ResolutionError):
@@ -790,7 +797,7 @@ class WorkingSet(object):
if dist not in req:
# Oops, the "best" so far conflicts with a dependency
dependent_req = list(required_by.get(req, []))
- raise VersionConflict(dist, req, dependent_req)
+ raise ContextualVersionConflict(dist, req, dependent_req)
# push the new requirements onto the stack
new_requirements = dist.requires(req.extras)[::-1]