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 | 2283fc214217e5c3dca8cc65045271ab5d0ea522 (patch) | |
| tree | f95c92095abd8ca4574765d3f836d176e5cd1dd4 /pkg_resources/__init__.py | |
| parent | 1581c8404e12f32190d3bc29825b9910a46f2347 (diff) | |
| download | python-setuptools-git-2283fc214217e5c3dca8cc65045271ab5d0ea522.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):
--HG--
branch : DistributionNotFound_list_requirers
Diffstat (limited to 'pkg_resources/__init__.py')
| -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 |
