2014-08-31 01:52:28 +02:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
import logging
|
2014-12-18 08:54:58 +01:00
|
|
|
import operator
|
2011-05-04 09:44:02 +02:00
|
|
|
import os
|
2012-02-03 04:23:07 +01:00
|
|
|
import tempfile
|
|
|
|
import shutil
|
2014-08-31 01:52:28 +02:00
|
|
|
import warnings
|
2015-04-01 03:39:45 +02:00
|
|
|
try:
|
|
|
|
import wheel
|
|
|
|
except ImportError:
|
|
|
|
wheel = None
|
2014-01-27 15:07:10 +01:00
|
|
|
|
2015-04-07 14:28:10 +02:00
|
|
|
from pip.req import RequirementSet
|
|
|
|
from pip.basecommand import RequirementCommand
|
2015-04-01 03:39:45 +02:00
|
|
|
from pip.locations import virtualenv_no_global, distutils_scheme
|
2014-01-27 15:07:10 +01:00
|
|
|
from pip.exceptions import (
|
|
|
|
InstallationError, CommandError, PreviousBuildDirError,
|
|
|
|
)
|
2013-02-03 07:40:30 +01:00
|
|
|
from pip import cmdoptions
|
2016-04-11 17:12:36 +02:00
|
|
|
from pip.utils import ensure_dir, get_installed_version
|
2014-11-12 01:19:32 +01:00
|
|
|
from pip.utils.build import BuildDirectory
|
2015-09-03 14:15:03 +02:00
|
|
|
from pip.utils.deprecation import RemovedInPip10Warning
|
2015-07-02 22:10:47 +02:00
|
|
|
from pip.utils.filesystem import check_path_owner
|
2015-04-20 06:43:02 +02:00
|
|
|
from pip.wheel import WheelCache, WheelBuilder
|
2014-08-31 01:52:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
2009-11-20 19:20:52 +01:00
|
|
|
|
2010-06-03 04:25:26 +02:00
|
|
|
|
2015-04-07 14:28:10 +02:00
|
|
|
class InstallCommand(RequirementCommand):
|
2013-02-16 19:00:29 +01:00
|
|
|
"""
|
|
|
|
Install packages from:
|
|
|
|
|
|
|
|
- PyPI (and other indexes) using requirement specifiers.
|
|
|
|
- VCS project urls.
|
|
|
|
- Local project directories.
|
|
|
|
- Local or remote source archives.
|
|
|
|
|
|
|
|
pip also supports installing from "requirements files", which provide
|
|
|
|
an easy way to specify a whole environment to be installed.
|
|
|
|
"""
|
2009-11-20 19:20:52 +01:00
|
|
|
name = 'install'
|
2013-01-18 22:25:15 +01:00
|
|
|
|
|
|
|
usage = """
|
2014-05-12 16:49:06 +02:00
|
|
|
%prog [options] <requirement specifier> [package-index-options] ...
|
|
|
|
%prog [options] -r <requirements file> [package-index-options] ...
|
2013-01-18 22:25:15 +01:00
|
|
|
%prog [options] [-e] <vcs project url> ...
|
|
|
|
%prog [options] [-e] <local project path> ...
|
|
|
|
%prog [options] <archive url/path> ..."""
|
|
|
|
|
|
|
|
summary = 'Install packages.'
|
2009-11-20 19:20:52 +01:00
|
|
|
|
2012-11-10 05:15:45 +01:00
|
|
|
def __init__(self, *args, **kw):
|
|
|
|
super(InstallCommand, self).__init__(*args, **kw)
|
2012-12-10 02:14:39 +01:00
|
|
|
|
2012-12-10 02:22:28 +01:00
|
|
|
cmd_opts = self.cmd_opts
|
2012-12-10 02:14:39 +01:00
|
|
|
|
2015-04-17 04:37:47 +02:00
|
|
|
cmd_opts.add_option(cmdoptions.requirements())
|
2015-06-02 05:39:10 +02:00
|
|
|
cmd_opts.add_option(cmdoptions.constraints())
|
2016-10-31 22:45:08 +01:00
|
|
|
cmd_opts.add_option(cmdoptions.no_deps())
|
|
|
|
cmd_opts.add_option(cmdoptions.pre())
|
2012-12-10 02:14:39 +01:00
|
|
|
|
2015-04-17 04:37:47 +02:00
|
|
|
cmd_opts.add_option(cmdoptions.editable())
|
2012-12-10 02:14:39 +01:00
|
|
|
cmd_opts.add_option(
|
2012-02-03 12:22:51 +01:00
|
|
|
'-t', '--target',
|
2012-02-03 04:23:07 +01:00
|
|
|
dest='target_dir',
|
2013-01-18 22:25:15 +01:00
|
|
|
metavar='dir',
|
2012-02-03 04:23:07 +01:00
|
|
|
default=None,
|
2014-08-31 02:15:32 +02:00
|
|
|
help='Install packages into <dir>. '
|
2014-08-31 03:25:03 +02:00
|
|
|
'By default this will not replace existing files/folders in '
|
|
|
|
'<dir>. Use --upgrade to replace existing packages in <dir> '
|
|
|
|
'with new versions.'
|
2014-08-31 02:15:32 +02:00
|
|
|
)
|
2016-11-02 13:40:38 +01:00
|
|
|
cmd_opts.add_option(
|
|
|
|
'--user',
|
|
|
|
dest='use_user_site',
|
|
|
|
action='store_true',
|
|
|
|
help="Install to the Python user install directory for your "
|
|
|
|
"platform. Typically ~/.local/, or %APPDATA%\Python on "
|
|
|
|
"Windows. (See the Python documentation for site.USER_BASE "
|
|
|
|
"for full details.)")
|
|
|
|
cmd_opts.add_option(
|
|
|
|
'--root',
|
|
|
|
dest='root_path',
|
|
|
|
metavar='dir',
|
|
|
|
default=None,
|
|
|
|
help="Install everything relative to this alternate root "
|
|
|
|
"directory.")
|
|
|
|
cmd_opts.add_option(
|
|
|
|
'--prefix',
|
|
|
|
dest='prefix_path',
|
|
|
|
metavar='dir',
|
|
|
|
default=None,
|
|
|
|
help="Installation prefix where lib, bin and other top-level "
|
|
|
|
"folders are placed")
|
2012-12-10 02:14:39 +01:00
|
|
|
|
|
|
|
cmd_opts.add_option(
|
2009-11-20 19:20:52 +01:00
|
|
|
'-d', '--download', '--download-dir', '--download-directory',
|
|
|
|
dest='download_dir',
|
2013-01-18 22:25:15 +01:00
|
|
|
metavar='dir',
|
2009-11-20 19:20:52 +01:00
|
|
|
default=None,
|
2014-01-27 15:07:10 +01:00
|
|
|
help=("Download packages into <dir> instead of installing them, "
|
|
|
|
"regardless of what's already installed."),
|
|
|
|
)
|
2016-11-02 13:40:38 +01:00
|
|
|
cmd_opts.add_option(cmdoptions.build_dir())
|
2012-12-10 02:14:39 +01:00
|
|
|
|
2015-04-17 04:37:47 +02:00
|
|
|
cmd_opts.add_option(cmdoptions.src())
|
2009-11-20 19:20:52 +01:00
|
|
|
|
2012-12-10 02:14:39 +01:00
|
|
|
cmd_opts.add_option(
|
2009-11-20 19:20:52 +01:00
|
|
|
'-U', '--upgrade',
|
|
|
|
dest='upgrade',
|
|
|
|
action='store_true',
|
2014-10-17 15:50:44 +02:00
|
|
|
help='Upgrade all specified packages to the newest available '
|
2016-09-18 22:48:01 +02:00
|
|
|
'version. The handling of dependencies depends on the '
|
|
|
|
'upgrade-strategy used.'
|
|
|
|
)
|
|
|
|
|
|
|
|
cmd_opts.add_option(
|
|
|
|
'--upgrade-strategy',
|
|
|
|
dest='upgrade_strategy',
|
|
|
|
default='eager',
|
|
|
|
choices=['only-if-needed', 'eager'],
|
2016-12-07 17:00:03 +01:00
|
|
|
help='Determines how dependency upgrading should be handled '
|
|
|
|
'(default: %(default)s). '
|
2016-09-18 22:48:01 +02:00
|
|
|
'"eager" - dependencies are upgraded regardless of '
|
|
|
|
'whether the currently installed version satisfies the '
|
|
|
|
'requirements of the upgraded package(s). '
|
|
|
|
'"only-if-needed" - are upgraded only when they do not '
|
|
|
|
'satisfy the requirements of the upgraded package(s).'
|
2014-01-27 15:07:10 +01:00
|
|
|
)
|
2012-12-10 02:14:39 +01:00
|
|
|
|
|
|
|
cmd_opts.add_option(
|
2011-08-24 20:07:16 +02:00
|
|
|
'--force-reinstall',
|
|
|
|
dest='force_reinstall',
|
|
|
|
action='store_true',
|
|
|
|
help='When upgrading, reinstall all packages even if they are '
|
|
|
|
'already up-to-date.')
|
2012-12-10 02:14:39 +01:00
|
|
|
|
|
|
|
cmd_opts.add_option(
|
2009-11-20 19:20:52 +01:00
|
|
|
'-I', '--ignore-installed',
|
|
|
|
dest='ignore_installed',
|
|
|
|
action='store_true',
|
2013-01-18 22:25:15 +01:00
|
|
|
help='Ignore the installed packages (reinstalling instead).')
|
2012-12-10 02:14:39 +01:00
|
|
|
|
2016-07-17 11:29:02 +02:00
|
|
|
cmd_opts.add_option(cmdoptions.ignore_requires_python())
|
2012-12-10 02:14:39 +01:00
|
|
|
|
2015-04-17 04:37:47 +02:00
|
|
|
cmd_opts.add_option(cmdoptions.install_options())
|
|
|
|
cmd_opts.add_option(cmdoptions.global_options())
|
2010-05-30 14:39:11 +02:00
|
|
|
|
2012-12-10 02:14:39 +01:00
|
|
|
cmd_opts.add_option(
|
2012-05-20 05:18:36 +02:00
|
|
|
'--egg',
|
|
|
|
dest='as_egg',
|
|
|
|
action='store_true',
|
2014-01-27 15:07:10 +01:00
|
|
|
help="Install packages as eggs, not 'flat', like pip normally "
|
|
|
|
"does. This option is not about installing *from* eggs. "
|
|
|
|
"(WARNING: Because this option overrides pip's normal install"
|
|
|
|
" logic, requirements files may not behave as expected.)")
|
2012-05-20 05:18:36 +02:00
|
|
|
|
2013-11-22 03:59:31 +01:00
|
|
|
cmd_opts.add_option(
|
|
|
|
"--compile",
|
|
|
|
action="store_true",
|
|
|
|
dest="compile",
|
|
|
|
default=True,
|
|
|
|
help="Compile py files to pyc",
|
|
|
|
)
|
|
|
|
|
|
|
|
cmd_opts.add_option(
|
|
|
|
"--no-compile",
|
|
|
|
action="store_false",
|
|
|
|
dest="compile",
|
|
|
|
help="Do not compile py files to pyc",
|
|
|
|
)
|
|
|
|
|
2015-04-17 04:37:47 +02:00
|
|
|
cmd_opts.add_option(cmdoptions.use_wheel())
|
|
|
|
cmd_opts.add_option(cmdoptions.no_use_wheel())
|
2015-04-17 05:03:34 +02:00
|
|
|
cmd_opts.add_option(cmdoptions.no_binary())
|
|
|
|
cmd_opts.add_option(cmdoptions.only_binary())
|
2015-04-17 04:37:47 +02:00
|
|
|
cmd_opts.add_option(cmdoptions.no_clean())
|
2015-10-07 23:33:57 +02:00
|
|
|
cmd_opts.add_option(cmdoptions.require_hashes())
|
Add checks against requirements-file-dwelling hashes for most kinds of packages. Close #1175.
* Add --require-hashes option. This is handy in deployment scripts to force application authors to hash their requirements. It is also a convenient way to get pip to show computed hashes for a virgin, unhashed requirements file. Eventually, additions to `pip freeze` should fill a superset of this use case.
* In --require-hashes mode, at least one hash is required to match for each requirement.
* Option-based requirements (--sha256=...) turn on --require-hashes mode implicitly.
* Internet-derived URL-based hashes are "necessary but not sufficient": they do not satisfy --require-hashes mode when they match, but they are still used to guard against transmission errors.
* Other URL-based requirements (#md5=...) are treated just like flag-based ones, except they don't turn on --require-hashes.
* Complain informatively, with the most devastating errors first so you don't chase your tail all day only to run up against a brick wall at the end. This also means we don't complain that a hash is missing, only for the user to find, after fixing it, that we have no idea how to even compute a hash for that type of requirement.
* Complain about unpinned requirements when hash-checking mode is on, lest they cause the user surprise later.
* Complain about missing hashes.
* Complain about requirement types we don't know how to hash (like VCS ones and local dirs).
* Have InstallRequirement keep its original Link around (original_link) so we can differentiate between URL hashes from requirements files and ones downloaded from the (untrustworthy) internet.
* Remove test_download_hashes, which is obsolete. Similar coverage is provided in test_utils.TestHashes and the various hash cases in test_req.py.
2015-09-09 19:01:53 +02:00
|
|
|
|
2014-01-27 15:07:10 +01:00
|
|
|
index_opts = cmdoptions.make_option_group(
|
|
|
|
cmdoptions.index_group,
|
|
|
|
self.parser,
|
|
|
|
)
|
2012-12-16 05:26:21 +01:00
|
|
|
|
|
|
|
self.parser.insert_option_group(0, index_opts)
|
2012-12-12 14:06:05 +01:00
|
|
|
self.parser.insert_option_group(0, cmd_opts)
|
2012-10-01 10:27:35 +02:00
|
|
|
|
2009-11-20 19:20:52 +01:00
|
|
|
def run(self, options, args):
|
2015-04-17 05:03:34 +02:00
|
|
|
cmdoptions.resolve_wheel_no_use_binary(options)
|
2015-04-22 01:53:05 +02:00
|
|
|
cmdoptions.check_install_build_global(options)
|
2014-01-10 05:28:28 +01:00
|
|
|
|
2016-09-07 22:43:58 +02:00
|
|
|
if options.as_egg:
|
|
|
|
warnings.warn(
|
|
|
|
"--egg has been deprecated and will be removed in the future. "
|
|
|
|
"This flag is mutually exclusive with large parts of pip, and "
|
|
|
|
"actually using it invalidates pip's ability to manage the "
|
|
|
|
"installation process.",
|
|
|
|
RemovedInPip10Warning,
|
|
|
|
)
|
|
|
|
|
2015-09-03 05:08:11 +02:00
|
|
|
if options.allow_external:
|
|
|
|
warnings.warn(
|
|
|
|
"--allow-external has been deprecated and will be removed in "
|
|
|
|
"the future. Due to changes in the repository protocol, it no "
|
|
|
|
"longer has any effect.",
|
|
|
|
RemovedInPip10Warning,
|
|
|
|
)
|
|
|
|
|
|
|
|
if options.allow_all_external:
|
|
|
|
warnings.warn(
|
|
|
|
"--allow-all-external has been deprecated and will be removed "
|
|
|
|
"in the future. Due to changes in the repository protocol, it "
|
|
|
|
"no longer has any effect.",
|
|
|
|
RemovedInPip10Warning,
|
|
|
|
)
|
|
|
|
|
|
|
|
if options.allow_unverified:
|
|
|
|
warnings.warn(
|
|
|
|
"--allow-unverified has been deprecated and will be removed "
|
|
|
|
"in the future. Due to changes in the repository protocol, it "
|
|
|
|
"no longer has any effect.",
|
|
|
|
RemovedInPip10Warning,
|
|
|
|
)
|
|
|
|
|
2015-02-04 20:30:37 +01:00
|
|
|
if options.download_dir:
|
2015-07-29 22:25:13 +02:00
|
|
|
warnings.warn(
|
|
|
|
"pip install --download has been deprecated and will be "
|
|
|
|
"removed in the future. Pip now has a download command that "
|
|
|
|
"should be used instead.",
|
|
|
|
RemovedInPip10Warning,
|
|
|
|
)
|
2015-02-04 20:30:37 +01:00
|
|
|
options.ignore_installed = True
|
|
|
|
|
2014-11-12 01:19:32 +01:00
|
|
|
if options.build_dir:
|
|
|
|
options.build_dir = os.path.abspath(options.build_dir)
|
|
|
|
|
2010-04-15 13:16:11 +02:00
|
|
|
options.src_dir = os.path.abspath(options.src_dir)
|
2009-11-20 19:20:52 +01:00
|
|
|
install_options = options.install_options or []
|
2010-08-18 23:59:33 +02:00
|
|
|
if options.use_user_site:
|
2015-11-19 16:32:02 +01:00
|
|
|
if options.prefix_path:
|
|
|
|
raise CommandError(
|
|
|
|
"Can not combine '--user' and '--prefix' as they imply "
|
|
|
|
"different installation locations"
|
|
|
|
)
|
2012-06-06 05:01:35 +02:00
|
|
|
if virtualenv_no_global():
|
2014-01-27 15:07:10 +01:00
|
|
|
raise InstallationError(
|
|
|
|
"Can not perform a '--user' install. User site-packages "
|
|
|
|
"are not visible in this virtualenv."
|
|
|
|
)
|
2010-08-18 23:59:33 +02:00
|
|
|
install_options.append('--user')
|
2015-06-26 04:23:50 +02:00
|
|
|
install_options.append('--prefix=')
|
2012-11-15 01:53:22 +01:00
|
|
|
|
|
|
|
temp_target_dir = None
|
2012-02-03 04:23:07 +01:00
|
|
|
if options.target_dir:
|
2012-02-07 08:13:02 +01:00
|
|
|
options.ignore_installed = True
|
2012-02-03 04:23:07 +01:00
|
|
|
temp_target_dir = tempfile.mkdtemp()
|
|
|
|
options.target_dir = os.path.abspath(options.target_dir)
|
2015-02-24 13:46:10 +01:00
|
|
|
if (os.path.exists(options.target_dir) and not
|
|
|
|
os.path.isdir(options.target_dir)):
|
2014-01-27 15:07:10 +01:00
|
|
|
raise CommandError(
|
|
|
|
"Target path exists but is not a directory, will not "
|
|
|
|
"continue."
|
|
|
|
)
|
2012-02-03 04:23:07 +01:00
|
|
|
install_options.append('--home=' + temp_target_dir)
|
2012-11-15 01:53:22 +01:00
|
|
|
|
2010-05-30 14:39:11 +02:00
|
|
|
global_options = options.global_options or []
|
2010-05-28 01:27:13 +02:00
|
|
|
|
2014-06-17 22:24:42 +02:00
|
|
|
with self._build_session(options) as session:
|
|
|
|
|
2015-07-29 22:25:13 +02:00
|
|
|
finder = self._build_package_finder(options, session)
|
2014-11-12 01:19:32 +01:00
|
|
|
build_delete = (not (options.no_clean or options.build_dir))
|
2015-04-17 05:03:34 +02:00
|
|
|
wheel_cache = WheelCache(options.cache_dir, options.format_control)
|
2015-07-02 22:10:47 +02:00
|
|
|
if options.cache_dir and not check_path_owner(options.cache_dir):
|
|
|
|
logger.warning(
|
|
|
|
"The directory '%s' or its parent directory is not owned "
|
|
|
|
"by the current user and caching wheels has been "
|
|
|
|
"disabled. check the permissions and owner of that "
|
|
|
|
"directory. If executing pip with sudo, you may want "
|
|
|
|
"sudo's -H flag.",
|
|
|
|
options.cache_dir,
|
|
|
|
)
|
|
|
|
options.cache_dir = None
|
|
|
|
|
2014-11-12 01:19:32 +01:00
|
|
|
with BuildDirectory(options.build_dir,
|
|
|
|
delete=build_delete) as build_dir:
|
|
|
|
requirement_set = RequirementSet(
|
|
|
|
build_dir=build_dir,
|
|
|
|
src_dir=options.src_dir,
|
|
|
|
download_dir=options.download_dir,
|
|
|
|
upgrade=options.upgrade,
|
2016-09-18 22:48:01 +02:00
|
|
|
upgrade_strategy=options.upgrade_strategy,
|
2014-11-12 01:19:32 +01:00
|
|
|
as_egg=options.as_egg,
|
|
|
|
ignore_installed=options.ignore_installed,
|
|
|
|
ignore_dependencies=options.ignore_dependencies,
|
2016-07-17 11:29:02 +02:00
|
|
|
ignore_requires_python=options.ignore_requires_python,
|
2014-11-12 01:19:32 +01:00
|
|
|
force_reinstall=options.force_reinstall,
|
|
|
|
use_user_site=options.use_user_site,
|
|
|
|
target_dir=temp_target_dir,
|
|
|
|
session=session,
|
|
|
|
pycompile=options.compile,
|
2014-12-11 15:44:53 +01:00
|
|
|
isolated=options.isolated_mode,
|
2015-04-20 06:43:02 +02:00
|
|
|
wheel_cache=wheel_cache,
|
Add checks against requirements-file-dwelling hashes for most kinds of packages. Close #1175.
* Add --require-hashes option. This is handy in deployment scripts to force application authors to hash their requirements. It is also a convenient way to get pip to show computed hashes for a virgin, unhashed requirements file. Eventually, additions to `pip freeze` should fill a superset of this use case.
* In --require-hashes mode, at least one hash is required to match for each requirement.
* Option-based requirements (--sha256=...) turn on --require-hashes mode implicitly.
* Internet-derived URL-based hashes are "necessary but not sufficient": they do not satisfy --require-hashes mode when they match, but they are still used to guard against transmission errors.
* Other URL-based requirements (#md5=...) are treated just like flag-based ones, except they don't turn on --require-hashes.
* Complain informatively, with the most devastating errors first so you don't chase your tail all day only to run up against a brick wall at the end. This also means we don't complain that a hash is missing, only for the user to find, after fixing it, that we have no idea how to even compute a hash for that type of requirement.
* Complain about unpinned requirements when hash-checking mode is on, lest they cause the user surprise later.
* Complain about missing hashes.
* Complain about requirement types we don't know how to hash (like VCS ones and local dirs).
* Have InstallRequirement keep its original Link around (original_link) so we can differentiate between URL hashes from requirements files and ones downloaded from the (untrustworthy) internet.
* Remove test_download_hashes, which is obsolete. Similar coverage is provided in test_utils.TestHashes and the various hash cases in test_req.py.
2015-09-09 19:01:53 +02:00
|
|
|
require_hashes=options.require_hashes,
|
2014-02-24 22:52:23 +01:00
|
|
|
)
|
2014-11-12 01:19:32 +01:00
|
|
|
|
2015-04-07 14:28:10 +02:00
|
|
|
self.populate_requirement_set(
|
|
|
|
requirement_set, args, options, finder, session, self.name,
|
2015-04-20 06:43:02 +02:00
|
|
|
wheel_cache
|
2015-04-07 14:28:10 +02:00
|
|
|
)
|
2014-11-12 01:19:32 +01:00
|
|
|
|
|
|
|
try:
|
2015-05-14 07:41:37 +02:00
|
|
|
if (options.download_dir or not wheel or not
|
|
|
|
options.cache_dir):
|
2015-04-01 03:39:45 +02:00
|
|
|
# on -d don't do complex things like building
|
|
|
|
# wheels, and don't try to build wheels when wheel is
|
|
|
|
# not installed.
|
|
|
|
requirement_set.prepare_files(finder)
|
|
|
|
else:
|
|
|
|
# build wheels before install.
|
|
|
|
wb = WheelBuilder(
|
|
|
|
requirement_set,
|
|
|
|
finder,
|
|
|
|
build_options=[],
|
|
|
|
global_options=[],
|
|
|
|
)
|
|
|
|
# Ignore the result: a failed wheel will be
|
|
|
|
# installed from the sdist/vcs whatever.
|
|
|
|
wb.build(autobuilding=True)
|
2014-11-12 01:19:32 +01:00
|
|
|
|
2015-04-07 07:39:14 +02:00
|
|
|
if not options.download_dir:
|
2014-11-12 01:19:32 +01:00
|
|
|
requirement_set.install(
|
|
|
|
install_options,
|
|
|
|
global_options,
|
|
|
|
root=options.root_path,
|
2015-11-16 17:39:44 +01:00
|
|
|
prefix=options.prefix_path,
|
2014-11-12 01:19:32 +01:00
|
|
|
)
|
2016-04-11 17:12:36 +02:00
|
|
|
|
|
|
|
possible_lib_locations = get_lib_location_guesses(
|
|
|
|
user=options.use_user_site,
|
|
|
|
home=temp_target_dir,
|
2016-05-30 11:33:25 +02:00
|
|
|
root=options.root_path,
|
2016-04-12 10:29:32 +02:00
|
|
|
prefix=options.prefix_path,
|
|
|
|
isolated=options.isolated_mode,
|
2016-04-11 17:12:36 +02:00
|
|
|
)
|
2014-12-18 08:54:58 +01:00
|
|
|
reqs = sorted(
|
|
|
|
requirement_set.successfully_installed,
|
|
|
|
key=operator.attrgetter('name'))
|
|
|
|
items = []
|
|
|
|
for req in reqs:
|
|
|
|
item = req.name
|
|
|
|
try:
|
2016-04-11 17:12:36 +02:00
|
|
|
installed_version = get_installed_version(
|
|
|
|
req.name, possible_lib_locations
|
|
|
|
)
|
|
|
|
if installed_version:
|
|
|
|
item += '-' + installed_version
|
2014-12-18 08:54:58 +01:00
|
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
items.append(item)
|
|
|
|
installed = ' '.join(items)
|
2014-11-12 01:19:32 +01:00
|
|
|
if installed:
|
|
|
|
logger.info('Successfully installed %s', installed)
|
|
|
|
else:
|
|
|
|
downloaded = ' '.join([
|
|
|
|
req.name
|
|
|
|
for req in requirement_set.successfully_downloaded
|
|
|
|
])
|
|
|
|
if downloaded:
|
|
|
|
logger.info(
|
|
|
|
'Successfully downloaded %s', downloaded
|
2014-08-31 03:25:03 +02:00
|
|
|
)
|
2014-11-12 01:19:32 +01:00
|
|
|
except PreviousBuildDirError:
|
|
|
|
options.no_clean = True
|
|
|
|
raise
|
|
|
|
finally:
|
|
|
|
# Clean up
|
2015-04-07 07:39:14 +02:00
|
|
|
if not options.no_clean:
|
2014-11-12 01:19:32 +01:00
|
|
|
requirement_set.cleanup_files()
|
|
|
|
|
|
|
|
if options.target_dir:
|
2015-03-31 03:40:30 +02:00
|
|
|
ensure_dir(options.target_dir)
|
2014-11-12 01:19:32 +01:00
|
|
|
|
2016-05-26 12:39:44 +02:00
|
|
|
# Checking both purelib and platlib directories for installed
|
|
|
|
# packages to be moved to target directory
|
|
|
|
lib_dir_list = []
|
|
|
|
|
|
|
|
purelib_dir = distutils_scheme('', home=temp_target_dir)['purelib']
|
|
|
|
platlib_dir = distutils_scheme('', home=temp_target_dir)['platlib']
|
|
|
|
|
|
|
|
if os.path.exists(purelib_dir):
|
|
|
|
lib_dir_list.append(purelib_dir)
|
|
|
|
if os.path.exists(platlib_dir) and platlib_dir != purelib_dir:
|
|
|
|
lib_dir_list.append(platlib_dir)
|
|
|
|
|
|
|
|
for lib_dir in lib_dir_list:
|
|
|
|
for item in os.listdir(lib_dir):
|
|
|
|
target_item_dir = os.path.join(options.target_dir, item)
|
|
|
|
if os.path.exists(target_item_dir):
|
|
|
|
if not options.upgrade:
|
|
|
|
logger.warning(
|
|
|
|
'Target directory %s already exists. Specify '
|
|
|
|
'--upgrade to force replacement.',
|
|
|
|
target_item_dir
|
|
|
|
)
|
|
|
|
continue
|
|
|
|
if os.path.islink(target_item_dir):
|
|
|
|
logger.warning(
|
|
|
|
'Target directory %s already exists and is '
|
|
|
|
'a link. Pip will not automatically replace '
|
|
|
|
'links, please remove if replacement is '
|
|
|
|
'desired.',
|
|
|
|
target_item_dir
|
|
|
|
)
|
|
|
|
continue
|
|
|
|
if os.path.isdir(target_item_dir):
|
|
|
|
shutil.rmtree(target_item_dir)
|
|
|
|
else:
|
|
|
|
os.remove(target_item_dir)
|
|
|
|
|
|
|
|
shutil.move(
|
|
|
|
os.path.join(lib_dir, item),
|
|
|
|
target_item_dir
|
|
|
|
)
|
2014-11-12 01:19:32 +01:00
|
|
|
shutil.rmtree(temp_target_dir)
|
|
|
|
return requirement_set
|
2016-04-11 17:12:36 +02:00
|
|
|
|
|
|
|
|
2016-04-12 10:29:32 +02:00
|
|
|
def get_lib_location_guesses(*args, **kwargs):
|
|
|
|
scheme = distutils_scheme('', *args, **kwargs)
|
2016-04-11 17:12:36 +02:00
|
|
|
return [scheme['purelib'], scheme['platlib']]
|