1
1
Fork 0
mirror of https://github.com/pypa/pip synced 2023-12-13 21:30:23 +01:00
pip/pip/commands/wheel.py

197 lines
6.9 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
from __future__ import absolute_import
import logging
2012-10-17 00:57:10 +02:00
import os
import warnings
from pip.basecommand import RequirementCommand
2012-10-17 01:39:56 +02:00
from pip.index import PackageFinder
2013-07-24 11:02:08 +02:00
from pip.exceptions import CommandError, PreviousBuildDirError
from pip.req import RequirementSet
from pip.utils import import_or_raise, normalize_path
from pip.utils.build import BuildDirectory
from pip.utils.deprecation import RemovedInPip8Warning
from pip.wheel import WheelBuilder
2013-02-03 07:40:30 +01:00
from pip import cmdoptions
2012-10-17 00:57:10 +02:00
DEFAULT_WHEEL_DIR = os.path.join(normalize_path(os.curdir), 'wheelhouse')
logger = logging.getLogger(__name__)
class WheelCommand(RequirementCommand):
2013-03-16 07:56:46 +01:00
"""
2013-03-18 03:58:32 +01:00
Build Wheel archives for your requirements and dependencies.
2013-03-16 07:56:46 +01:00
Wheel is a built-package format, and offers the advantage of not
recompiling your software during every install. For more details, see the
wheel docs: http://wheel.readthedocs.org/en/latest.
2013-03-18 03:58:32 +01:00
Requirements: setuptools>=0.8, and wheel.
2013-03-18 03:58:32 +01:00
'pip wheel' uses the bdist_wheel setuptools extension from the wheel
package to build individual wheels.
2013-03-18 03:58:32 +01:00
2013-03-16 07:56:46 +01:00
"""
2012-10-17 00:57:10 +02:00
name = 'wheel'
2013-02-03 07:40:30 +01:00
usage = """
%prog [options] <requirement specifier> ...
2013-04-05 20:02:15 +02:00
%prog [options] -r <requirements file> ...
%prog [options] [-e] <vcs project url> ...
%prog [options] [-e] <local project path> ...
2013-04-05 20:02:15 +02:00
%prog [options] <archive url/path> ..."""
2013-02-03 07:40:30 +01:00
summary = 'Build wheels from your requirements.'
def __init__(self, *args, **kw):
super(WheelCommand, self).__init__(*args, **kw)
cmd_opts = self.cmd_opts
cmd_opts.add_option(
2012-10-17 00:57:10 +02:00
'-w', '--wheel-dir',
dest='wheel_dir',
2013-02-03 07:40:30 +01:00
metavar='dir',
2012-10-17 00:57:10 +02:00
default=DEFAULT_WHEEL_DIR,
help=("Build wheels into <dir>, where the default is "
"'<cwd>/wheelhouse'."),
)
cmd_opts.add_option(cmdoptions.use_wheel.make())
cmd_opts.add_option(cmdoptions.no_use_wheel.make())
2013-02-03 07:40:30 +01:00
cmd_opts.add_option(
2012-10-17 00:57:10 +02:00
'--build-option',
dest='build_options',
2013-02-03 07:56:32 +01:00
metavar='options',
2012-10-17 00:57:10 +02:00
action='append',
2013-02-03 07:40:30 +01:00
help="Extra arguments to be supplied to 'setup.py bdist_wheel'.")
cmd_opts.add_option(cmdoptions.editable.make())
cmd_opts.add_option(cmdoptions.requirements.make())
cmd_opts.add_option(cmdoptions.download_cache.make())
cmd_opts.add_option(cmdoptions.src.make())
cmd_opts.add_option(cmdoptions.no_deps.make())
cmd_opts.add_option(cmdoptions.build_dir.make())
2013-02-03 07:40:30 +01:00
cmd_opts.add_option(
'--global-option',
dest='global_options',
action='append',
metavar='options',
help="Extra global options to be supplied to the setup.py "
"call before the 'bdist_wheel' command.")
cmd_opts.add_option(
'--pre',
action='store_true',
default=False,
help=("Include pre-release and development versions. By default, "
"pip only finds stable versions."),
)
cmd_opts.add_option(cmdoptions.no_clean.make())
2013-05-25 02:11:15 +02:00
index_opts = cmdoptions.make_option_group(
cmdoptions.index_group,
self.parser,
)
2013-02-03 07:40:30 +01:00
self.parser.insert_option_group(0, index_opts)
self.parser.insert_option_group(0, cmd_opts)
2012-10-17 00:57:10 +02:00
def check_required_packages(self):
import_or_raise(
'wheel.bdist_wheel',
CommandError,
"'pip wheel' requires the 'wheel' package. To fix this, run: "
"pip install wheel"
)
pkg_resources = import_or_raise(
'pkg_resources',
CommandError,
"'pip wheel' requires setuptools >= 0.8 for dist-info support."
" To fix this, run: pip install --upgrade setuptools"
)
if not hasattr(pkg_resources, 'DistInfoDistribution'):
raise CommandError(
"'pip wheel' requires setuptools >= 0.8 for dist-info "
"support. To fix this, run: pip install --upgrade "
"setuptools"
)
def run(self, options, args):
self.check_required_packages()
2012-10-17 01:39:56 +02:00
2012-10-17 00:57:10 +02:00
index_urls = [options.index_url] + options.extra_index_urls
if options.no_index:
logger.info('Ignoring indexes: %s', ','.join(index_urls))
2012-10-17 00:57:10 +02:00
index_urls = []
if options.download_cache:
warnings.warn(
"--download-cache has been deprecated and will be removed in "
"the future. Pip now automatically uses and configures its "
"cache.",
RemovedInPip8Warning,
)
if options.build_dir:
options.build_dir = os.path.abspath(options.build_dir)
with self._build_session(options) as session:
finder = PackageFinder(
find_links=options.find_links,
index_urls=index_urls,
use_wheel=options.use_wheel,
allow_external=options.allow_external,
allow_unverified=options.allow_unverified,
allow_all_external=options.allow_all_external,
allow_all_prereleases=options.pre,
trusted_hosts=options.trusted_hosts,
process_dependency_links=options.process_dependency_links,
session=session,
)
2012-10-17 00:57:10 +02:00
build_delete = (not (options.no_clean or options.build_dir))
with BuildDirectory(options.build_dir,
delete=build_delete) as build_dir:
requirement_set = RequirementSet(
build_dir=build_dir,
cache_root=options.cache_dir,
src_dir=options.src_dir,
download_dir=None,
ignore_dependencies=options.ignore_dependencies,
ignore_installed=True,
isolated=options.isolated_mode,
session=session,
wheel_download_dir=options.wheel_dir
)
self.populate_requirement_set(
requirement_set, args, options, finder, session, self.name,
)
if not requirement_set.has_requirements:
return
try:
# build wheels
wb = WheelBuilder(
requirement_set,
finder,
build_options=options.build_options or [],
global_options=options.global_options or [],
)
if not wb.build():
raise CommandError(
"Failed to build one or more wheels"
)
except PreviousBuildDirError:
options.no_clean = True
raise
finally:
if not options.no_clean:
requirement_set.cleanup_files()