2014-08-31 01:52:28 +02:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2015-03-19 00:20:40 +01:00
|
|
|
import functools
|
|
|
|
import itertools
|
2014-08-31 01:52:28 +02:00
|
|
|
import logging
|
2014-01-12 07:50:07 +01:00
|
|
|
import os
|
|
|
|
|
|
|
|
from pip._vendor import pkg_resources
|
2014-09-11 21:28:21 +02:00
|
|
|
from pip._vendor import requests
|
|
|
|
|
2014-05-16 16:36:06 +02:00
|
|
|
from pip.download import (url_to_path, unpack_url)
|
2014-01-12 07:50:07 +01:00
|
|
|
from pip.exceptions import (InstallationError, BestVersionAlreadyInstalled,
|
2014-01-12 19:05:11 +01:00
|
|
|
DistributionNotFound, PreviousBuildDirError)
|
2014-05-16 16:36:06 +02:00
|
|
|
from pip.locations import (PIP_DELETE_MARKER_FILENAME, build_prefix)
|
2014-01-12 19:05:11 +01:00
|
|
|
from pip.req.req_install import InstallRequirement
|
2014-12-20 11:53:20 +01:00
|
|
|
from pip.utils import (display_path, rmtree, dist_in_usersite, normalize_path)
|
2014-08-31 01:52:28 +02:00
|
|
|
from pip.utils.logging import indent_log
|
2014-01-12 07:50:07 +01:00
|
|
|
from pip.vcs import vcs
|
2014-01-12 01:50:11 +01:00
|
|
|
|
|
|
|
|
2014-08-31 01:52:28 +02:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2014-01-12 01:50:11 +01:00
|
|
|
class Requirements(object):
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self._keys = []
|
|
|
|
self._dict = {}
|
|
|
|
|
|
|
|
def keys(self):
|
|
|
|
return self._keys
|
|
|
|
|
|
|
|
def values(self):
|
|
|
|
return [self._dict[key] for key in self._keys]
|
|
|
|
|
|
|
|
def __contains__(self, item):
|
|
|
|
return item in self._keys
|
|
|
|
|
|
|
|
def __setitem__(self, key, value):
|
|
|
|
if key not in self._keys:
|
|
|
|
self._keys.append(key)
|
|
|
|
self._dict[key] = value
|
|
|
|
|
|
|
|
def __getitem__(self, key):
|
|
|
|
return self._dict[key]
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
values = ['%s: %s' % (repr(k), repr(self[k])) for k in self.keys()]
|
|
|
|
return 'Requirements({%s})' % ', '.join(values)
|
|
|
|
|
|
|
|
|
2015-03-19 05:01:55 +01:00
|
|
|
class DistAbstraction(object):
|
|
|
|
"""Abstracts out the wheel vs non-wheel prepare_files logic."""
|
|
|
|
|
|
|
|
def __init__(self, req_to_install):
|
|
|
|
self.req_to_install = req_to_install
|
|
|
|
|
|
|
|
def dist(self, finder):
|
|
|
|
"""Return a setuptools Dist object."""
|
|
|
|
raise NotImplementedError(self.dist)
|
|
|
|
|
|
|
|
def prep_for_dist(self):
|
|
|
|
"""Ensure that we can get a Dist for this requirement."""
|
|
|
|
raise NotImplementedError(self.dist)
|
|
|
|
|
|
|
|
|
|
|
|
class IsWheel(DistAbstraction):
|
|
|
|
|
2015-03-20 00:08:42 +01:00
|
|
|
def __init__(self, req_to_install, location):
|
2015-03-19 05:01:55 +01:00
|
|
|
super(IsWheel, self).__init__(req_to_install)
|
|
|
|
self.location = location
|
|
|
|
|
|
|
|
def dist(self, finder):
|
|
|
|
return list(pkg_resources.find_distributions(self.location))[0]
|
|
|
|
|
|
|
|
def prep_for_dist(self):
|
|
|
|
# FIXME:https://github.com/pypa/pip/issues/1112
|
2015-03-20 00:08:42 +01:00
|
|
|
pass
|
2015-03-19 05:01:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
class IsSDist(DistAbstraction):
|
|
|
|
|
|
|
|
def dist(self, finder):
|
|
|
|
if self.req_to_install.satisfied_by:
|
|
|
|
dist = self.req_to_install.satisfied_by
|
|
|
|
else:
|
|
|
|
dist = self.req_to_install.get_dist()
|
|
|
|
# FIXME: shouldn't be globally added:
|
|
|
|
if dist.has_metadata('dependency_links.txt'):
|
|
|
|
finder.add_dependency_links(
|
|
|
|
dist.get_metadata_lines('dependency_links.txt')
|
|
|
|
)
|
|
|
|
return dist
|
|
|
|
|
|
|
|
def prep_for_dist(self):
|
|
|
|
self.req_to_install.run_egg_info()
|
|
|
|
self.req_to_install.assert_source_matches_version()
|
|
|
|
|
|
|
|
|
2014-01-12 01:50:11 +01:00
|
|
|
class RequirementSet(object):
|
|
|
|
|
2014-04-24 13:29:57 +02:00
|
|
|
def __init__(self, build_dir, src_dir, download_dir, upgrade=False,
|
|
|
|
ignore_installed=False, as_egg=False, target_dir=None,
|
|
|
|
ignore_dependencies=False, force_reinstall=False,
|
|
|
|
use_user_site=False, session=None, pycompile=True,
|
2014-12-11 15:44:53 +01:00
|
|
|
isolated=False, wheel_download_dir=None):
|
2014-05-07 01:25:44 +02:00
|
|
|
if session is None:
|
|
|
|
raise TypeError(
|
|
|
|
"RequirementSet() missing 1 required keyword argument: "
|
|
|
|
"'session'"
|
|
|
|
)
|
|
|
|
|
2014-01-12 01:50:11 +01:00
|
|
|
self.build_dir = build_dir
|
|
|
|
self.src_dir = src_dir
|
2015-03-20 03:15:56 +01:00
|
|
|
# XXX: download_dir and wheel_download_dir overlap semantically and may
|
|
|
|
# be combinable.
|
2014-01-12 01:50:11 +01:00
|
|
|
self.download_dir = download_dir
|
|
|
|
self.upgrade = upgrade
|
|
|
|
self.ignore_installed = ignore_installed
|
|
|
|
self.force_reinstall = force_reinstall
|
|
|
|
self.requirements = Requirements()
|
|
|
|
# Mapping of alias: real_name
|
|
|
|
self.requirement_aliases = {}
|
|
|
|
self.unnamed_requirements = []
|
|
|
|
self.ignore_dependencies = ignore_dependencies
|
|
|
|
self.successfully_downloaded = []
|
|
|
|
self.successfully_installed = []
|
|
|
|
self.reqs_to_cleanup = []
|
|
|
|
self.as_egg = as_egg
|
|
|
|
self.use_user_site = use_user_site
|
2014-01-27 15:07:10 +01:00
|
|
|
self.target_dir = target_dir # set from --target option
|
2014-05-07 01:25:44 +02:00
|
|
|
self.session = session
|
2014-01-12 01:50:11 +01:00
|
|
|
self.pycompile = pycompile
|
2014-12-11 15:44:53 +01:00
|
|
|
self.isolated = isolated
|
2014-05-03 22:41:44 +02:00
|
|
|
if wheel_download_dir:
|
|
|
|
wheel_download_dir = normalize_path(wheel_download_dir)
|
2014-02-01 20:41:55 +01:00
|
|
|
self.wheel_download_dir = wheel_download_dir
|
2014-01-12 01:50:11 +01:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
reqs = [req for req in self.requirements.values()
|
|
|
|
if not req.comes_from]
|
|
|
|
reqs.sort(key=lambda req: req.name.lower())
|
|
|
|
return ' '.join([str(req.req) for req in reqs])
|
|
|
|
|
|
|
|
def add_requirement(self, install_req):
|
2014-01-14 18:36:47 +01:00
|
|
|
if not install_req.match_markers():
|
2014-11-20 16:53:03 +01:00
|
|
|
logger.debug("Ignore %s: markers %r don't match",
|
|
|
|
install_req.name, install_req.markers)
|
2014-01-14 18:36:47 +01:00
|
|
|
return
|
|
|
|
|
2014-01-12 01:50:11 +01:00
|
|
|
name = install_req.name
|
|
|
|
install_req.as_egg = self.as_egg
|
|
|
|
install_req.use_user_site = self.use_user_site
|
|
|
|
install_req.target_dir = self.target_dir
|
|
|
|
install_req.pycompile = self.pycompile
|
|
|
|
if not name:
|
2014-03-26 23:24:19 +01:00
|
|
|
# url or path requirement w/o an egg fragment
|
2014-01-12 01:50:11 +01:00
|
|
|
self.unnamed_requirements.append(install_req)
|
|
|
|
else:
|
|
|
|
if self.has_requirement(name):
|
|
|
|
raise InstallationError(
|
|
|
|
'Double requirement given: %s (already in %s, name=%r)'
|
|
|
|
% (install_req, self.get_requirement(name), name))
|
|
|
|
self.requirements[name] = install_req
|
2014-03-26 23:24:19 +01:00
|
|
|
# FIXME: what about other normalizations? E.g., _ vs. -?
|
2014-01-12 01:50:11 +01:00
|
|
|
if name.lower() != name:
|
|
|
|
self.requirement_aliases[name.lower()] = name
|
|
|
|
|
|
|
|
def has_requirement(self, project_name):
|
|
|
|
for name in project_name, project_name.lower():
|
|
|
|
if name in self.requirements or name in self.requirement_aliases:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
@property
|
|
|
|
def has_requirements(self):
|
|
|
|
return list(self.requirements.values()) or self.unnamed_requirements
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_download(self):
|
|
|
|
if self.download_dir:
|
|
|
|
self.download_dir = os.path.expanduser(self.download_dir)
|
|
|
|
if os.path.exists(self.download_dir):
|
|
|
|
return True
|
|
|
|
else:
|
2014-08-31 01:52:28 +02:00
|
|
|
logger.critical('Could not find download directory')
|
2014-01-12 01:50:11 +01:00
|
|
|
raise InstallationError(
|
|
|
|
"Could not find or access download directory '%s'"
|
|
|
|
% display_path(self.download_dir))
|
|
|
|
return False
|
|
|
|
|
|
|
|
def get_requirement(self, project_name):
|
|
|
|
for name in project_name, project_name.lower():
|
|
|
|
if name in self.requirements:
|
|
|
|
return self.requirements[name]
|
|
|
|
if name in self.requirement_aliases:
|
|
|
|
return self.requirements[self.requirement_aliases[name]]
|
|
|
|
raise KeyError("No project with the name %r" % project_name)
|
|
|
|
|
|
|
|
def uninstall(self, auto_confirm=False):
|
|
|
|
for req in self.requirements.values():
|
|
|
|
req.uninstall(auto_confirm=auto_confirm)
|
|
|
|
req.commit_uninstall()
|
|
|
|
|
2015-03-19 00:20:40 +01:00
|
|
|
def _walk_req_to_install(self, handler):
|
|
|
|
"""Call handler for all pending reqs.
|
|
|
|
|
|
|
|
:param handler: Handle a single requirement. Should take a requirement
|
|
|
|
to install. Can optionally return an iterable of additional
|
|
|
|
InstallRequirements to cover.
|
|
|
|
"""
|
|
|
|
# The list() here is to avoid potential mutate-while-iterating bugs.
|
|
|
|
discovered_reqs = []
|
|
|
|
reqs = itertools.chain(
|
|
|
|
list(self.unnamed_requirements), list(self.requirements.values()),
|
|
|
|
discovered_reqs)
|
|
|
|
for req_to_install in reqs:
|
|
|
|
more_reqs = handler(req_to_install)
|
|
|
|
if more_reqs:
|
|
|
|
discovered_reqs.extend(more_reqs)
|
|
|
|
|
2014-01-12 01:50:11 +01:00
|
|
|
def locate_files(self):
|
2015-03-19 03:04:58 +01:00
|
|
|
"""Remove in 7.0: used by --no-download"""
|
2015-03-19 00:20:40 +01:00
|
|
|
self._walk_req_to_install(self._locate_file)
|
|
|
|
|
|
|
|
def _locate_file(self, req_to_install):
|
|
|
|
install_needed = True
|
|
|
|
if not self.ignore_installed and not req_to_install.editable:
|
|
|
|
req_to_install.check_if_exists()
|
|
|
|
if req_to_install.satisfied_by:
|
|
|
|
if self.upgrade:
|
|
|
|
# don't uninstall conflict if user install and
|
|
|
|
# conflict is not user install
|
|
|
|
if not (self.use_user_site and
|
|
|
|
not dist_in_usersite(
|
2014-01-27 15:07:10 +01:00
|
|
|
req_to_install.satisfied_by
|
2015-03-19 00:20:40 +01:00
|
|
|
)):
|
|
|
|
req_to_install.conflicts_with = \
|
|
|
|
req_to_install.satisfied_by
|
|
|
|
req_to_install.satisfied_by = None
|
|
|
|
else:
|
|
|
|
install_needed = False
|
|
|
|
logger.info(
|
|
|
|
'Requirement already satisfied (use --upgrade to '
|
|
|
|
'upgrade): %s',
|
|
|
|
req_to_install,
|
2014-01-27 15:07:10 +01:00
|
|
|
)
|
2015-03-19 00:20:40 +01:00
|
|
|
|
|
|
|
if req_to_install.editable:
|
|
|
|
if req_to_install.source_dir is None:
|
2014-01-27 15:07:10 +01:00
|
|
|
req_to_install.source_dir = req_to_install.build_location(
|
2015-03-19 00:20:40 +01:00
|
|
|
self.src_dir
|
2014-01-27 15:07:10 +01:00
|
|
|
)
|
2015-03-19 00:20:40 +01:00
|
|
|
elif install_needed:
|
|
|
|
req_to_install.source_dir = req_to_install.build_location(
|
|
|
|
self.build_dir,
|
|
|
|
)
|
2014-01-12 01:50:11 +01:00
|
|
|
|
2015-03-19 00:20:40 +01:00
|
|
|
if (req_to_install.source_dir is not None and not
|
|
|
|
os.path.isdir(req_to_install.source_dir)):
|
|
|
|
raise InstallationError(
|
|
|
|
'Could not install requirement %s because source folder %s'
|
|
|
|
' does not exist (perhaps --no-download was used without '
|
|
|
|
'first running an equivalent install with --no-install?)' %
|
|
|
|
(req_to_install, req_to_install.source_dir)
|
|
|
|
)
|
2014-01-12 01:50:11 +01:00
|
|
|
|
2014-05-08 18:12:34 +02:00
|
|
|
def prepare_files(self, finder):
|
2014-01-27 15:07:10 +01:00
|
|
|
"""
|
|
|
|
Prepare process. Create temp directories, download and/or unpack files.
|
|
|
|
"""
|
2015-03-19 00:20:40 +01:00
|
|
|
self._walk_req_to_install(
|
|
|
|
functools.partial(self._prepare_file, finder))
|
|
|
|
|
|
|
|
def _prepare_file(self, finder, req_to_install):
|
|
|
|
"""Prepare a single requirements files.
|
|
|
|
|
|
|
|
:return: A list of addition InstallRequirements to also install.
|
|
|
|
"""
|
|
|
|
# ############################################# #
|
|
|
|
# # Search for archive to fulfill requirement # #
|
|
|
|
# ############################################# #
|
|
|
|
|
|
|
|
if req_to_install.editable:
|
|
|
|
logger.info('Obtaining %s', req_to_install)
|
2015-03-20 07:40:51 +01:00
|
|
|
else:
|
|
|
|
if not self.ignore_installed:
|
|
|
|
# Check whether to upgrade/reinstall this req or not.
|
|
|
|
req_to_install.check_if_exists()
|
|
|
|
if req_to_install.satisfied_by:
|
|
|
|
skip_reason = 'satisfied (use --upgrade to upgrade)'
|
|
|
|
# check that we don't already have an exact version match
|
|
|
|
# i.e. with at least one strict req operator
|
|
|
|
strict_req = set(('==', '===')) & set(
|
|
|
|
op for op, _ in req_to_install.req.specs)
|
|
|
|
if self.upgrade and (
|
|
|
|
not strict_req or self.force_reinstall):
|
|
|
|
best_installed = False
|
|
|
|
# For link based requirements we have to pull the
|
|
|
|
# tree down and inspect to assess the version #, so
|
|
|
|
# its handled way down.
|
|
|
|
if not (self.force_reinstall or req_to_install.link):
|
|
|
|
try:
|
|
|
|
finder.find_requirement(
|
|
|
|
req_to_install, self.upgrade)
|
|
|
|
except BestVersionAlreadyInstalled:
|
|
|
|
skip_reason = 'up-to-date'
|
|
|
|
best_installed = True
|
|
|
|
except DistributionNotFound as exc:
|
|
|
|
# No distribution found, so we squash the
|
|
|
|
# error...
|
|
|
|
# However, we then set satisfied_by to None
|
|
|
|
# below which leads to an attemp to install
|
|
|
|
# it later, which will fail hilariously.
|
|
|
|
# Why?
|
|
|
|
pass
|
|
|
|
|
|
|
|
if not best_installed:
|
|
|
|
# don't uninstall conflict if user install and
|
|
|
|
# conflict is not user install
|
|
|
|
if not (self.use_user_site and not
|
|
|
|
dist_in_usersite(
|
|
|
|
req_to_install.satisfied_by
|
|
|
|
)):
|
|
|
|
req_to_install.conflicts_with = \
|
|
|
|
req_to_install.satisfied_by
|
|
|
|
req_to_install.satisfied_by = None
|
|
|
|
if req_to_install.satisfied_by:
|
|
|
|
logger.info(
|
|
|
|
'Requirement already %s: %s', skip_reason,
|
|
|
|
req_to_install)
|
|
|
|
if not req_to_install.satisfied_by:
|
|
|
|
if (req_to_install.link and
|
|
|
|
req_to_install.link.scheme == 'file'):
|
|
|
|
path = url_to_path(req_to_install.link.url)
|
|
|
|
logger.info('Processing %s', display_path(path))
|
|
|
|
else:
|
|
|
|
logger.info('Collecting %s', req_to_install)
|
2014-02-01 20:41:55 +01:00
|
|
|
|
2015-03-19 00:20:40 +01:00
|
|
|
with indent_log():
|
|
|
|
# ################################ #
|
|
|
|
# # vcs update or unpack archive # #
|
|
|
|
# ################################ #
|
2015-03-19 05:01:55 +01:00
|
|
|
abstract_dist = IsSDist(req_to_install)
|
2015-03-19 03:33:23 +01:00
|
|
|
more_reqs = []
|
2015-03-19 00:20:40 +01:00
|
|
|
if req_to_install.editable:
|
|
|
|
if req_to_install.source_dir is None:
|
|
|
|
req_to_install.source_dir = (
|
|
|
|
req_to_install.build_location(self.src_dir)
|
|
|
|
)
|
|
|
|
location = req_to_install.source_dir
|
|
|
|
req_to_install.update_editable(not self.is_download)
|
2015-03-19 05:01:55 +01:00
|
|
|
abstract_dist.prep_for_dist()
|
2015-03-19 00:20:40 +01:00
|
|
|
if self.is_download:
|
|
|
|
req_to_install.archive(self.download_dir)
|
2015-03-20 07:40:51 +01:00
|
|
|
elif not req_to_install.satisfied_by:
|
2015-03-19 00:20:40 +01:00
|
|
|
# @@ if filesystem packages are not marked
|
|
|
|
# editable in a req, a non deterministic error
|
|
|
|
# occurs when the script attempts to unpack the
|
|
|
|
# build directory
|
|
|
|
|
|
|
|
# NB: This call can result in the creation of a temporary
|
|
|
|
# build directory
|
|
|
|
location = req_to_install.build_location(
|
|
|
|
self.build_dir,
|
|
|
|
)
|
|
|
|
# If a checkout exists, it's unwise to keep going. version
|
|
|
|
# inconsistencies are logged later, but do not fail the
|
|
|
|
# installation.
|
2015-03-20 00:08:42 +01:00
|
|
|
# FIXME: this won't upgrade when there's an existing
|
|
|
|
# package unpacked in `location`
|
2015-03-19 00:20:40 +01:00
|
|
|
if os.path.exists(os.path.join(location, 'setup.py')):
|
|
|
|
raise PreviousBuildDirError(
|
|
|
|
"pip can't proceed with requirements '%s' due to a"
|
|
|
|
" pre-existing build directory (%s). This is "
|
|
|
|
"likely due to a previous installation that failed"
|
|
|
|
". pip is being responsible and not assuming it "
|
|
|
|
"can delete this. Please delete it and try again."
|
|
|
|
% (req_to_install, location)
|
|
|
|
)
|
2015-03-20 00:08:42 +01:00
|
|
|
req_to_install.populate_link(finder, self.upgrade)
|
|
|
|
if req_to_install.link:
|
2015-03-19 06:23:26 +01:00
|
|
|
try:
|
2015-03-20 07:40:51 +01:00
|
|
|
if req_to_install.link.is_wheel and \
|
|
|
|
self.wheel_download_dir:
|
2015-03-19 06:23:26 +01:00
|
|
|
# when doing 'pip wheel`
|
|
|
|
download_dir = self.wheel_download_dir
|
|
|
|
do_download = True
|
|
|
|
else:
|
|
|
|
download_dir = self.download_dir
|
|
|
|
do_download = self.is_download
|
|
|
|
unpack_url(
|
2015-03-20 00:08:42 +01:00
|
|
|
req_to_install.link, location, download_dir,
|
2015-03-19 06:23:26 +01:00
|
|
|
do_download, session=self.session,
|
|
|
|
)
|
|
|
|
except requests.HTTPError as exc:
|
|
|
|
logger.critical(
|
|
|
|
'Could not install requirement %s because '
|
|
|
|
'of error %s',
|
2015-03-19 00:20:40 +01:00
|
|
|
req_to_install,
|
2015-03-19 06:23:26 +01:00
|
|
|
exc,
|
|
|
|
)
|
|
|
|
raise InstallationError(
|
|
|
|
'Could not install requirement %s because '
|
|
|
|
'of HTTP error %s for URL %s' %
|
2015-03-20 00:08:42 +01:00
|
|
|
(req_to_install, exc, req_to_install.link)
|
2015-03-19 00:20:40 +01:00
|
|
|
)
|
2015-03-20 00:08:42 +01:00
|
|
|
if req_to_install.link.is_wheel:
|
|
|
|
abstract_dist = IsWheel(req_to_install, location)
|
2015-03-19 00:20:40 +01:00
|
|
|
req_to_install.source_dir = location
|
2015-03-19 05:01:55 +01:00
|
|
|
abstract_dist.prep_for_dist()
|
2015-03-19 00:20:40 +01:00
|
|
|
if self.is_download:
|
2015-03-19 05:01:55 +01:00
|
|
|
# Make a .zip of the source_dir we already created.
|
2015-03-20 00:08:42 +01:00
|
|
|
if req_to_install.link.scheme in vcs.all_schemes:
|
2015-03-19 00:20:40 +01:00
|
|
|
req_to_install.archive(self.download_dir)
|
|
|
|
# req_to_install.req is only avail after unpack for URL
|
|
|
|
# pkgs repeat check_if_exists to uninstall-on-upgrade
|
|
|
|
# (#14)
|
|
|
|
if not self.ignore_installed:
|
|
|
|
req_to_install.check_if_exists()
|
|
|
|
if req_to_install.satisfied_by:
|
|
|
|
if self.upgrade or self.ignore_installed:
|
2014-01-27 15:07:10 +01:00
|
|
|
# don't uninstall conflict if user install and
|
|
|
|
# conflict is not user install
|
2015-02-24 13:46:10 +01:00
|
|
|
if not (self.use_user_site and not
|
|
|
|
dist_in_usersite(
|
2015-03-19 00:20:40 +01:00
|
|
|
req_to_install.satisfied_by)):
|
2014-01-27 15:07:10 +01:00
|
|
|
req_to_install.conflicts_with = \
|
|
|
|
req_to_install.satisfied_by
|
2014-01-12 01:50:11 +01:00
|
|
|
req_to_install.satisfied_by = None
|
2015-03-19 00:20:40 +01:00
|
|
|
else:
|
|
|
|
logger.info(
|
|
|
|
'Requirement already satisfied (use '
|
|
|
|
'--upgrade to upgrade): %s',
|
2014-01-27 15:07:10 +01:00
|
|
|
req_to_install,
|
|
|
|
)
|
2015-03-19 00:20:40 +01:00
|
|
|
|
|
|
|
# ###################### #
|
|
|
|
# # parse dependencies # #
|
|
|
|
# ###################### #
|
2015-03-19 05:01:55 +01:00
|
|
|
dist = abstract_dist.dist(finder)
|
2014-12-07 23:51:46 +01:00
|
|
|
|
2015-03-19 00:20:40 +01:00
|
|
|
if not self.ignore_dependencies:
|
2015-03-20 00:41:31 +01:00
|
|
|
if (req_to_install.extras):
|
|
|
|
logger.debug(
|
|
|
|
"Installing extra requirements: %r",
|
|
|
|
','.join(req_to_install.extras),
|
|
|
|
)
|
2015-03-19 00:20:40 +01:00
|
|
|
missing_requested = sorted(
|
|
|
|
set(req_to_install.extras) - set(dist.extras)
|
|
|
|
)
|
|
|
|
for missing in missing_requested:
|
|
|
|
logger.warning(
|
|
|
|
'%s does not provide the extra \'%s\'',
|
|
|
|
dist, missing
|
2015-02-26 19:11:04 +01:00
|
|
|
)
|
2015-02-26 13:50:56 +01:00
|
|
|
|
2015-03-19 00:20:40 +01:00
|
|
|
available_requested = sorted(
|
|
|
|
set(dist.extras) & set(req_to_install.extras)
|
|
|
|
)
|
|
|
|
for subreq in dist.requires(available_requested):
|
|
|
|
if self.has_requirement(subreq.project_name):
|
|
|
|
# FIXME: check for conflict
|
|
|
|
continue
|
|
|
|
subreq = InstallRequirement(
|
|
|
|
str(subreq),
|
|
|
|
req_to_install,
|
|
|
|
isolated=self.isolated,
|
2015-02-26 19:11:04 +01:00
|
|
|
)
|
2015-03-19 00:20:40 +01:00
|
|
|
more_reqs.append(subreq)
|
|
|
|
self.add_requirement(subreq)
|
|
|
|
|
|
|
|
if not self.has_requirement(req_to_install.name):
|
|
|
|
# 'unnamed' requirements will get added here
|
|
|
|
self.add_requirement(req_to_install)
|
2014-12-07 23:51:46 +01:00
|
|
|
|
2015-03-19 00:20:40 +01:00
|
|
|
# cleanup tmp src
|
2015-03-19 03:33:23 +01:00
|
|
|
self.reqs_to_cleanup.append(req_to_install)
|
2014-01-12 01:50:11 +01:00
|
|
|
|
2015-03-20 07:40:51 +01:00
|
|
|
if not req_to_install.editable and not req_to_install.satisfied_by:
|
2015-03-19 00:20:40 +01:00
|
|
|
self.successfully_downloaded.append(req_to_install)
|
2014-05-08 18:12:34 +02:00
|
|
|
|
2015-03-19 00:20:40 +01:00
|
|
|
return more_reqs
|
2014-05-08 18:12:34 +02:00
|
|
|
|
|
|
|
def cleanup_files(self):
|
2014-01-12 01:50:11 +01:00
|
|
|
"""Clean up files, remove builds."""
|
2014-12-12 18:02:23 +01:00
|
|
|
logger.debug('Cleaning up...')
|
2014-08-31 01:52:28 +02:00
|
|
|
with indent_log():
|
|
|
|
for req in self.reqs_to_cleanup:
|
|
|
|
req.remove_temporary_source()
|
2014-01-12 01:50:11 +01:00
|
|
|
|
2014-08-31 01:52:28 +02:00
|
|
|
if self._pip_has_created_build_dir():
|
2014-12-17 14:02:04 +01:00
|
|
|
logger.debug('Removing temporary dir %s...', self.build_dir)
|
|
|
|
rmtree(self.build_dir)
|
2014-01-12 01:50:11 +01:00
|
|
|
|
|
|
|
def _pip_has_created_build_dir(self):
|
2014-01-27 15:07:10 +01:00
|
|
|
return (
|
2015-02-24 13:46:10 +01:00
|
|
|
self.build_dir == build_prefix and
|
|
|
|
os.path.exists(
|
2014-01-27 15:07:10 +01:00
|
|
|
os.path.join(self.build_dir, PIP_DELETE_MARKER_FILENAME)
|
|
|
|
)
|
|
|
|
)
|
2014-01-12 01:50:11 +01:00
|
|
|
|
|
|
|
def install(self, install_options, global_options=(), *args, **kwargs):
|
2014-01-27 15:07:10 +01:00
|
|
|
"""
|
|
|
|
Install everything in this set (after having downloaded and unpacked
|
|
|
|
the packages)
|
|
|
|
"""
|
2014-07-16 21:05:01 +02:00
|
|
|
to_install = [r for r in self.requirements.values()[::-1]
|
2014-01-12 01:50:11 +01:00
|
|
|
if not r.satisfied_by]
|
|
|
|
|
|
|
|
# DISTRIBUTE TO SETUPTOOLS UPGRADE HACK (1 of 3 parts)
|
|
|
|
# move the distribute-0.7.X wrapper to the end because it does not
|
|
|
|
# install a setuptools package. by moving it to the end, we ensure it's
|
|
|
|
# setuptools dependency is handled first, which will provide the
|
|
|
|
# setuptools package
|
|
|
|
# TODO: take this out later
|
|
|
|
distribute_req = pkg_resources.Requirement.parse("distribute>=0.7")
|
|
|
|
for req in to_install:
|
2015-02-24 13:46:10 +01:00
|
|
|
if (req.name == 'distribute' and
|
|
|
|
req.installed_version is not None and
|
|
|
|
req.installed_version in distribute_req):
|
2014-01-12 01:50:11 +01:00
|
|
|
to_install.remove(req)
|
|
|
|
to_install.append(req)
|
|
|
|
|
|
|
|
if to_install:
|
2014-08-31 01:52:28 +02:00
|
|
|
logger.info(
|
|
|
|
'Installing collected packages: %s',
|
|
|
|
', '.join([req.name for req in to_install]),
|
2014-01-27 15:07:10 +01:00
|
|
|
)
|
2014-08-31 01:52:28 +02:00
|
|
|
|
|
|
|
with indent_log():
|
2014-01-12 01:50:11 +01:00
|
|
|
for requirement in to_install:
|
|
|
|
|
|
|
|
# DISTRIBUTE TO SETUPTOOLS UPGRADE HACK (1 of 3 parts)
|
|
|
|
# when upgrading from distribute-0.6.X to the new merged
|
|
|
|
# setuptools in py2, we need to force setuptools to uninstall
|
|
|
|
# distribute. In py3, which is always using distribute, this
|
2014-01-27 15:07:10 +01:00
|
|
|
# conversion is already happening in distribute's
|
|
|
|
# pkg_resources. It's ok *not* to check if setuptools>=0.7
|
|
|
|
# because if someone were actually trying to ugrade from
|
|
|
|
# distribute to setuptools 0.6.X, then all this could do is
|
|
|
|
# actually help, although that upgade path was certainly never
|
|
|
|
# "supported"
|
2014-01-12 01:50:11 +01:00
|
|
|
# TODO: remove this later
|
|
|
|
if requirement.name == 'setuptools':
|
|
|
|
try:
|
|
|
|
# only uninstall distribute<0.7. For >=0.7, setuptools
|
|
|
|
# will also be present, and that's what we need to
|
|
|
|
# uninstall
|
2014-01-27 15:07:10 +01:00
|
|
|
distribute_requirement = \
|
|
|
|
pkg_resources.Requirement.parse("distribute<0.7")
|
|
|
|
existing_distribute = \
|
|
|
|
pkg_resources.get_distribution("distribute")
|
2014-01-12 01:50:11 +01:00
|
|
|
if existing_distribute in distribute_requirement:
|
|
|
|
requirement.conflicts_with = existing_distribute
|
|
|
|
except pkg_resources.DistributionNotFound:
|
|
|
|
# distribute wasn't installed, so nothing to do
|
|
|
|
pass
|
|
|
|
|
|
|
|
if requirement.conflicts_with:
|
2014-08-31 01:52:28 +02:00
|
|
|
logger.info(
|
|
|
|
'Found existing installation: %s',
|
|
|
|
requirement.conflicts_with,
|
|
|
|
)
|
|
|
|
with indent_log():
|
2014-01-12 01:50:11 +01:00
|
|
|
requirement.uninstall(auto_confirm=True)
|
|
|
|
try:
|
2014-01-27 15:07:10 +01:00
|
|
|
requirement.install(
|
|
|
|
install_options,
|
|
|
|
global_options,
|
|
|
|
*args,
|
|
|
|
**kwargs
|
|
|
|
)
|
2014-01-12 01:50:11 +01:00
|
|
|
except:
|
|
|
|
# if install did not succeed, rollback previous uninstall
|
2015-02-24 13:46:10 +01:00
|
|
|
if (requirement.conflicts_with and not
|
|
|
|
requirement.install_succeeded):
|
2014-01-12 01:50:11 +01:00
|
|
|
requirement.rollback_uninstall()
|
|
|
|
raise
|
|
|
|
else:
|
2015-02-24 13:46:10 +01:00
|
|
|
if (requirement.conflicts_with and
|
|
|
|
requirement.install_succeeded):
|
2014-01-12 01:50:11 +01:00
|
|
|
requirement.commit_uninstall()
|
|
|
|
requirement.remove_temporary_source()
|
2014-08-31 01:52:28 +02:00
|
|
|
|
2014-01-12 01:50:11 +01:00
|
|
|
self.successfully_installed = to_install
|