diff options
author | Marc Abramowitz <marc@marc-abramowitz.com> | 2015-03-19 09:48:18 -0700 |
---|---|---|
committer | Marc Abramowitz <marc@marc-abramowitz.com> | 2015-03-19 09:48:18 -0700 |
commit | 457cf31da61a2ca3fbe7c91e11b23adb25d2c2b9 (patch) | |
tree | 5bb46bb489cb750215d80df8327c5ba586f1ee30 /pkg_resources | |
parent | 19c84ce5abb7e7cacb13ce23be5b12bba03323d9 (diff) | |
download | python-setuptools-bitbucket-457cf31da61a2ca3fbe7c91e11b23adb25d2c2b9.tar.gz |
DistributionNotFound: Show requirers
It is very helpful to know who required the missing package. E.g.:
pkg_resources.DistributionNotFound: The 'colorama>=0.3.1' distribution was not found and is required by smlib.log.
Note that there was a comment: "unfortunately, zc.buildout uses a str(err) to
get the name of the distribution here..", but I did a search in the `buildout`
code and I think that is no longer true, so I think that we're free to make the
exception message more helpful without risk of breaking buildout:
# In clone from https://github.com/buildout/buildout
$ ag DistributionNotFound
src/zc/buildout/buildout.py
686: except (ImportError, pkg_resources.DistributionNotFound):
$ pip install --download=. --no-install zc.buildout
...
Saved ./zc.buildout-2.3.1.tar.gz
...
$ tar xf zc.buildout-2.3.1.tar.gz
$ ag DistributionNotFound zc.buildout-2.3.1
zc.buildout-2.3.1/src/zc/buildout/buildout.py
686: except (ImportError, pkg_resources.DistributionNotFound):
Diffstat (limited to 'pkg_resources')
-rw-r--r-- | pkg_resources/__init__.py | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py index c3686f88..4e820c09 100644 --- a/pkg_resources/__init__.py +++ b/pkg_resources/__init__.py @@ -798,13 +798,16 @@ class WorkingSet(object): ws = WorkingSet([]) dist = best[req.key] = env.best_match(req, ws, installer) if dist is None: - #msg = ("The '%s' distribution was not found on this " - # "system, and is required by this application.") - #raise DistributionNotFound(msg % req) - - # unfortunately, zc.buildout uses a str(err) - # to get the name of the distribution here.. - raise DistributionNotFound(req) + 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) to_activate.append(dist) if dist not in req: # Oops, the "best" so far conflicts with a dependency |