Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hhhrrrttt222111
GitHub Repository: hhhrrrttt222111/Dorkify
Path: blob/master/venv/Lib/site-packages/pip/_internal/commands/wheel.py
811 views
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, with_cleanup
15
from pip._internal.exceptions import CommandError
16
from pip._internal.req.req_tracker import get_requirement_tracker
17
from pip._internal.utils.misc import ensure_dir, normalize_path
18
from pip._internal.utils.temp_dir import TempDirectory
19
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
20
from pip._internal.wheel_builder import build, should_build_for_wheel_command
21
22
if MYPY_CHECK_RUNNING:
23
from optparse import Values
24
from typing import Any, List
25
26
27
logger = logging.getLogger(__name__)
28
29
30
class WheelCommand(RequirementCommand):
31
"""
32
Build Wheel archives for your requirements and dependencies.
33
34
Wheel is a built-package format, and offers the advantage of not
35
recompiling your software during every install. For more details, see the
36
wheel docs: https://wheel.readthedocs.io/en/latest/
37
38
Requirements: setuptools>=0.8, and wheel.
39
40
'pip wheel' uses the bdist_wheel setuptools extension from the wheel
41
package to build individual wheels.
42
43
"""
44
45
usage = """
46
%prog [options] <requirement specifier> ...
47
%prog [options] -r <requirements file> ...
48
%prog [options] [-e] <vcs project url> ...
49
%prog [options] [-e] <local project path> ...
50
%prog [options] <archive url/path> ..."""
51
52
def __init__(self, *args, **kw):
53
super(WheelCommand, self).__init__(*args, **kw)
54
55
cmd_opts = self.cmd_opts
56
57
cmd_opts.add_option(
58
'-w', '--wheel-dir',
59
dest='wheel_dir',
60
metavar='dir',
61
default=os.curdir,
62
help=("Build wheels into <dir>, where the default is the "
63
"current working directory."),
64
)
65
cmd_opts.add_option(cmdoptions.no_binary())
66
cmd_opts.add_option(cmdoptions.only_binary())
67
cmd_opts.add_option(cmdoptions.prefer_binary())
68
cmd_opts.add_option(
69
'--build-option',
70
dest='build_options',
71
metavar='options',
72
action='append',
73
help="Extra arguments to be supplied to 'setup.py bdist_wheel'.",
74
)
75
cmd_opts.add_option(cmdoptions.no_build_isolation())
76
cmd_opts.add_option(cmdoptions.use_pep517())
77
cmd_opts.add_option(cmdoptions.no_use_pep517())
78
cmd_opts.add_option(cmdoptions.constraints())
79
cmd_opts.add_option(cmdoptions.editable())
80
cmd_opts.add_option(cmdoptions.requirements())
81
cmd_opts.add_option(cmdoptions.src())
82
cmd_opts.add_option(cmdoptions.ignore_requires_python())
83
cmd_opts.add_option(cmdoptions.no_deps())
84
cmd_opts.add_option(cmdoptions.build_dir())
85
cmd_opts.add_option(cmdoptions.progress_bar())
86
87
cmd_opts.add_option(
88
'--global-option',
89
dest='global_options',
90
action='append',
91
metavar='options',
92
help="Extra global options to be supplied to the setup.py "
93
"call before the 'bdist_wheel' command.")
94
95
cmd_opts.add_option(
96
'--pre',
97
action='store_true',
98
default=False,
99
help=("Include pre-release and development versions. By default, "
100
"pip only finds stable versions."),
101
)
102
103
cmd_opts.add_option(cmdoptions.require_hashes())
104
105
index_opts = cmdoptions.make_option_group(
106
cmdoptions.index_group,
107
self.parser,
108
)
109
110
self.parser.insert_option_group(0, index_opts)
111
self.parser.insert_option_group(0, cmd_opts)
112
113
@with_cleanup
114
def run(self, options, args):
115
# type: (Values, List[Any]) -> None
116
cmdoptions.check_install_build_global(options)
117
118
session = self.get_default_session(options)
119
120
finder = self._build_package_finder(options, session)
121
build_delete = (not (options.no_clean or options.build_dir))
122
wheel_cache = WheelCache(options.cache_dir, options.format_control)
123
124
options.wheel_dir = normalize_path(options.wheel_dir)
125
ensure_dir(options.wheel_dir)
126
127
req_tracker = self.enter_context(get_requirement_tracker())
128
129
directory = TempDirectory(
130
options.build_dir,
131
delete=build_delete,
132
kind="wheel",
133
globally_managed=True,
134
)
135
136
reqs = self.get_requirements(args, options, finder, session)
137
138
preparer = self.make_requirement_preparer(
139
temp_build_dir=directory,
140
options=options,
141
req_tracker=req_tracker,
142
session=session,
143
finder=finder,
144
wheel_download_dir=options.wheel_dir,
145
use_user_site=False,
146
)
147
148
resolver = self.make_resolver(
149
preparer=preparer,
150
finder=finder,
151
options=options,
152
wheel_cache=wheel_cache,
153
ignore_requires_python=options.ignore_requires_python,
154
use_pep517=options.use_pep517,
155
)
156
157
self.trace_basic_info(finder)
158
159
requirement_set = resolver.resolve(
160
reqs, check_supported_wheels=True
161
)
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
192