Skip to content

Commit

Permalink
Issue pypa#2677: Disable wheels for setup.py options.
Browse files Browse the repository at this point in the history
Using --install-options, --build-options, --global-options changes
the way that setup.py behaves, and isn't honoured by the wheel code.
The new wheel autobuilding code made this very obvious - disable
the use of wheels when these options are supplied.
  • Loading branch information
rbtcollins committed Apr 24, 2015
1 parent ff1206f commit af084d9
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
* Allow fine grained control over the use of wheels and source builds.
(:pull:`2699`)

* The use of ``--install-option``, ``--global-option`` or ``--build-option``
disable the use of wheels, and the autobuilding of wheels. (:pull:`2711`))
Fixes :issue:`2677`

**6.1.1 (2015-04-07)**

* No longer ignore dependencies which have been added to the standard library,
Expand Down
26 changes: 25 additions & 1 deletion pip/cmdoptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
from optparse import OptionGroup, SUPPRESS_HELP, Option

from pip.index import (
PyPI, FormatControl, fmt_ctl_handle_mutual_exclude, fmt_ctl_no_use_wheel)
PyPI, FormatControl, fmt_ctl_handle_mutual_exclude, fmt_ctl_no_binary,
fmt_ctl_no_use_wheel)
from pip.locations import CA_BUNDLE_PATH, USER_CACHE_DIR, src_prefix


Expand All @@ -35,6 +36,27 @@ def resolve_wheel_no_use_binary(options):
fmt_ctl_no_use_wheel(control)


def check_install_build_global(options, check_options=None):
"""Disable wheels if per-setup.py call options are set.
:param options: The OptionParser options to update.
:param check_options: The options to check, if not supplied defaults to
options.
"""
if check_options is None:
check_options = options

def getname(n):
return getattr(check_options, n, None)
names = ["build_options", "global_options", "install_options"]
if any(map(getname, names)):
control = options.format_control
fmt_ctl_no_binary(control)
warnings.warn(
'Disabling all use of wheels due to the use of --build-options '
'/ --global-options / --install-options.', stacklevel=2)


###########
# options #
###########
Expand Down Expand Up @@ -353,9 +375,11 @@ def editable():
'--use-wheel',
dest='use_wheel',
action='store_true',
default=True,
help=SUPPRESS_HELP,
)

# XXX: deprecated, remove in 9.0
no_use_wheel = partial(
Option,
'--no-use-wheel',
Expand Down
1 change: 1 addition & 0 deletions pip/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ def _build_package_finder(self, options, index_urls, session):

def run(self, options, args):
cmdoptions.resolve_wheel_no_use_binary(options)
cmdoptions.check_install_build_global(options)

if options.download_dir:
options.ignore_installed = True
Expand Down
1 change: 1 addition & 0 deletions pip/commands/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def check_required_packages(self):
def run(self, options, args):
self.check_required_packages()
cmdoptions.resolve_wheel_no_use_binary(options)
cmdoptions.check_install_build_global(options)

index_urls = [options.index_url] + options.extra_index_urls
if options.no_index:
Expand Down
9 changes: 7 additions & 2 deletions pip/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1243,12 +1243,17 @@ def fmt_ctl_formats(fmt_ctl, canonical_name):
return frozenset(result)


def fmt_ctl_no_use_wheel(fmt_ctl):
def fmt_ctl_no_binary(fmt_ctl):
fmt_ctl_handle_mutual_exclude(
':all:', fmt_ctl.no_binary, fmt_ctl.only_binary)


def fmt_ctl_no_use_wheel(fmt_ctl):
fmt_ctl_no_binary(fmt_ctl)
warnings.warn(
'--no-use-wheel is deprecated and will be removed in the future. '
' Please use --no-binary :all: instead.')
' Please use --no-binary :all: instead.', DeprecationWarning,
stacklevel=2)


Search = namedtuple('Search', 'supplied canonical formats')
Expand Down
6 changes: 4 additions & 2 deletions pip/req/req_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ def process_line(line, filename, line_number, finder=None, comes_from=None,
args_line = ' '.join(args)
comes_from = '-r %s (line %s)' % (filename, line_number)
isolated = options.isolated_mode if options else False
if options:
cmdoptions.check_install_build_global(options, opts)
# trim the None items
keys = [opt for opt in opts.__dict__ if getattr(opts, opt) is None]
for key in keys:
Expand Down Expand Up @@ -215,8 +217,8 @@ def build_parser():
parser = optparse.OptionParser(add_help_option=False)

options = SUPPORTED_OPTIONS + SUPPORTED_OPTIONS_REQ
for option in options:
option = option()
for option_factory in options:
option = option_factory()
# we want no default values; defaults are handled in `pip install`
# parsing. just concerned with values that are specifically set.
option.default = None
Expand Down
20 changes: 15 additions & 5 deletions tests/unit/test_req_file.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from optparse import Values
import os
import subprocess
from textwrap import dedent
Expand All @@ -11,7 +12,7 @@
ReqFileOnleOneOptionPerLineError,
ReqFileOptionNotAllowedWithReqError)
from pip.download import PipSession
from pip.index import PackageFinder
from pip.index import FormatControl, PackageFinder
from pip.req.req_install import InstallRequirement
from pip.req.req_file import (parse_requirements, process_line, join_lines,
ignore_comments)
Expand Down Expand Up @@ -68,8 +69,10 @@ class TestProcessLine(object):
"""tests for `process_line`"""

def setup(self):
self.options = stub(isolated_mode=False, default_vcs=None,
skip_requirements_regex=False)
self.options = stub(
isolated_mode=False, default_vcs=None,
skip_requirements_regex=False,
format_control=pip.index.FormatControl(set(), set()))

def test_parser_error(self):
with pytest.raises(RequirementsFileParseError):
Expand Down Expand Up @@ -335,6 +338,7 @@ def test_install_requirements_with_options(self, tmpdir, finder, session):
install_option = '--prefix=/opt'

content = '''
--only-binary :all:
INITools==2.0 --global-option="{global_option}" \
--install-option "{install_option}"
'''.format(global_option=global_option, install_option=install_option)
Expand All @@ -343,8 +347,12 @@ def test_install_requirements_with_options(self, tmpdir, finder, session):
with open(req_path, 'w') as fh:
fh.write(content)

req = next(parse_requirements(req_path, finder=finder,
session=session))
options = Values()
options.format_control = FormatControl(set(), set())
options.skip_requirements_regex = None
options.isolated_mode = False
req = next(parse_requirements(
req_path, finder=finder, options=options, session=session))

req.source_dir = os.curdir
with patch.object(subprocess, 'Popen') as popen:
Expand All @@ -357,3 +365,5 @@ def test_install_requirements_with_options(self, tmpdir, finder, session):
assert call.index(install_option) > \
call.index('install') > \
call.index(global_option) > 0
assert options.format_control.no_binary == set([':all:'])
assert options.format_control.only_binary == set([])

0 comments on commit af084d9

Please sign in to comment.