Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/pip/_internal/commands/wheel.py @ 0:4f3585e2f14b draft default tip
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author | shellac |
---|---|
date | Mon, 22 Mar 2021 18:12:50 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4f3585e2f14b |
---|---|
1 import logging | |
2 import os | |
3 import shutil | |
4 | |
5 from pip._internal.cache import WheelCache | |
6 from pip._internal.cli import cmdoptions | |
7 from pip._internal.cli.req_command import RequirementCommand, with_cleanup | |
8 from pip._internal.cli.status_codes import SUCCESS | |
9 from pip._internal.exceptions import CommandError | |
10 from pip._internal.req.req_tracker import get_requirement_tracker | |
11 from pip._internal.utils.misc import ensure_dir, normalize_path | |
12 from pip._internal.utils.temp_dir import TempDirectory | |
13 from pip._internal.utils.typing import MYPY_CHECK_RUNNING | |
14 from pip._internal.wheel_builder import build, should_build_for_wheel_command | |
15 | |
16 if MYPY_CHECK_RUNNING: | |
17 from optparse import Values | |
18 from typing import List | |
19 | |
20 from pip._internal.req.req_install import InstallRequirement | |
21 | |
22 logger = logging.getLogger(__name__) | |
23 | |
24 | |
25 class WheelCommand(RequirementCommand): | |
26 """ | |
27 Build Wheel archives for your requirements and dependencies. | |
28 | |
29 Wheel is a built-package format, and offers the advantage of not | |
30 recompiling your software during every install. For more details, see the | |
31 wheel docs: https://wheel.readthedocs.io/en/latest/ | |
32 | |
33 Requirements: setuptools>=0.8, and wheel. | |
34 | |
35 'pip wheel' uses the bdist_wheel setuptools extension from the wheel | |
36 package to build individual wheels. | |
37 | |
38 """ | |
39 | |
40 usage = """ | |
41 %prog [options] <requirement specifier> ... | |
42 %prog [options] -r <requirements file> ... | |
43 %prog [options] [-e] <vcs project url> ... | |
44 %prog [options] [-e] <local project path> ... | |
45 %prog [options] <archive url/path> ...""" | |
46 | |
47 def add_options(self): | |
48 # type: () -> None | |
49 | |
50 self.cmd_opts.add_option( | |
51 '-w', '--wheel-dir', | |
52 dest='wheel_dir', | |
53 metavar='dir', | |
54 default=os.curdir, | |
55 help=("Build wheels into <dir>, where the default is the " | |
56 "current working directory."), | |
57 ) | |
58 self.cmd_opts.add_option(cmdoptions.no_binary()) | |
59 self.cmd_opts.add_option(cmdoptions.only_binary()) | |
60 self.cmd_opts.add_option(cmdoptions.prefer_binary()) | |
61 self.cmd_opts.add_option( | |
62 '--build-option', | |
63 dest='build_options', | |
64 metavar='options', | |
65 action='append', | |
66 help="Extra arguments to be supplied to 'setup.py bdist_wheel'.", | |
67 ) | |
68 self.cmd_opts.add_option(cmdoptions.no_build_isolation()) | |
69 self.cmd_opts.add_option(cmdoptions.use_pep517()) | |
70 self.cmd_opts.add_option(cmdoptions.no_use_pep517()) | |
71 self.cmd_opts.add_option(cmdoptions.constraints()) | |
72 self.cmd_opts.add_option(cmdoptions.editable()) | |
73 self.cmd_opts.add_option(cmdoptions.requirements()) | |
74 self.cmd_opts.add_option(cmdoptions.src()) | |
75 self.cmd_opts.add_option(cmdoptions.ignore_requires_python()) | |
76 self.cmd_opts.add_option(cmdoptions.no_deps()) | |
77 self.cmd_opts.add_option(cmdoptions.build_dir()) | |
78 self.cmd_opts.add_option(cmdoptions.progress_bar()) | |
79 | |
80 self.cmd_opts.add_option( | |
81 '--no-verify', | |
82 dest='no_verify', | |
83 action='store_true', | |
84 default=False, | |
85 help="Don't verify if built wheel is valid.", | |
86 ) | |
87 | |
88 self.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 self.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 self.cmd_opts.add_option(cmdoptions.require_hashes()) | |
105 | |
106 index_opts = cmdoptions.make_option_group( | |
107 cmdoptions.index_group, | |
108 self.parser, | |
109 ) | |
110 | |
111 self.parser.insert_option_group(0, index_opts) | |
112 self.parser.insert_option_group(0, self.cmd_opts) | |
113 | |
114 @with_cleanup | |
115 def run(self, options, args): | |
116 # type: (Values, List[str]) -> int | |
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 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 delete=not options.no_clean, | |
131 kind="wheel", | |
132 globally_managed=True, | |
133 ) | |
134 | |
135 reqs = self.get_requirements(args, options, finder, session) | |
136 | |
137 preparer = self.make_requirement_preparer( | |
138 temp_build_dir=directory, | |
139 options=options, | |
140 req_tracker=req_tracker, | |
141 session=session, | |
142 finder=finder, | |
143 download_dir=options.wheel_dir, | |
144 use_user_site=False, | |
145 ) | |
146 | |
147 resolver = self.make_resolver( | |
148 preparer=preparer, | |
149 finder=finder, | |
150 options=options, | |
151 wheel_cache=wheel_cache, | |
152 ignore_requires_python=options.ignore_requires_python, | |
153 use_pep517=options.use_pep517, | |
154 ) | |
155 | |
156 self.trace_basic_info(finder) | |
157 | |
158 requirement_set = resolver.resolve( | |
159 reqs, check_supported_wheels=True | |
160 ) | |
161 | |
162 reqs_to_build = [] # type: List[InstallRequirement] | |
163 for req in requirement_set.requirements.values(): | |
164 if req.is_wheel: | |
165 preparer.save_linked_requirement(req) | |
166 elif should_build_for_wheel_command(req): | |
167 reqs_to_build.append(req) | |
168 | |
169 # build wheels | |
170 build_successes, build_failures = build( | |
171 reqs_to_build, | |
172 wheel_cache=wheel_cache, | |
173 verify=(not options.no_verify), | |
174 build_options=options.build_options or [], | |
175 global_options=options.global_options or [], | |
176 ) | |
177 for req in build_successes: | |
178 assert req.link and req.link.is_wheel | |
179 assert req.local_file_path | |
180 # copy from cache to target directory | |
181 try: | |
182 shutil.copy(req.local_file_path, options.wheel_dir) | |
183 except OSError as e: | |
184 logger.warning( | |
185 "Building wheel for %s failed: %s", | |
186 req.name, e, | |
187 ) | |
188 build_failures.append(req) | |
189 if len(build_failures) != 0: | |
190 raise CommandError( | |
191 "Failed to build one or more wheels" | |
192 ) | |
193 | |
194 return SUCCESS |