Installing setuptools/distribute
--------------------------------

Some initial test setup:

    >>> import sys
    >>> import zc.buildout
    >>> dest = tmpdir('sample-install')

Setuptools (0.6something) is packaged as an ``.egg``.  So when installing it,
the egg is downloaded and used.  Distribute is packaged as a tarball, which
makes an easy_install call necessary.  In older versions of buildout, the
``_call_easy_install()`` method would call ``_get_dist()`` to get hold of the
setuptools path for calling easy_install.  When an updated "distribute" was
found, this would try an install again, leading to an infinite recursion.

The solution is to just use the setuptools location found at import time, like
happens with the buildout and setuptools location that is inserted in scripts'
paths.

We test this corner case by patching the ``_get_dist()`` call:

    >>> def mock_get_dist(requirement, ws, always_unzip):
    ...     raise RuntimeError("We should not get called")

When installing setuptools itself, we expect the "Getting dist" message not to
be printed.  We call ``_call_easy_install()`` directly and get an error
because of a non-existing tarball, but that's the OK for this corner case
test: we only want to test that ``_get_dist()`` isn't getting called:

    >>> class MockDist(object):
    ...     def __str__(self):
    ...         return 'nonexisting.tgz'
    ...     @property
    ...     def project_name(self):
    ...         # Testing corner case: there *is* actually
    ...         # a newer setuptools package on pypi than we
    ...         # are running with, so it really installs it
    ...         # and compares project_name. We're past the
    ...         # point that we're testing, so we just raise
    ...         # the normally expected error.
    ...         raise zc.buildout.UserError(
    ...             "Couldn't install: nonexisting.tgz")
    >>> dist = MockDist()

    >>> installer = zc.buildout.easy_install.Installer(
    ...     dest=dest,
    ...     links=[link_server],
    ...     index=link_server+'index/',
    ...     executable=sys.executable,
    ...     always_unzip=True)
    >>> installer._get_dist = mock_get_dist
    >>> installer._call_easy_install('setuptools', None, dest, dist)
    Traceback (most recent call last):
    ...
    UserError: Couldn't install: nonexisting.tgz
