Exemple #1
0
def _extract_egg_args(args):
    eggs, reqs = [], []
    for arg in args:
        if os.path.exists(arg) and os.path.splitext(arg)[1] == '.egg':
            eggs.append(arg)
            reqs.append(str(egg_distribution(arg).as_requirement()))
        else:
            reqs.append(arg)
    return eggs, reqs
Exemple #2
0
def _extract_egg_args(args):
    eggs, reqs = [], []
    for arg in args:
        if os.path.exists(arg) and os.path.splitext(arg)[1] == '.egg':
            eggs.append(arg)
            reqs.append(str(egg_distribution(arg).as_requirement()))
        else:
            reqs.append(arg)
    return eggs, reqs
Exemple #3
0
def install(cmd,
            reqs,
            add_to_global=False,
            prefer_final=True,
            force_upgrade=False,
            use_existing=False,
            eggs=None,
            reinstall=False):
    """ Installs a given requirement using buildout's modified easy_install.

        Parameters
        ----------
        cmd : `setuptools.Command`
           active setuptools Command class
        reqs : `list` of `str`
           list of distutils requirements, eg ['foo==1.2']
        eggs : `list` of `str`
           paths to egg files to use to satisfy requirements
        add_to_global : `bool`
           adds installed distribution to the global working_set.
           This has the effect of making them available for import within this
           process, used by fetch_build_eggs.
        prefer_final : `bool`
           Will prefer released versions of the requirements over dev versions,
           unless the package is third-party where it always prefers final
           versions.
        force_upgrade : `bool`
           Will force downloads of requirements from PyPI. This is the rough
           equivalent of ``easy_install -U acme.foo``
        use_existing : `bool`
           Will not update any packages found in the current working set
        reinstall : `bool`
            Will reinstall packages that are already installed.

        Returns
        -------
        ws : `pkg_resources.WorkingSet`
            Working Set for the distributions that were just installed.
    """
    # Remove anything we're upgrading
    if force_upgrade:
        uninstall_eggs(reqs)

    # Create installer class configured to install into wherever the command
    # class was setup for
    installer = Installer(dest=cmd.install_dir,
                          index=cmd.index_url,
                          prefer_final=prefer_final)

    egg_dists = [egg_distribution(egg) for egg in (eggs or [])]
    installer._egg_dists = egg_dists

    # This is a bit nasty - we have to monkey-patch the filter for final
    # versions so that we can also filter for dev versions as well.

    # Set prefer_final to True, always, so it enables the filter
    easy_install.prefer_final(True)

    # This returns a WorkingSet of the packages we just installed.
    # NOTE here we pass in the existing stuff - this will prefer installed
    #      packages over ones on the server, eg an installed release
    #      version won't get trumped by a dev version on the server
    ws = pkg_resources.WorkingSet(pkg_resources.working_set.entries)

    # We must remove the package we're installing from the 'baseline' ws.
    # This way we won't get any weird requirement conflicts with new
    # versions of the package we're trying to set up
    if cmd.distribution.metadata.name:
        dist = dependency.get_dist(cmd.distribution.metadata.name)
        if dist:
            dependency.remove_from_ws(ws, dist)

    # There's a chance that there were packages in setup_requires that were
    # also in install_requires. All packages that were not in the original
    # environment and were installed during the `setup_requires` resolution
    # process are tracked by `fetched_setup_requires` field of
    # `pkglib.setuptools.dist.Distribution`.

    # Here we ensure that they're re-added for setup along with any of their
    # own dependencies if they are also part of the package install_requires.

    for d in getattr(cmd.distribution, "fetched_setup_requires", []):
        dependency.remove_from_ws(ws, d)

    # Now run the installer
    to_setup = installer.install(reqs,
                                 working_set=ws,
                                 use_existing=use_existing,
                                 force_upgrade=force_upgrade,
                                 reinstall=reinstall)

    return setup_dists(cmd,
                       ws,
                       to_setup,
                       egg_dists,
                       add_to_global=add_to_global)
Exemple #4
0
def install(cmd, reqs, add_to_global=False, prefer_final=True,
            force_upgrade=False, use_existing=False, eggs=None,
            reinstall=False):
    """ Installs a given requirement using buildout's modified easy_install.

        Parameters
        ----------
        cmd : `setuptools.Command`
           active setuptools Command class
        reqs : `list` of `str`
           list of distutils requirements, eg ['foo==1.2']
        eggs : `list` of `str`
           paths to egg files to use to satisfy requirements
        add_to_global : `bool`
           adds installed distribution to the global working_set.
           This has the effect of making them available for import within this
           process, used by fetch_build_eggs.
        prefer_final : `bool`
           Will prefer released versions of the requirements over dev versions,
           unless the package is third-party where it always prefers final
           versions.
        force_upgrade : `bool`
           Will force downloads of requirements from PyPI. This is the rough
           equivalent of ``easy_install -U acme.foo``
        use_existing : `bool`
           Will not update any packages found in the current working set
        reinstall : `bool`
            Will reinstall packages that are already installed.

        Returns
        -------
        ws : `pkg_resources.WorkingSet`
            Working Set for the distributions that were just installed.
    """
    # Remove anything we're upgrading
    if force_upgrade:
        uninstall_eggs(reqs)

    # Create installer class configured to install into wherever the command
    # class was setup for
    installer = Installer(dest=cmd.install_dir, index=cmd.index_url,
                          prefer_final=prefer_final)

    egg_dists = [egg_distribution(egg) for egg in (eggs or [])]
    installer._egg_dists = egg_dists

    # This is a bit nasty - we have to monkey-patch the filter for final
    # versions so that we can also filter for dev versions as well.

    # Set prefer_final to True, always, so it enables the filter
    easy_install.prefer_final(True)

    # This returns a WorkingSet of the packages we just installed.
    # NOTE here we pass in the existing stuff - this will prefer installed
    #      packages over ones on the server, eg an installed release
    #      version won't get trumped by a dev version on the server
    ws = pkg_resources.WorkingSet(pkg_resources.working_set.entries)

    # We must remove the package we're installing from the 'baseline' ws.
    # This way we won't get any weird requirement conflicts with new
    # versions of the package we're trying to set up
    if cmd.distribution.metadata.name:
        dist = dependency.get_dist(cmd.distribution.metadata.name)
        if dist:
            dependency.remove_from_ws(ws, dist)

    # There's a chance that there were packages in setup_requires that were
    # also in install_requires. All packages that were not in the original
    # environment and were installed during the `setup_requires` resolution
    # process are tracked by `fetched_setup_requires` field of
    # `pkglib.setuptools.dist.Distribution`.

    # Here we ensure that they're re-added for setup along with any of their
    # own dependencies if they are also part of the package install_requires.

    for d in getattr(cmd.distribution, "fetched_setup_requires", []):
        dependency.remove_from_ws(ws, d)

    # Now run the installer
    to_setup = installer.install(reqs, working_set=ws,
                                 use_existing=use_existing,
                                 force_upgrade=force_upgrade,
                                 reinstall=reinstall)

    return setup_dists(cmd, ws, to_setup, egg_dists,
                       add_to_global=add_to_global)