diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2015-01-04 13:39:31 -0500 |
|---|---|---|
| committer | Jason R. Coombs <jaraco@jaraco.com> | 2015-01-04 13:39:31 -0500 |
| commit | ddb012669aa26fffd6791283e6405fa34bf9f0e5 (patch) | |
| tree | c787e6192999ee72c053206c61ca3210912b9ac4 /pkg_resources | |
| parent | 23d5e4a81a61c5e6617fa69fd0b2bc440fa20c45 (diff) | |
| download | python-setuptools-git-ddb012669aa26fffd6791283e6405fa34bf9f0e5.tar.gz | |
Split out ContextualVersionConflict
Diffstat (limited to 'pkg_resources')
| -rw-r--r-- | pkg_resources/__init__.py | 29 |
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] |
