#126 Merged at 1903f0f
Repository
pypa
Branch
default
Author
  1. Marc Abramowitz
Reviewers
Description

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):

Comments (6)

  1. Jason R. Coombs

    Thanks for the contrib. I do agree the DistributionNotFound could include more information. However, this technique feels not quite right. It's a fine implementation if all it represents is a human-readable error message. But thinking about other consumers of DistributionNotFound, it would be difficult to consume it programmatically. Also, the message template should be affiliated with the Exception and not this one invocation of the exception.

    Looking at VersionConflict as a model, it encapsulates the message rendering and parameters (optional and required), and renders a message accordingly. It keeps the attributes separate so they may be consumed independently.

    Note also that easy_install catches a DistributionNotFound exception and renders its args in a template string, so it should probably also be updated.

  2. Reinout van Rees

    a) Great feature. Also very useful for buildout. Seeing which package requires a distribution is something I've wanted for buildout for a long time.

    b) Sadly, buildout has been broken by this change. https://github.com/buildout/buildout/issues/246

    c) It is really something that needs to be changed in buildout, I think. Buildout is hard-coded to expect one argument, but there are now two. I'll prepare a buildout pull request.

  3. Reinout van Rees

    Actually, buildout has not been broken :-) Well, the 2.2.1 release (and earlier) have been broken, but changes in 2.2.2 meant that this specific DistributionNotFound isn't inspected in the same way anymore. So 2.2.2 and higher are all fine.

    I was just looking at a project that accidentally still had an old buildout. False alarm!