Commit 2283fc21 authored by Marc Abramowitz's avatar Marc Abramowitz

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
parent 1581c840
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment