aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Abramowitz <marc@marc-abramowitz.com>2015-03-24 08:20:42 -0700
committerMarc Abramowitz <marc@marc-abramowitz.com>2015-03-24 08:20:42 -0700
commite1f0b4019be6efa9c20f0f0dae13009f071ff2a0 (patch)
treea7ce91785c27871b48323342aad45206ef62d558
parent2283fc214217e5c3dca8cc65045271ab5d0ea522 (diff)
downloadexternal_python_setuptools-e1f0b4019be6efa9c20f0f0dae13009f071ff2a0.tar.gz
external_python_setuptools-e1f0b4019be6efa9c20f0f0dae13009f071ff2a0.tar.bz2
external_python_setuptools-e1f0b4019be6efa9c20f0f0dae13009f071ff2a0.zip
DistributionNotFound: Move message template to class
--HG-- branch : DistributionNotFound_list_requirers
-rw-r--r--pkg_resources/__init__.py34
-rwxr-xr-xsetuptools/command/easy_install.py4
2 files changed, 26 insertions, 12 deletions
diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py
index 4e820c09..6f1ab9b7 100644
--- a/pkg_resources/__init__.py
+++ b/pkg_resources/__init__.py
@@ -368,6 +368,30 @@ class ContextualVersionConflict(VersionConflict):
class DistributionNotFound(ResolutionError):
"""A requested distribution was not found"""
+ _template = ("The '{self.req}' distribution was not found "
+ "and is required by {self.requirers_str}")
+
+ @property
+ def req(self):
+ return self.args[0]
+
+ @property
+ def requirers(self):
+ return self.args[1]
+
+ @property
+ def requirers_str(self):
+ if not self.requirers:
+ return 'the application'
+ return ', '.join(self.requirers)
+
+ def report(self):
+ return self._template.format(**locals())
+
+ def __str__(self):
+ return self.report()
+
+
class UnknownExtra(ResolutionError):
"""Distribution doesn't have an "extra feature" of the given name"""
_provider_factories = {}
@@ -799,15 +823,7 @@ class WorkingSet(object):
dist = best[req.key] = env.best_match(req, ws, installer)
if dist is None:
requirers = required_by.get(req, None)
- if requirers:
- requirers_str = ', '.join(requirers)
- else:
- requirers_str = 'this application'
- msg = ("The '%s' distribution was not found "
- "and is required by %s."
- % (req, requirers_str))
- warnings.warn(msg)
- raise DistributionNotFound(msg)
+ raise DistributionNotFound(req, requirers)
to_activate.append(dist)
if dist not in req:
# Oops, the "best" so far conflicts with a dependency
diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py
index 276b6f99..f2bfa68d 100755
--- a/setuptools/command/easy_install.py
+++ b/setuptools/command/easy_install.py
@@ -709,9 +709,7 @@ class easy_install(Command):
[requirement], self.local_index, self.easy_install
)
except DistributionNotFound as e:
- raise DistutilsError(
- "Could not find required distribution %s" % e.args
- )
+ raise DistutilsError(str(e))
except VersionConflict as e:
raise DistutilsError(e.report())
if self.always_copy or self.always_copy_from: