comparison venv/lib/python2.7/site-packages/pip/commands/wheel.py @ 0:d67268158946 draft

planemo upload commit a3f181f5f126803c654b3a66dd4e83a48f7e203b
author bcclaywell
date Mon, 12 Oct 2015 17:43:33 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:d67268158946
1 # -*- coding: utf-8 -*-
2 from __future__ import absolute_import
3
4 import logging
5 import os
6 import warnings
7
8 from pip.basecommand import Command
9 from pip.index import PackageFinder
10 from pip.exceptions import CommandError, PreviousBuildDirError
11 from pip.req import InstallRequirement, RequirementSet, parse_requirements
12 from pip.utils import import_or_raise, normalize_path
13 from pip.utils.build import BuildDirectory
14 from pip.utils.deprecation import RemovedInPip7Warning, RemovedInPip8Warning
15 from pip.wheel import WheelBuilder
16 from pip import cmdoptions
17
18 DEFAULT_WHEEL_DIR = os.path.join(normalize_path(os.curdir), 'wheelhouse')
19
20
21 logger = logging.getLogger(__name__)
22
23
24 class WheelCommand(Command):
25 """
26 Build Wheel archives for your requirements and dependencies.
27
28 Wheel is a built-package format, and offers the advantage of not
29 recompiling your software during every install. For more details, see the
30 wheel docs: http://wheel.readthedocs.org/en/latest.
31
32 Requirements: setuptools>=0.8, and wheel.
33
34 'pip wheel' uses the bdist_wheel setuptools extension from the wheel
35 package to build individual wheels.
36
37 """
38
39 name = 'wheel'
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 summary = 'Build wheels from your requirements.'
48
49 def __init__(self, *args, **kw):
50 super(WheelCommand, self).__init__(*args, **kw)
51
52 cmd_opts = self.cmd_opts
53
54 cmd_opts.add_option(
55 '-w', '--wheel-dir',
56 dest='wheel_dir',
57 metavar='dir',
58 default=DEFAULT_WHEEL_DIR,
59 help=("Build wheels into <dir>, where the default is "
60 "'<cwd>/wheelhouse'."),
61 )
62 cmd_opts.add_option(cmdoptions.use_wheel.make())
63 cmd_opts.add_option(cmdoptions.no_use_wheel.make())
64 cmd_opts.add_option(
65 '--build-option',
66 dest='build_options',
67 metavar='options',
68 action='append',
69 help="Extra arguments to be supplied to 'setup.py bdist_wheel'.")
70 cmd_opts.add_option(cmdoptions.editable.make())
71 cmd_opts.add_option(cmdoptions.requirements.make())
72 cmd_opts.add_option(cmdoptions.download_cache.make())
73 cmd_opts.add_option(cmdoptions.src.make())
74 cmd_opts.add_option(cmdoptions.no_deps.make())
75 cmd_opts.add_option(cmdoptions.build_dir.make())
76
77 cmd_opts.add_option(
78 '--global-option',
79 dest='global_options',
80 action='append',
81 metavar='options',
82 help="Extra global options to be supplied to the setup.py "
83 "call before the 'bdist_wheel' command.")
84
85 cmd_opts.add_option(
86 '--pre',
87 action='store_true',
88 default=False,
89 help=("Include pre-release and development versions. By default, "
90 "pip only finds stable versions."),
91 )
92
93 cmd_opts.add_option(cmdoptions.no_clean.make())
94
95 index_opts = cmdoptions.make_option_group(
96 cmdoptions.index_group,
97 self.parser,
98 )
99
100 self.parser.insert_option_group(0, index_opts)
101 self.parser.insert_option_group(0, cmd_opts)
102
103 def check_required_packages(self):
104 import_or_raise(
105 'wheel.bdist_wheel',
106 CommandError,
107 "'pip wheel' requires the 'wheel' package. To fix this, run: "
108 "pip install wheel"
109 )
110 pkg_resources = import_or_raise(
111 'pkg_resources',
112 CommandError,
113 "'pip wheel' requires setuptools >= 0.8 for dist-info support."
114 " To fix this, run: pip install --upgrade setuptools"
115 )
116 if not hasattr(pkg_resources, 'DistInfoDistribution'):
117 raise CommandError(
118 "'pip wheel' requires setuptools >= 0.8 for dist-info "
119 "support. To fix this, run: pip install --upgrade "
120 "setuptools"
121 )
122
123 def run(self, options, args):
124 self.check_required_packages()
125
126 index_urls = [options.index_url] + options.extra_index_urls
127 if options.no_index:
128 logger.info('Ignoring indexes: %s', ','.join(index_urls))
129 index_urls = []
130
131 if options.use_mirrors:
132 warnings.warn(
133 "--use-mirrors has been deprecated and will be removed in the "
134 "future. Explicit uses of --index-url and/or --extra-index-url"
135 " is suggested.",
136 RemovedInPip7Warning,
137 )
138
139 if options.mirrors:
140 warnings.warn(
141 "--mirrors has been deprecated and will be removed in the "
142 "future. Explicit uses of --index-url and/or --extra-index-url"
143 " is suggested.",
144 RemovedInPip7Warning,
145 )
146 index_urls += options.mirrors
147
148 if options.download_cache:
149 warnings.warn(
150 "--download-cache has been deprecated and will be removed in "
151 "the future. Pip now automatically uses and configures its "
152 "cache.",
153 RemovedInPip8Warning,
154 )
155
156 if options.build_dir:
157 options.build_dir = os.path.abspath(options.build_dir)
158
159 with self._build_session(options) as session:
160
161 finder = PackageFinder(
162 find_links=options.find_links,
163 index_urls=index_urls,
164 use_wheel=options.use_wheel,
165 allow_external=options.allow_external,
166 allow_unverified=options.allow_unverified,
167 allow_all_external=options.allow_all_external,
168 allow_all_prereleases=options.pre,
169 trusted_hosts=options.trusted_hosts,
170 process_dependency_links=options.process_dependency_links,
171 session=session,
172 )
173
174 build_delete = (not (options.no_clean or options.build_dir))
175 with BuildDirectory(options.build_dir,
176 delete=build_delete) as build_dir:
177 requirement_set = RequirementSet(
178 build_dir=build_dir,
179 src_dir=options.src_dir,
180 download_dir=None,
181 ignore_dependencies=options.ignore_dependencies,
182 ignore_installed=True,
183 isolated=options.isolated_mode,
184 session=session,
185 wheel_download_dir=options.wheel_dir
186 )
187
188 # make the wheelhouse
189 options.wheel_dir = normalize_path(options.wheel_dir)
190 if not os.path.exists(options.wheel_dir):
191 os.makedirs(options.wheel_dir)
192
193 # parse args and/or requirements files
194 for name in args:
195 requirement_set.add_requirement(
196 InstallRequirement.from_line(
197 name, None, isolated=options.isolated_mode,
198 )
199 )
200 for name in options.editables:
201 requirement_set.add_requirement(
202 InstallRequirement.from_editable(
203 name,
204 default_vcs=options.default_vcs,
205 isolated=options.isolated_mode,
206 )
207 )
208 for filename in options.requirements:
209 for req in parse_requirements(
210 filename,
211 finder=finder,
212 options=options,
213 session=session):
214 requirement_set.add_requirement(req)
215
216 # fail if no requirements
217 if not requirement_set.has_requirements:
218 logger.error(
219 "You must give at least one requirement to %s "
220 "(see \"pip help %s\")",
221 self.name, self.name,
222 )
223 return
224
225 try:
226 # build wheels
227 wb = WheelBuilder(
228 requirement_set,
229 finder,
230 options.wheel_dir,
231 build_options=options.build_options or [],
232 global_options=options.global_options or [],
233 )
234 if not wb.build():
235 raise CommandError(
236 "Failed to build one or more wheels"
237 )
238 except PreviousBuildDirError:
239 options.no_clean = True
240 raise
241 finally:
242 if not options.no_clean:
243 requirement_set.cleanup_files()