Path: blob/master/venv/Lib/site-packages/pip/_internal/commands/wheel.py
811 views
# -*- coding: utf-8 -*-12# The following comment should be removed at some point in the future.3# mypy: disallow-untyped-defs=False45from __future__ import absolute_import67import logging8import os9import shutil1011from pip._internal.cache import WheelCache12from pip._internal.cli import cmdoptions13from pip._internal.cli.req_command import RequirementCommand, with_cleanup14from pip._internal.exceptions import CommandError15from pip._internal.req.req_tracker import get_requirement_tracker16from pip._internal.utils.misc import ensure_dir, normalize_path17from pip._internal.utils.temp_dir import TempDirectory18from pip._internal.utils.typing import MYPY_CHECK_RUNNING19from pip._internal.wheel_builder import build, should_build_for_wheel_command2021if MYPY_CHECK_RUNNING:22from optparse import Values23from typing import Any, List242526logger = logging.getLogger(__name__)272829class WheelCommand(RequirementCommand):30"""31Build Wheel archives for your requirements and dependencies.3233Wheel is a built-package format, and offers the advantage of not34recompiling your software during every install. For more details, see the35wheel docs: https://wheel.readthedocs.io/en/latest/3637Requirements: setuptools>=0.8, and wheel.3839'pip wheel' uses the bdist_wheel setuptools extension from the wheel40package to build individual wheels.4142"""4344usage = """45%prog [options] <requirement specifier> ...46%prog [options] -r <requirements file> ...47%prog [options] [-e] <vcs project url> ...48%prog [options] [-e] <local project path> ...49%prog [options] <archive url/path> ..."""5051def __init__(self, *args, **kw):52super(WheelCommand, self).__init__(*args, **kw)5354cmd_opts = self.cmd_opts5556cmd_opts.add_option(57'-w', '--wheel-dir',58dest='wheel_dir',59metavar='dir',60default=os.curdir,61help=("Build wheels into <dir>, where the default is the "62"current working directory."),63)64cmd_opts.add_option(cmdoptions.no_binary())65cmd_opts.add_option(cmdoptions.only_binary())66cmd_opts.add_option(cmdoptions.prefer_binary())67cmd_opts.add_option(68'--build-option',69dest='build_options',70metavar='options',71action='append',72help="Extra arguments to be supplied to 'setup.py bdist_wheel'.",73)74cmd_opts.add_option(cmdoptions.no_build_isolation())75cmd_opts.add_option(cmdoptions.use_pep517())76cmd_opts.add_option(cmdoptions.no_use_pep517())77cmd_opts.add_option(cmdoptions.constraints())78cmd_opts.add_option(cmdoptions.editable())79cmd_opts.add_option(cmdoptions.requirements())80cmd_opts.add_option(cmdoptions.src())81cmd_opts.add_option(cmdoptions.ignore_requires_python())82cmd_opts.add_option(cmdoptions.no_deps())83cmd_opts.add_option(cmdoptions.build_dir())84cmd_opts.add_option(cmdoptions.progress_bar())8586cmd_opts.add_option(87'--global-option',88dest='global_options',89action='append',90metavar='options',91help="Extra global options to be supplied to the setup.py "92"call before the 'bdist_wheel' command.")9394cmd_opts.add_option(95'--pre',96action='store_true',97default=False,98help=("Include pre-release and development versions. By default, "99"pip only finds stable versions."),100)101102cmd_opts.add_option(cmdoptions.require_hashes())103104index_opts = cmdoptions.make_option_group(105cmdoptions.index_group,106self.parser,107)108109self.parser.insert_option_group(0, index_opts)110self.parser.insert_option_group(0, cmd_opts)111112@with_cleanup113def run(self, options, args):114# type: (Values, List[Any]) -> None115cmdoptions.check_install_build_global(options)116117session = self.get_default_session(options)118119finder = self._build_package_finder(options, session)120build_delete = (not (options.no_clean or options.build_dir))121wheel_cache = WheelCache(options.cache_dir, options.format_control)122123options.wheel_dir = normalize_path(options.wheel_dir)124ensure_dir(options.wheel_dir)125126req_tracker = self.enter_context(get_requirement_tracker())127128directory = TempDirectory(129options.build_dir,130delete=build_delete,131kind="wheel",132globally_managed=True,133)134135reqs = self.get_requirements(args, options, finder, session)136137preparer = self.make_requirement_preparer(138temp_build_dir=directory,139options=options,140req_tracker=req_tracker,141session=session,142finder=finder,143wheel_download_dir=options.wheel_dir,144use_user_site=False,145)146147resolver = self.make_resolver(148preparer=preparer,149finder=finder,150options=options,151wheel_cache=wheel_cache,152ignore_requires_python=options.ignore_requires_python,153use_pep517=options.use_pep517,154)155156self.trace_basic_info(finder)157158requirement_set = resolver.resolve(159reqs, check_supported_wheels=True160)161162reqs_to_build = [163r for r in requirement_set.requirements.values()164if should_build_for_wheel_command(r)165]166167# build wheels168build_successes, build_failures = build(169reqs_to_build,170wheel_cache=wheel_cache,171build_options=options.build_options or [],172global_options=options.global_options or [],173)174for req in build_successes:175assert req.link and req.link.is_wheel176assert req.local_file_path177# copy from cache to target directory178try:179shutil.copy(req.local_file_path, options.wheel_dir)180except OSError as e:181logger.warning(182"Building wheel for %s failed: %s",183req.name, e,184)185build_failures.append(req)186if len(build_failures) != 0:187raise CommandError(188"Failed to build one or more wheels"189)190191192