2014-08-31 01:52:28 +02:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2017-05-16 13:21:39 +02:00
|
|
|
import errno
|
2014-08-31 01:52:28 +02:00
|
|
|
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 shutil
|
2019-09-09 16:22:08 +02:00
|
|
|
import site
|
2018-03-26 13:01:27 +02:00
|
|
|
from optparse import SUPPRESS_HELP
|
2014-01-27 15:07:10 +01:00
|
|
|
|
2018-06-19 08:50:58 +02:00
|
|
|
from pip._vendor import pkg_resources
|
2019-09-05 02:55:11 +02:00
|
|
|
from pip._vendor.packaging.utils import canonicalize_name
|
2018-06-19 08:50:58 +02:00
|
|
|
|
2018-07-29 13:37:42 +02:00
|
|
|
from pip._internal.cache import WheelCache
|
2018-07-23 09:31:05 +02:00
|
|
|
from pip._internal.cli import cmdoptions
|
2019-06-22 08:30:34 +02:00
|
|
|
from pip._internal.cli.cmdoptions import make_target_python
|
2020-01-25 22:23:46 +01:00
|
|
|
from pip._internal.cli.req_command import RequirementCommand, with_cleanup
|
2019-08-11 13:13:44 +02:00
|
|
|
from pip._internal.cli.status_codes import ERROR, SUCCESS
|
2020-02-23 20:25:46 +01:00
|
|
|
from pip._internal.exceptions import CommandError, InstallationError
|
2019-07-18 22:39:34 +02:00
|
|
|
from pip._internal.locations import distutils_scheme
|
2017-10-28 19:25:32 +02:00
|
|
|
from pip._internal.operations.check import check_install_conflicts
|
2020-02-06 03:42:04 +01:00
|
|
|
from pip._internal.req import install_given_reqs
|
2019-10-30 18:07:13 +01:00
|
|
|
from pip._internal.req.req_tracker import get_requirement_tracker
|
2019-11-17 02:42:27 +01:00
|
|
|
from pip._internal.utils.deprecation import deprecated
|
|
|
|
from pip._internal.utils.distutils_args import parse_distutils_args
|
2019-12-15 13:55:48 +01:00
|
|
|
from pip._internal.utils.filesystem import test_writable_dir
|
2018-04-20 11:49:06 +02:00
|
|
|
from pip._internal.utils.misc import (
|
2019-07-22 06:45:27 +02:00
|
|
|
ensure_dir,
|
|
|
|
get_installed_version,
|
2018-04-20 11:49:06 +02:00
|
|
|
protect_pip_from_modification_on_windows,
|
2019-08-23 02:29:22 +02:00
|
|
|
write_output,
|
2018-04-20 11:49:06 +02:00
|
|
|
)
|
2017-08-31 17:48:18 +02:00
|
|
|
from pip._internal.utils.temp_dir import TempDirectory
|
2019-08-11 13:13:44 +02:00
|
|
|
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
|
2019-07-18 22:39:34 +02:00
|
|
|
from pip._internal.utils.virtualenv import virtualenv_no_global
|
2020-01-03 12:46:01 +01:00
|
|
|
from pip._internal.wheel_builder import build, should_build_for_install_command
|
2014-08-31 01:52:28 +02:00
|
|
|
|
2019-08-11 13:13:44 +02:00
|
|
|
if MYPY_CHECK_RUNNING:
|
2020-05-22 11:31:58 +02:00
|
|
|
from optparse import Values
|
2020-05-30 19:38:08 +02:00
|
|
|
from typing import Iterable, List, Optional
|
2019-08-11 13:13:44 +02:00
|
|
|
|
2019-09-05 02:55:11 +02:00
|
|
|
from pip._internal.models.format_control import FormatControl
|
2019-08-11 13:13:44 +02:00
|
|
|
from pip._internal.req.req_install import InstallRequirement
|
2019-12-29 18:10:42 +01:00
|
|
|
from pip._internal.wheel_builder import BinaryAllowedPredicate
|
2019-08-11 13:13:44 +02:00
|
|
|
|
|
|
|
|
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
|
|
|
|
2019-09-05 02:55:11 +02:00
|
|
|
def get_check_binary_allowed(format_control):
|
|
|
|
# type: (FormatControl) -> BinaryAllowedPredicate
|
|
|
|
def check_binary_allowed(req):
|
|
|
|
# type: (InstallRequirement) -> bool
|
2019-09-25 06:58:53 +02:00
|
|
|
if req.use_pep517:
|
|
|
|
return True
|
2019-09-05 02:55:11 +02:00
|
|
|
canonical_name = canonicalize_name(req.name)
|
|
|
|
allowed_formats = format_control.get_allowed_formats(canonical_name)
|
2019-09-25 06:58:53 +02:00
|
|
|
return "binary" in allowed_formats
|
2019-09-05 02:55:11 +02:00
|
|
|
|
|
|
|
return check_binary_allowed
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
2019-10-04 14:46:50 +02:00
|
|
|
pip also supports installing from "requirements files", which provide
|
2013-02-16 19:00:29 +01:00
|
|
|
an easy way to specify a whole environment to be installed.
|
|
|
|
"""
|
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> ..."""
|
|
|
|
|
2020-05-22 11:31:58 +02:00
|
|
|
def add_options(self):
|
|
|
|
# type: () -> None
|
|
|
|
self.cmd_opts.add_option(cmdoptions.requirements())
|
|
|
|
self.cmd_opts.add_option(cmdoptions.constraints())
|
|
|
|
self.cmd_opts.add_option(cmdoptions.no_deps())
|
|
|
|
self.cmd_opts.add_option(cmdoptions.pre())
|
2012-12-10 02:14:39 +01:00
|
|
|
|
2020-05-22 11:31:58 +02:00
|
|
|
self.cmd_opts.add_option(cmdoptions.editable())
|
|
|
|
self.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
|
|
|
)
|
2020-05-22 11:31:58 +02:00
|
|
|
cmdoptions.add_target_python_options(self.cmd_opts)
|
2018-07-24 17:09:32 +02:00
|
|
|
|
2020-05-22 11:31:58 +02:00
|
|
|
self.cmd_opts.add_option(
|
2016-11-02 13:40:38 +01:00
|
|
|
'--user',
|
|
|
|
dest='use_user_site',
|
|
|
|
action='store_true',
|
|
|
|
help="Install to the Python user install directory for your "
|
2017-02-23 15:02:24 +01:00
|
|
|
"platform. Typically ~/.local/, or %APPDATA%\\Python on "
|
2016-11-02 13:40:38 +01:00
|
|
|
"Windows. (See the Python documentation for site.USER_BASE "
|
|
|
|
"for full details.)")
|
2020-05-22 11:31:58 +02:00
|
|
|
self.cmd_opts.add_option(
|
2018-03-25 19:22:18 +02:00
|
|
|
'--no-user',
|
|
|
|
dest='use_user_site',
|
|
|
|
action='store_false',
|
2018-03-26 13:01:27 +02:00
|
|
|
help=SUPPRESS_HELP)
|
2020-05-22 11:31:58 +02:00
|
|
|
self.cmd_opts.add_option(
|
2016-11-02 13:40:38 +01:00
|
|
|
'--root',
|
|
|
|
dest='root_path',
|
|
|
|
metavar='dir',
|
|
|
|
default=None,
|
|
|
|
help="Install everything relative to this alternate root "
|
|
|
|
"directory.")
|
2020-05-22 11:31:58 +02:00
|
|
|
self.cmd_opts.add_option(
|
2016-11-02 13:40:38 +01:00
|
|
|
'--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
|
|
|
|
2020-05-22 11:31:58 +02:00
|
|
|
self.cmd_opts.add_option(cmdoptions.build_dir())
|
2012-12-10 02:14:39 +01:00
|
|
|
|
2020-05-22 11:31:58 +02:00
|
|
|
self.cmd_opts.add_option(cmdoptions.src())
|
2009-11-20 19:20:52 +01:00
|
|
|
|
2020-05-22 11:31:58 +02:00
|
|
|
self.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.'
|
|
|
|
)
|
|
|
|
|
2020-05-22 11:31:58 +02:00
|
|
|
self.cmd_opts.add_option(
|
2016-09-18 22:48:01 +02:00
|
|
|
'--upgrade-strategy',
|
|
|
|
dest='upgrade_strategy',
|
2017-05-19 13:39:48 +02:00
|
|
|
default='only-if-needed',
|
2016-09-18 22:48:01 +02:00
|
|
|
choices=['only-if-needed', 'eager'],
|
2016-12-07 17:00:03 +01:00
|
|
|
help='Determines how dependency upgrading should be handled '
|
2018-04-01 08:34:59 +02:00
|
|
|
'[default: %default]. '
|
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
|
|
|
|
2020-05-22 11:31:58 +02:00
|
|
|
self.cmd_opts.add_option(
|
2011-08-24 20:07:16 +02:00
|
|
|
'--force-reinstall',
|
|
|
|
dest='force_reinstall',
|
|
|
|
action='store_true',
|
2017-10-24 00:03:20 +02:00
|
|
|
help='Reinstall all packages even if they are already '
|
|
|
|
'up-to-date.')
|
2012-12-10 02:14:39 +01:00
|
|
|
|
2020-05-22 11:31:58 +02:00
|
|
|
self.cmd_opts.add_option(
|
2009-11-20 19:20:52 +01:00
|
|
|
'-I', '--ignore-installed',
|
|
|
|
dest='ignore_installed',
|
|
|
|
action='store_true',
|
2019-07-27 01:46:08 +02:00
|
|
|
help='Ignore the installed packages, overwriting them. '
|
|
|
|
'This can break your system if the existing package '
|
|
|
|
'is of a different version or was installed '
|
|
|
|
'with a different package manager!'
|
2019-07-27 02:19:11 +02:00
|
|
|
)
|
2012-12-10 02:14:39 +01:00
|
|
|
|
2020-05-22 11:31:58 +02:00
|
|
|
self.cmd_opts.add_option(cmdoptions.ignore_requires_python())
|
|
|
|
self.cmd_opts.add_option(cmdoptions.no_build_isolation())
|
|
|
|
self.cmd_opts.add_option(cmdoptions.use_pep517())
|
|
|
|
self.cmd_opts.add_option(cmdoptions.no_use_pep517())
|
2012-12-10 02:14:39 +01:00
|
|
|
|
2020-05-22 11:31:58 +02:00
|
|
|
self.cmd_opts.add_option(cmdoptions.install_options())
|
|
|
|
self.cmd_opts.add_option(cmdoptions.global_options())
|
2010-05-30 14:39:11 +02:00
|
|
|
|
2020-05-22 11:31:58 +02:00
|
|
|
self.cmd_opts.add_option(
|
2013-11-22 03:59:31 +01:00
|
|
|
"--compile",
|
|
|
|
action="store_true",
|
|
|
|
dest="compile",
|
|
|
|
default=True,
|
2017-04-06 19:27:46 +02:00
|
|
|
help="Compile Python source files to bytecode",
|
2013-11-22 03:59:31 +01:00
|
|
|
)
|
|
|
|
|
2020-05-22 11:31:58 +02:00
|
|
|
self.cmd_opts.add_option(
|
2013-11-22 03:59:31 +01:00
|
|
|
"--no-compile",
|
|
|
|
action="store_false",
|
|
|
|
dest="compile",
|
2017-04-06 19:27:46 +02:00
|
|
|
help="Do not compile Python source files to bytecode",
|
2013-11-22 03:59:31 +01:00
|
|
|
)
|
|
|
|
|
2020-05-22 11:31:58 +02:00
|
|
|
self.cmd_opts.add_option(
|
2017-10-02 18:54:37 +02:00
|
|
|
"--no-warn-script-location",
|
|
|
|
action="store_false",
|
|
|
|
dest="warn_script_location",
|
|
|
|
default=True,
|
|
|
|
help="Do not warn when installing scripts outside PATH",
|
|
|
|
)
|
2020-05-22 11:31:58 +02:00
|
|
|
self.cmd_opts.add_option(
|
2017-10-28 19:25:32 +02:00
|
|
|
"--no-warn-conflicts",
|
|
|
|
action="store_false",
|
|
|
|
dest="warn_about_conflicts",
|
|
|
|
default=True,
|
|
|
|
help="Do not warn about broken dependencies",
|
|
|
|
)
|
2017-10-02 18:54:37 +02:00
|
|
|
|
2020-05-22 11:31:58 +02:00
|
|
|
self.cmd_opts.add_option(cmdoptions.no_binary())
|
|
|
|
self.cmd_opts.add_option(cmdoptions.only_binary())
|
|
|
|
self.cmd_opts.add_option(cmdoptions.prefer_binary())
|
|
|
|
self.cmd_opts.add_option(cmdoptions.require_hashes())
|
|
|
|
self.cmd_opts.add_option(cmdoptions.progress_bar())
|
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)
|
2020-05-22 11:31:58 +02:00
|
|
|
self.parser.insert_option_group(0, self.cmd_opts)
|
2012-10-01 10:27:35 +02:00
|
|
|
|
2020-01-25 22:23:46 +01:00
|
|
|
@with_cleanup
|
2009-11-20 19:20:52 +01:00
|
|
|
def run(self, options, args):
|
2020-05-30 19:38:08 +02:00
|
|
|
# type: (Values, List[str]) -> int
|
2020-02-27 07:52:05 +01:00
|
|
|
if options.use_user_site and options.target_dir is not None:
|
|
|
|
raise CommandError("Can not combine '--user' and '--target'")
|
|
|
|
|
2015-04-22 01:53:05 +02:00
|
|
|
cmdoptions.check_install_build_global(options)
|
2017-06-27 18:37:38 +02:00
|
|
|
upgrade_strategy = "to-satisfy-only"
|
|
|
|
if options.upgrade:
|
|
|
|
upgrade_strategy = options.upgrade_strategy
|
|
|
|
|
2018-07-24 17:09:32 +02:00
|
|
|
cmdoptions.check_dist_restriction(options, check_target=True)
|
|
|
|
|
2009-11-20 19:20:52 +01:00
|
|
|
install_options = options.install_options or []
|
2019-10-09 18:34:16 +02:00
|
|
|
|
|
|
|
options.use_user_site = decide_user_install(
|
|
|
|
options.use_user_site,
|
|
|
|
prefix_path=options.prefix_path,
|
|
|
|
target_dir=options.target_dir,
|
|
|
|
root_path=options.root_path,
|
|
|
|
isolated_mode=options.isolated_mode,
|
|
|
|
)
|
|
|
|
|
2019-09-20 03:54:39 +02:00
|
|
|
target_temp_dir = None # type: Optional[TempDirectory]
|
|
|
|
target_temp_dir_path = None # type: Optional[str]
|
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
|
|
|
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."
|
|
|
|
)
|
2017-06-01 14:54:29 +02:00
|
|
|
|
|
|
|
# Create a target directory for using with the target option
|
2019-09-20 03:54:39 +02:00
|
|
|
target_temp_dir = TempDirectory(kind="target")
|
|
|
|
target_temp_dir_path = target_temp_dir.path
|
2020-06-25 10:14:59 +02:00
|
|
|
self.enter_context(target_temp_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
|
|
|
|
2019-09-03 00:48:15 +02:00
|
|
|
session = self.get_default_session(options)
|
|
|
|
|
|
|
|
target_python = make_target_python(options)
|
|
|
|
finder = self._build_package_finder(
|
|
|
|
options=options,
|
|
|
|
session=session,
|
|
|
|
target_python=target_python,
|
|
|
|
ignore_requires_python=options.ignore_requires_python,
|
|
|
|
)
|
|
|
|
build_delete = (not (options.no_clean or options.build_dir))
|
|
|
|
wheel_cache = WheelCache(options.cache_dir, options.format_control)
|
|
|
|
|
2020-02-23 20:37:01 +01:00
|
|
|
req_tracker = self.enter_context(get_requirement_tracker())
|
|
|
|
|
2020-02-23 20:52:16 +01:00
|
|
|
directory = TempDirectory(
|
|
|
|
options.build_dir,
|
|
|
|
delete=build_delete,
|
|
|
|
kind="install",
|
|
|
|
globally_managed=True,
|
|
|
|
)
|
|
|
|
|
2020-02-23 20:53:57 +01:00
|
|
|
try:
|
2020-04-16 09:05:12 +02:00
|
|
|
reqs = self.get_requirements(args, options, finder, session)
|
2019-11-17 02:42:27 +01:00
|
|
|
|
2020-02-23 20:53:57 +01:00
|
|
|
warn_deprecated_install_options(
|
|
|
|
reqs, options.install_options
|
|
|
|
)
|
2019-11-17 02:42:27 +01:00
|
|
|
|
2020-02-23 20:53:57 +01:00
|
|
|
preparer = self.make_requirement_preparer(
|
|
|
|
temp_build_dir=directory,
|
|
|
|
options=options,
|
|
|
|
req_tracker=req_tracker,
|
|
|
|
session=session,
|
|
|
|
finder=finder,
|
|
|
|
use_user_site=options.use_user_site,
|
|
|
|
)
|
|
|
|
resolver = self.make_resolver(
|
|
|
|
preparer=preparer,
|
|
|
|
finder=finder,
|
|
|
|
options=options,
|
|
|
|
wheel_cache=wheel_cache,
|
|
|
|
use_user_site=options.use_user_site,
|
|
|
|
ignore_installed=options.ignore_installed,
|
|
|
|
ignore_requires_python=options.ignore_requires_python,
|
|
|
|
force_reinstall=options.force_reinstall,
|
|
|
|
upgrade_strategy=upgrade_strategy,
|
|
|
|
use_pep517=options.use_pep517,
|
|
|
|
)
|
2019-11-05 02:45:37 +01:00
|
|
|
|
2020-02-23 20:53:57 +01:00
|
|
|
self.trace_basic_info(finder)
|
2019-11-05 02:45:37 +01:00
|
|
|
|
2020-02-23 20:53:57 +01:00
|
|
|
requirement_set = resolver.resolve(
|
|
|
|
reqs, check_supported_wheels=not options.target_dir
|
|
|
|
)
|
2014-11-12 01:19:32 +01:00
|
|
|
|
2020-02-23 20:53:57 +01:00
|
|
|
try:
|
|
|
|
pip_req = requirement_set.get_requirement("pip")
|
|
|
|
except KeyError:
|
2020-05-30 19:38:08 +02:00
|
|
|
modifying_pip = False
|
2020-02-23 20:53:57 +01:00
|
|
|
else:
|
|
|
|
# If we're not replacing an already installed pip,
|
|
|
|
# we're not modifying it.
|
|
|
|
modifying_pip = pip_req.satisfied_by is None
|
|
|
|
protect_pip_from_modification_on_windows(
|
|
|
|
modifying_pip=modifying_pip
|
|
|
|
)
|
|
|
|
|
|
|
|
check_binary_allowed = get_check_binary_allowed(
|
|
|
|
finder.format_control
|
|
|
|
)
|
2017-05-31 20:08:20 +02:00
|
|
|
|
2020-02-23 20:53:57 +01:00
|
|
|
reqs_to_build = [
|
|
|
|
r for r in requirement_set.requirements.values()
|
|
|
|
if should_build_for_install_command(
|
|
|
|
r, check_binary_allowed
|
2019-09-22 21:31:45 +02:00
|
|
|
)
|
2020-02-23 20:53:57 +01:00
|
|
|
]
|
2019-12-29 18:07:49 +01:00
|
|
|
|
2020-02-23 20:53:57 +01:00
|
|
|
_, build_failures = build(
|
|
|
|
reqs_to_build,
|
|
|
|
wheel_cache=wheel_cache,
|
|
|
|
build_options=[],
|
|
|
|
global_options=[],
|
|
|
|
)
|
2018-04-20 11:49:06 +02:00
|
|
|
|
2020-02-23 20:53:57 +01:00
|
|
|
# If we're using PEP 517, we cannot do a direct install
|
|
|
|
# so we fail here.
|
|
|
|
# We don't care about failures building legacy
|
|
|
|
# requirements, as we'll fall through to a direct
|
|
|
|
# install for those.
|
|
|
|
pep517_build_failures = [
|
|
|
|
r for r in build_failures if r.use_pep517
|
|
|
|
]
|
|
|
|
if pep517_build_failures:
|
|
|
|
raise InstallationError(
|
|
|
|
"Could not build wheels for {} which use"
|
|
|
|
" PEP 517 and cannot be installed directly".format(
|
2020-05-30 19:38:08 +02:00
|
|
|
", ".join(r.name # type: ignore
|
|
|
|
for r in pep517_build_failures)))
|
2020-02-23 20:53:57 +01:00
|
|
|
|
|
|
|
to_install = resolver.get_installation_order(
|
|
|
|
requirement_set
|
|
|
|
)
|
2018-08-27 17:38:56 +02:00
|
|
|
|
2020-02-23 20:53:57 +01:00
|
|
|
# Consistency Checking of the package set we're installing.
|
|
|
|
should_warn_about_conflicts = (
|
|
|
|
not options.ignore_dependencies and
|
|
|
|
options.warn_about_conflicts
|
|
|
|
)
|
|
|
|
if should_warn_about_conflicts:
|
|
|
|
self._warn_about_conflicts(to_install)
|
|
|
|
|
|
|
|
# Don't warn about script install locations if
|
|
|
|
# --target has been specified
|
|
|
|
warn_script_location = options.warn_script_location
|
|
|
|
if options.target_dir:
|
|
|
|
warn_script_location = False
|
|
|
|
|
|
|
|
installed = install_given_reqs(
|
|
|
|
to_install,
|
|
|
|
install_options,
|
|
|
|
global_options,
|
|
|
|
root=options.root_path,
|
|
|
|
home=target_temp_dir_path,
|
|
|
|
prefix=options.prefix_path,
|
|
|
|
warn_script_location=warn_script_location,
|
|
|
|
use_user_site=options.use_user_site,
|
2020-05-21 14:15:10 +02:00
|
|
|
pycompile=options.compile,
|
2020-02-23 20:53:57 +01:00
|
|
|
)
|
2017-10-28 19:25:32 +02:00
|
|
|
|
2020-02-23 20:53:57 +01:00
|
|
|
lib_locations = get_lib_location_guesses(
|
|
|
|
user=options.use_user_site,
|
|
|
|
home=target_temp_dir_path,
|
|
|
|
root=options.root_path,
|
|
|
|
prefix=options.prefix_path,
|
|
|
|
isolated=options.isolated_mode,
|
|
|
|
)
|
|
|
|
working_set = pkg_resources.WorkingSet(lib_locations)
|
2017-03-20 02:26:36 +01:00
|
|
|
|
2020-02-23 20:53:57 +01:00
|
|
|
installed.sort(key=operator.attrgetter('name'))
|
|
|
|
items = []
|
|
|
|
for result in installed:
|
|
|
|
item = result.name
|
|
|
|
try:
|
|
|
|
installed_version = get_installed_version(
|
|
|
|
result.name, working_set=working_set
|
2017-05-19 13:04:23 +02:00
|
|
|
)
|
2020-02-23 20:53:57 +01:00
|
|
|
if installed_version:
|
|
|
|
item += '-' + installed_version
|
|
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
items.append(item)
|
|
|
|
installed_desc = ' '.join(items)
|
|
|
|
if installed_desc:
|
|
|
|
write_output(
|
|
|
|
'Successfully installed %s', installed_desc,
|
2019-09-03 00:48:15 +02:00
|
|
|
)
|
2020-02-23 20:53:57 +01:00
|
|
|
except EnvironmentError as error:
|
|
|
|
show_traceback = (self.verbosity >= 1)
|
2020-05-31 00:20:14 +02:00
|
|
|
|
2020-02-23 20:53:57 +01:00
|
|
|
message = create_env_error_message(
|
|
|
|
error, show_traceback, options.use_user_site,
|
|
|
|
)
|
|
|
|
logger.error(message, exc_info=show_traceback)
|
2019-09-03 00:48:15 +02:00
|
|
|
|
2020-02-23 20:53:57 +01:00
|
|
|
return ERROR
|
2014-11-12 01:19:32 +01:00
|
|
|
|
2020-07-07 11:36:27 +02:00
|
|
|
if options.target_dir:
|
|
|
|
assert target_temp_dir
|
2017-05-17 10:38:42 +02:00
|
|
|
self._handle_target_dir(
|
2017-06-01 14:54:29 +02:00
|
|
|
options.target_dir, target_temp_dir, options.upgrade
|
2017-05-17 10:38:42 +02:00
|
|
|
)
|
2019-08-11 13:13:44 +02:00
|
|
|
|
|
|
|
return SUCCESS
|
2016-04-11 17:12:36 +02:00
|
|
|
|
2017-06-01 14:54:29 +02:00
|
|
|
def _handle_target_dir(self, target_dir, target_temp_dir, upgrade):
|
2020-05-31 00:20:14 +02:00
|
|
|
# type: (str, TempDirectory, bool) -> None
|
2017-05-17 10:38:42 +02:00
|
|
|
ensure_dir(target_dir)
|
|
|
|
|
|
|
|
# Checking both purelib and platlib directories for installed
|
|
|
|
# packages to be moved to target directory
|
|
|
|
lib_dir_list = []
|
|
|
|
|
2020-06-25 10:14:59 +02:00
|
|
|
# Checking both purelib and platlib directories for installed
|
|
|
|
# packages to be moved to target directory
|
|
|
|
scheme = distutils_scheme('', home=target_temp_dir.path)
|
|
|
|
purelib_dir = scheme['purelib']
|
|
|
|
platlib_dir = scheme['platlib']
|
|
|
|
data_dir = scheme['data']
|
|
|
|
|
|
|
|
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)
|
|
|
|
if os.path.exists(data_dir):
|
|
|
|
lib_dir_list.append(data_dir)
|
|
|
|
|
|
|
|
for lib_dir in lib_dir_list:
|
|
|
|
for item in os.listdir(lib_dir):
|
|
|
|
if lib_dir == data_dir:
|
|
|
|
ddir = os.path.join(data_dir, item)
|
|
|
|
if any(s.startswith(ddir) for s in lib_dir_list[:-1]):
|
|
|
|
continue
|
|
|
|
target_item_dir = os.path.join(target_dir, item)
|
|
|
|
if os.path.exists(target_item_dir):
|
|
|
|
if not 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
|
|
|
|
)
|
2017-05-17 10:38:42 +02:00
|
|
|
|
2017-10-28 19:25:32 +02:00
|
|
|
def _warn_about_conflicts(self, to_install):
|
2020-05-30 19:38:08 +02:00
|
|
|
# type: (List[InstallRequirement]) -> None
|
2018-10-02 12:07:48 +02:00
|
|
|
try:
|
|
|
|
package_set, _dep_info = check_install_conflicts(to_install)
|
2018-10-02 14:29:58 +02:00
|
|
|
except Exception:
|
2018-10-02 12:07:48 +02:00
|
|
|
logger.error("Error checking for conflicts.", exc_info=True)
|
|
|
|
return
|
2017-10-28 19:25:32 +02:00
|
|
|
missing, conflicting = _dep_info
|
|
|
|
|
|
|
|
# NOTE: There is some duplication here from pip check
|
|
|
|
for project_name in missing:
|
|
|
|
version = package_set[project_name][0]
|
|
|
|
for dependency in missing[project_name]:
|
|
|
|
logger.critical(
|
|
|
|
"%s %s requires %s, which is not installed.",
|
|
|
|
project_name, version, dependency[1],
|
|
|
|
)
|
|
|
|
|
|
|
|
for project_name in conflicting:
|
|
|
|
version = package_set[project_name][0]
|
|
|
|
for dep_name, dep_version, req in conflicting[project_name]:
|
|
|
|
logger.critical(
|
|
|
|
"%s %s has requirement %s, but you'll have %s %s which is "
|
|
|
|
"incompatible.",
|
|
|
|
project_name, version, req, dep_name, dep_version,
|
|
|
|
)
|
|
|
|
|
2016-04-11 17:12:36 +02:00
|
|
|
|
2020-05-30 19:38:08 +02:00
|
|
|
def get_lib_location_guesses(
|
|
|
|
user=False, # type: bool
|
|
|
|
home=None, # type: Optional[str]
|
|
|
|
root=None, # type: Optional[str]
|
|
|
|
isolated=False, # type: bool
|
|
|
|
prefix=None # type: Optional[str]
|
|
|
|
):
|
|
|
|
# type:(...) -> List[str]
|
|
|
|
scheme = distutils_scheme('', user=user, home=home, root=root,
|
|
|
|
isolated=isolated, prefix=prefix)
|
2016-04-11 17:12:36 +02:00
|
|
|
return [scheme['purelib'], scheme['platlib']]
|
2018-04-15 16:25:31 +02:00
|
|
|
|
|
|
|
|
2020-05-30 19:38:08 +02:00
|
|
|
def site_packages_writable(root, isolated):
|
|
|
|
# type: (Optional[str], bool) -> bool
|
2019-10-09 09:43:58 +02:00
|
|
|
return all(
|
2020-05-30 19:38:08 +02:00
|
|
|
test_writable_dir(d) for d in set(
|
|
|
|
get_lib_location_guesses(root=root, isolated=isolated))
|
2019-10-09 09:43:58 +02:00
|
|
|
)
|
2019-09-09 16:22:08 +02:00
|
|
|
|
|
|
|
|
2019-10-09 18:34:16 +02:00
|
|
|
def decide_user_install(
|
2019-10-19 12:23:27 +02:00
|
|
|
use_user_site, # type: Optional[bool]
|
2019-10-20 22:48:18 +02:00
|
|
|
prefix_path=None, # type: Optional[str]
|
|
|
|
target_dir=None, # type: Optional[str]
|
|
|
|
root_path=None, # type: Optional[str]
|
|
|
|
isolated_mode=False, # type: bool
|
2019-10-09 18:34:16 +02:00
|
|
|
):
|
2019-10-19 12:23:27 +02:00
|
|
|
# type: (...) -> bool
|
2019-10-09 18:34:16 +02:00
|
|
|
"""Determine whether to do a user install based on the input options.
|
|
|
|
|
2019-10-19 12:23:27 +02:00
|
|
|
If use_user_site is False, no additional checks are done.
|
|
|
|
If use_user_site is True, it is checked for compatibility with other
|
|
|
|
options.
|
|
|
|
If use_user_site is None, the default behaviour depends on the environment,
|
|
|
|
which is provided by the other arguments.
|
2019-10-09 18:34:16 +02:00
|
|
|
"""
|
2019-10-24 12:59:22 +02:00
|
|
|
# In some cases (config from tox), use_user_site can be set to an integer
|
2019-10-25 09:26:11 +02:00
|
|
|
# rather than a bool, which 'use_user_site is False' wouldn't catch.
|
|
|
|
if (use_user_site is not None) and (not use_user_site):
|
2019-10-20 22:28:56 +02:00
|
|
|
logger.debug("Non-user install by explicit request")
|
2019-10-19 12:23:27 +02:00
|
|
|
return False
|
|
|
|
|
2019-10-25 09:26:11 +02:00
|
|
|
if use_user_site:
|
2019-10-09 18:34:16 +02:00
|
|
|
if prefix_path:
|
|
|
|
raise CommandError(
|
|
|
|
"Can not combine '--user' and '--prefix' as they imply "
|
|
|
|
"different installation locations"
|
|
|
|
)
|
|
|
|
if virtualenv_no_global():
|
|
|
|
raise InstallationError(
|
|
|
|
"Can not perform a '--user' install. User site-packages "
|
|
|
|
"are not visible in this virtualenv."
|
|
|
|
)
|
2019-10-20 22:28:56 +02:00
|
|
|
logger.debug("User install by explicit request")
|
2019-10-19 12:23:27 +02:00
|
|
|
return True
|
|
|
|
|
|
|
|
# If we are here, user installs have not been explicitly requested/avoided
|
|
|
|
assert use_user_site is None
|
2019-10-09 18:34:16 +02:00
|
|
|
|
2019-10-19 12:23:27 +02:00
|
|
|
# user install incompatible with --prefix/--target
|
2019-10-09 18:34:16 +02:00
|
|
|
if prefix_path or target_dir:
|
2019-10-20 22:28:56 +02:00
|
|
|
logger.debug("Non-user install due to --prefix or --target option")
|
2019-10-19 12:23:27 +02:00
|
|
|
return False
|
|
|
|
|
|
|
|
# If user installs are not enabled, choose a non-user install
|
|
|
|
if not site.ENABLE_USER_SITE:
|
2019-10-20 22:28:56 +02:00
|
|
|
logger.debug("Non-user install because user site-packages disabled")
|
2019-10-19 12:23:27 +02:00
|
|
|
return False
|
2019-10-09 18:34:16 +02:00
|
|
|
|
2019-10-21 14:52:50 +02:00
|
|
|
# If we have permission for a non-user install, do that,
|
|
|
|
# otherwise do a user install.
|
2019-10-20 22:28:56 +02:00
|
|
|
if site_packages_writable(root=root_path, isolated=isolated_mode):
|
|
|
|
logger.debug("Non-user install because site-packages writeable")
|
|
|
|
return False
|
|
|
|
|
|
|
|
logger.info("Defaulting to user installation because normal site-packages "
|
|
|
|
"is not writeable")
|
|
|
|
return True
|
2019-10-09 18:34:16 +02:00
|
|
|
|
|
|
|
|
2020-02-06 03:39:10 +01:00
|
|
|
def warn_deprecated_install_options(requirements, options):
|
|
|
|
# type: (List[InstallRequirement], Optional[List[str]]) -> None
|
2019-11-17 02:42:27 +01:00
|
|
|
"""If any location-changing --install-option arguments were passed for
|
|
|
|
requirements or on the command-line, then show a deprecation warning.
|
|
|
|
"""
|
|
|
|
def format_options(option_names):
|
|
|
|
# type: (Iterable[str]) -> List[str]
|
|
|
|
return ["--{}".format(name.replace("_", "-")) for name in option_names]
|
|
|
|
|
|
|
|
offenders = []
|
|
|
|
|
|
|
|
for requirement in requirements:
|
2020-02-06 17:05:11 +01:00
|
|
|
install_options = requirement.install_options
|
2019-11-17 02:42:27 +01:00
|
|
|
location_options = parse_distutils_args(install_options)
|
|
|
|
if location_options:
|
|
|
|
offenders.append(
|
|
|
|
"{!r} from {}".format(
|
|
|
|
format_options(location_options.keys()), requirement
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
if options:
|
|
|
|
location_options = parse_distutils_args(options)
|
|
|
|
if location_options:
|
|
|
|
offenders.append(
|
|
|
|
"{!r} from command line".format(
|
|
|
|
format_options(location_options.keys())
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
if not offenders:
|
|
|
|
return
|
|
|
|
|
|
|
|
deprecated(
|
|
|
|
reason=(
|
|
|
|
"Location-changing options found in --install-option: {}. "
|
|
|
|
"This configuration may cause unexpected behavior and is "
|
|
|
|
"unsupported.".format(
|
|
|
|
"; ".join(offenders)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
replacement=(
|
|
|
|
"using pip-level options like --user, --prefix, --root, and "
|
|
|
|
"--target"
|
|
|
|
),
|
|
|
|
gone_in="20.2",
|
|
|
|
issue=7309,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2018-04-15 16:25:31 +02:00
|
|
|
def create_env_error_message(error, show_traceback, using_user_site):
|
2020-05-30 19:38:08 +02:00
|
|
|
# type: (EnvironmentError, bool, bool) -> str
|
2018-04-15 16:25:31 +02:00
|
|
|
"""Format an error message for an EnvironmentError
|
|
|
|
|
|
|
|
It may occur anytime during the execution of the install command.
|
|
|
|
"""
|
|
|
|
parts = []
|
|
|
|
|
|
|
|
# Mention the error if we are not going to show a traceback
|
|
|
|
parts.append("Could not install packages due to an EnvironmentError")
|
|
|
|
if not show_traceback:
|
|
|
|
parts.append(": ")
|
|
|
|
parts.append(str(error))
|
|
|
|
else:
|
|
|
|
parts.append(".")
|
|
|
|
|
|
|
|
# Spilt the error indication from a helper message (if any)
|
|
|
|
parts[-1] += "\n"
|
|
|
|
|
|
|
|
# Suggest useful actions to the user:
|
|
|
|
# (1) using user site-packages or (2) verifying the permissions
|
|
|
|
if error.errno == errno.EACCES:
|
|
|
|
user_option_part = "Consider using the `--user` option"
|
|
|
|
permissions_part = "Check the permissions"
|
|
|
|
|
|
|
|
if not using_user_site:
|
|
|
|
parts.extend([
|
|
|
|
user_option_part, " or ",
|
|
|
|
permissions_part.lower(),
|
|
|
|
])
|
|
|
|
else:
|
|
|
|
parts.append(permissions_part)
|
|
|
|
parts.append(".\n")
|
|
|
|
|
|
|
|
return "".join(parts).strip() + "\n"
|