aboutsummaryrefslogtreecommitdiffstats
path: root/pkg_resources/__init__.py
diff options
context:
space:
mode:
authorBenoit Pierre <benoit.pierre@gmail.com>2017-08-07 23:28:19 +0200
committerBenoit Pierre <benoit.pierre@gmail.com>2017-08-29 14:34:38 +0200
commitff554f49af775663bc37e1005cf1b613804b2f51 (patch)
treed3119916e784923d9b705fc68073c6b8402757a9 /pkg_resources/__init__.py
parentb4d58d4929dd4e19870b5eafa48046a0a0c2bf07 (diff)
downloadexternal_python_setuptools-ff554f49af775663bc37e1005cf1b613804b2f51.tar.gz
external_python_setuptools-ff554f49af775663bc37e1005cf1b613804b2f51.tar.bz2
external_python_setuptools-ff554f49af775663bc37e1005cf1b613804b2f51.zip
pkg_resources: improve WorkingSet.resolve(replace_conflicting=True)
Correctly replace conflicting distributions in sub-requirements if possible (instead of only for top-level requirements passed as arguments). Fix #1124.
Diffstat (limited to 'pkg_resources/__init__.py')
-rw-r--r--pkg_resources/__init__.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py
index f13a69b3..9eb2a370 100644
--- a/pkg_resources/__init__.py
+++ b/pkg_resources/__init__.py
@@ -852,7 +852,10 @@ class WorkingSet(object):
# distribution
env = Environment([])
ws = WorkingSet([])
- dist = best[req.key] = env.best_match(req, ws, installer)
+ dist = best[req.key] = env.best_match(
+ req, ws, installer,
+ replace_conflicting=replace_conflicting
+ )
if dist is None:
requirers = required_by.get(req, None)
raise DistributionNotFound(req, requirers)
@@ -1104,7 +1107,7 @@ class Environment(object):
dists.append(dist)
dists.sort(key=operator.attrgetter('hashcmp'), reverse=True)
- def best_match(self, req, working_set, installer=None):
+ def best_match(self, req, working_set, installer=None, replace_conflicting=False):
"""Find distribution best matching `req` and usable on `working_set`
This calls the ``find(req)`` method of the `working_set` to see if a
@@ -1117,7 +1120,12 @@ class Environment(object):
calling the environment's ``obtain(req, installer)`` method will be
returned.
"""
- dist = working_set.find(req)
+ try:
+ dist = working_set.find(req)
+ except VersionConflict:
+ if not replace_conflicting:
+ raise
+ dist = None
if dist is not None:
return dist
for dist in self[req.key]: