Mercurial > repos > guerler > hhblits
comparison lib/python3.8/site-packages/pip/_internal/commands/wheel.py @ 1:64071f2a4cf0 draft default tip
Deleted selected files
| author | guerler |
|---|---|
| date | Mon, 27 Jul 2020 03:55:49 -0400 |
| parents | 9e54283cc701 |
| children |
comparison
equal
deleted
inserted
replaced
| 0:9e54283cc701 | 1:64071f2a4cf0 |
|---|---|
| 1 # -*- coding: utf-8 -*- | |
| 2 | |
| 3 # The following comment should be removed at some point in the future. | |
| 4 # mypy: disallow-untyped-defs=False | |
| 5 | |
| 6 from __future__ import absolute_import | |
| 7 | |
| 8 import logging | |
| 9 import os | |
| 10 import shutil | |
| 11 | |
| 12 from pip._internal.cache import WheelCache | |
| 13 from pip._internal.cli import cmdoptions | |
| 14 from pip._internal.cli.req_command import RequirementCommand | |
| 15 from pip._internal.exceptions import CommandError, PreviousBuildDirError | |
| 16 from pip._internal.req import RequirementSet | |
| 17 from pip._internal.req.req_tracker import get_requirement_tracker | |
| 18 from pip._internal.utils.misc import ensure_dir, normalize_path | |
| 19 from pip._internal.utils.temp_dir import TempDirectory | |
| 20 from pip._internal.utils.typing import MYPY_CHECK_RUNNING | |
| 21 from pip._internal.wheel_builder import build, should_build_for_wheel_command | |
| 22 | |
| 23 if MYPY_CHECK_RUNNING: | |
| 24 from optparse import Values | |
| 25 from typing import Any, List | |
| 26 | |
| 27 | |
| 28 logger = logging.getLogger(__name__) | |
| 29 | |
| 30 | |
| 31 class WheelCommand(RequirementCommand): | |
| 32 """ | |
| 33 Build Wheel archives for your requirements and dependencies. | |
| 34 | |
| 35 Wheel is a built-package format, and offers the advantage of not | |
| 36 recompiling your software during every install. For more details, see the | |
| 37 wheel docs: https://wheel.readthedocs.io/en/latest/ | |
| 38 | |
| 39 Requirements: setuptools>=0.8, and wheel. | |
| 40 | |
| 41 'pip wheel' uses the bdist_wheel setuptools extension from the wheel | |
| 42 package to build individual wheels. | |
| 43 | |
| 44 """ | |
| 45 | |
| 46 usage = """ | |
| 47 %prog [options] <requirement specifier> ... | |
| 48 %prog [options] -r <requirements file> ... | |
| 49 %prog [options] [-e] <vcs project url> ... | |
| 50 %prog [options] [-e] <local project path> ... | |
| 51 %prog [options] <archive url/path> ...""" | |
| 52 | |
| 53 def __init__(self, *args, **kw): | |
| 54 super(WheelCommand, self).__init__(*args, **kw) | |
| 55 | |
| 56 cmd_opts = self.cmd_opts | |
| 57 | |
| 58 cmd_opts.add_option( | |
| 59 '-w', '--wheel-dir', | |
| 60 dest='wheel_dir', | |
| 61 metavar='dir', | |
| 62 default=os.curdir, | |
| 63 help=("Build wheels into <dir>, where the default is the " | |
| 64 "current working directory."), | |
| 65 ) | |
| 66 cmd_opts.add_option(cmdoptions.no_binary()) | |
| 67 cmd_opts.add_option(cmdoptions.only_binary()) | |
| 68 cmd_opts.add_option(cmdoptions.prefer_binary()) | |
| 69 cmd_opts.add_option( | |
| 70 '--build-option', | |
| 71 dest='build_options', | |
| 72 metavar='options', | |
| 73 action='append', | |
| 74 help="Extra arguments to be supplied to 'setup.py bdist_wheel'.", | |
| 75 ) | |
| 76 cmd_opts.add_option(cmdoptions.no_build_isolation()) | |
| 77 cmd_opts.add_option(cmdoptions.use_pep517()) | |
| 78 cmd_opts.add_option(cmdoptions.no_use_pep517()) | |
| 79 cmd_opts.add_option(cmdoptions.constraints()) | |
| 80 cmd_opts.add_option(cmdoptions.editable()) | |
| 81 cmd_opts.add_option(cmdoptions.requirements()) | |
| 82 cmd_opts.add_option(cmdoptions.src()) | |
| 83 cmd_opts.add_option(cmdoptions.ignore_requires_python()) | |
| 84 cmd_opts.add_option(cmdoptions.no_deps()) | |
| 85 cmd_opts.add_option(cmdoptions.build_dir()) | |
| 86 cmd_opts.add_option(cmdoptions.progress_bar()) | |
| 87 | |
| 88 cmd_opts.add_option( | |
| 89 '--global-option', | |
| 90 dest='global_options', | |
| 91 action='append', | |
| 92 metavar='options', | |
| 93 help="Extra global options to be supplied to the setup.py " | |
| 94 "call before the 'bdist_wheel' command.") | |
| 95 | |
| 96 cmd_opts.add_option( | |
| 97 '--pre', | |
| 98 action='store_true', | |
| 99 default=False, | |
| 100 help=("Include pre-release and development versions. By default, " | |
| 101 "pip only finds stable versions."), | |
| 102 ) | |
| 103 | |
| 104 cmd_opts.add_option(cmdoptions.no_clean()) | |
| 105 cmd_opts.add_option(cmdoptions.require_hashes()) | |
| 106 | |
| 107 index_opts = cmdoptions.make_option_group( | |
| 108 cmdoptions.index_group, | |
| 109 self.parser, | |
| 110 ) | |
| 111 | |
| 112 self.parser.insert_option_group(0, index_opts) | |
| 113 self.parser.insert_option_group(0, cmd_opts) | |
| 114 | |
| 115 def run(self, options, args): | |
| 116 # type: (Values, List[Any]) -> None | |
| 117 cmdoptions.check_install_build_global(options) | |
| 118 | |
| 119 session = self.get_default_session(options) | |
| 120 | |
| 121 finder = self._build_package_finder(options, session) | |
| 122 build_delete = (not (options.no_clean or options.build_dir)) | |
| 123 wheel_cache = WheelCache(options.cache_dir, options.format_control) | |
| 124 | |
| 125 options.wheel_dir = normalize_path(options.wheel_dir) | |
| 126 ensure_dir(options.wheel_dir) | |
| 127 | |
| 128 with get_requirement_tracker() as req_tracker, TempDirectory( | |
| 129 options.build_dir, delete=build_delete, kind="wheel" | |
| 130 ) as directory: | |
| 131 | |
| 132 requirement_set = RequirementSet() | |
| 133 | |
| 134 try: | |
| 135 self.populate_requirement_set( | |
| 136 requirement_set, args, options, finder, session, | |
| 137 wheel_cache | |
| 138 ) | |
| 139 | |
| 140 preparer = self.make_requirement_preparer( | |
| 141 temp_build_dir=directory, | |
| 142 options=options, | |
| 143 req_tracker=req_tracker, | |
| 144 session=session, | |
| 145 finder=finder, | |
| 146 wheel_download_dir=options.wheel_dir, | |
| 147 use_user_site=False, | |
| 148 ) | |
| 149 | |
| 150 resolver = self.make_resolver( | |
| 151 preparer=preparer, | |
| 152 finder=finder, | |
| 153 options=options, | |
| 154 wheel_cache=wheel_cache, | |
| 155 ignore_requires_python=options.ignore_requires_python, | |
| 156 use_pep517=options.use_pep517, | |
| 157 ) | |
| 158 | |
| 159 self.trace_basic_info(finder) | |
| 160 | |
| 161 resolver.resolve(requirement_set) | |
| 162 | |
| 163 reqs_to_build = [ | |
| 164 r for r in requirement_set.requirements.values() | |
| 165 if should_build_for_wheel_command(r) | |
| 166 ] | |
| 167 | |
| 168 # build wheels | |
| 169 build_successes, build_failures = build( | |
| 170 reqs_to_build, | |
| 171 wheel_cache=wheel_cache, | |
| 172 build_options=options.build_options or [], | |
| 173 global_options=options.global_options or [], | |
| 174 ) | |
| 175 for req in build_successes: | |
| 176 assert req.link and req.link.is_wheel | |
| 177 assert req.local_file_path | |
| 178 # copy from cache to target directory | |
| 179 try: | |
| 180 shutil.copy(req.local_file_path, options.wheel_dir) | |
| 181 except OSError as e: | |
| 182 logger.warning( | |
| 183 "Building wheel for %s failed: %s", | |
| 184 req.name, e, | |
| 185 ) | |
| 186 build_failures.append(req) | |
| 187 if len(build_failures) != 0: | |
| 188 raise CommandError( | |
| 189 "Failed to build one or more wheels" | |
| 190 ) | |
| 191 except PreviousBuildDirError: | |
| 192 options.no_clean = True | |
| 193 raise | |
| 194 finally: | |
| 195 if not options.no_clean: | |
| 196 requirement_set.cleanup_files() | |
| 197 wheel_cache.cleanup() |
