Skip to content

Commit 7311c82

Browse files
authored
Merge pull request #11359 from sbidoul/deprecate-install-options
Deprecate --install-options
2 parents e6e7c12 + fe58a42 commit 7311c82

File tree

10 files changed

+96
-38
lines changed

10 files changed

+96
-38
lines changed

news/11358.removal.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Deprecate ``--install-options`` which forces pip to use the deprecated ``install``
2+
command of ``setuptools``.

src/pip/_internal/cli/cmdoptions.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -59,31 +59,6 @@ def make_option_group(group: Dict[str, Any], parser: ConfigOptionParser) -> Opti
5959
return option_group
6060

6161

62-
def check_install_build_global(
63-
options: Values, check_options: Optional[Values] = None
64-
) -> None:
65-
"""Disable wheels if per-setup.py call options are set.
66-
67-
:param options: The OptionParser options to update.
68-
:param check_options: The options to check, if not supplied defaults to
69-
options.
70-
"""
71-
if check_options is None:
72-
check_options = options
73-
74-
def getname(n: str) -> Optional[Any]:
75-
return getattr(check_options, n, None)
76-
77-
names = ["build_options", "global_options", "install_options"]
78-
if any(map(getname, names)):
79-
control = options.format_control
80-
control.disallow_binaries()
81-
logger.warning(
82-
"Disabling all use of wheels due to the use of --build-option "
83-
"/ --global-option / --install-option.",
84-
)
85-
86-
8762
def check_dist_restriction(options: Values, check_target: bool = False) -> None:
8863
"""Function for determining if custom platform options are allowed.
8964

src/pip/_internal/commands/download.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
from pip._internal.cli.req_command import RequirementCommand, with_cleanup
99
from pip._internal.cli.status_codes import SUCCESS
1010
from pip._internal.operations.build.build_tracker import get_build_tracker
11+
from pip._internal.req.req_install import (
12+
LegacySetupPyOptionsCheckMode,
13+
check_legacy_setup_py_options,
14+
)
1115
from pip._internal.utils.misc import ensure_dir, normalize_path, write_output
1216
from pip._internal.utils.temp_dir import TempDirectory
1317

@@ -105,6 +109,9 @@ def run(self, options: Values, args: List[str]) -> int:
105109
)
106110

107111
reqs = self.get_requirements(args, options, finder, session)
112+
check_legacy_setup_py_options(
113+
options, reqs, LegacySetupPyOptionsCheckMode.DOWNLOAD
114+
)
108115

109116
preparer = self.make_requirement_preparer(
110117
temp_build_dir=directory,

src/pip/_internal/commands/install.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@
2727
from pip._internal.operations.build.build_tracker import get_build_tracker
2828
from pip._internal.operations.check import ConflictDetails, check_install_conflicts
2929
from pip._internal.req import install_given_reqs
30-
from pip._internal.req.req_install import InstallRequirement
30+
from pip._internal.req.req_install import (
31+
InstallRequirement,
32+
LegacySetupPyOptionsCheckMode,
33+
check_legacy_setup_py_options,
34+
)
3135
from pip._internal.utils.compat import WINDOWS
3236
from pip._internal.utils.deprecation import (
3337
LegacyInstallReasonFailedBdistWheel,
@@ -280,7 +284,6 @@ def run(self, options: Values, args: List[str]) -> int:
280284
if options.use_user_site and options.target_dir is not None:
281285
raise CommandError("Can not combine '--user' and '--target'")
282286

283-
cmdoptions.check_install_build_global(options)
284287
upgrade_strategy = "to-satisfy-only"
285288
if options.upgrade:
286289
upgrade_strategy = options.upgrade_strategy
@@ -339,6 +342,9 @@ def run(self, options: Values, args: List[str]) -> int:
339342

340343
try:
341344
reqs = self.get_requirements(args, options, finder, session)
345+
check_legacy_setup_py_options(
346+
options, reqs, LegacySetupPyOptionsCheckMode.INSTALL
347+
)
342348

343349
if "no-binary-enable-wheel-cache" in options.features_enabled:
344350
# TODO: remove format_control from WheelCache when the deprecation cycle
@@ -446,7 +452,7 @@ def run(self, options: Values, args: List[str]) -> int:
446452
wheel_cache=wheel_cache,
447453
verify=True,
448454
build_options=[],
449-
global_options=[],
455+
global_options=global_options,
450456
)
451457

452458
# If we're using PEP 517, we cannot do a legacy setup.py install

src/pip/_internal/commands/wheel.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
from pip._internal.cli.status_codes import SUCCESS
1111
from pip._internal.exceptions import CommandError
1212
from pip._internal.operations.build.build_tracker import get_build_tracker
13-
from pip._internal.req.req_install import InstallRequirement
13+
from pip._internal.req.req_install import (
14+
InstallRequirement,
15+
LegacySetupPyOptionsCheckMode,
16+
check_legacy_setup_py_options,
17+
)
1418
from pip._internal.utils.deprecation import deprecated
1519
from pip._internal.utils.misc import ensure_dir, normalize_path
1620
from pip._internal.utils.temp_dir import TempDirectory
@@ -101,8 +105,6 @@ def add_options(self) -> None:
101105

102106
@with_cleanup
103107
def run(self, options: Values, args: List[str]) -> int:
104-
cmdoptions.check_install_build_global(options)
105-
106108
session = self.get_default_session(options)
107109

108110
finder = self._build_package_finder(options, session)
@@ -120,6 +122,9 @@ def run(self, options: Values, args: List[str]) -> int:
120122
)
121123

122124
reqs = self.get_requirements(args, options, finder, session)
125+
check_legacy_setup_py_options(
126+
options, reqs, LegacySetupPyOptionsCheckMode.WHEEL
127+
)
123128

124129
if "no-binary-enable-wheel-cache" in options.features_enabled:
125130
# TODO: remove format_control from WheelCache when the deprecation cycle

src/pip/_internal/req/req_file.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,6 @@ def handle_requirement_line(
186186
constraint=line.constraint,
187187
)
188188
else:
189-
if options:
190-
# Disable wheels if the user has specified build options
191-
cmdoptions.check_install_build_global(options, line.opts)
192-
193189
# get the options that apply to requirements
194190
req_options = {}
195191
for dest in SUPPORTED_OPTIONS_REQ_DEST:

src/pip/_internal/req/req_install.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import sys
99
import uuid
1010
import zipfile
11+
from enum import Enum
12+
from optparse import Values
1113
from typing import Any, Collection, Dict, Iterable, List, Optional, Sequence, Union
1214

1315
from pip._vendor.packaging.markers import Marker
@@ -876,3 +878,65 @@ def check_invalid_constraint_type(req: InstallRequirement) -> str:
876878
)
877879

878880
return problem
881+
882+
883+
def _has_option(options: Values, reqs: List[InstallRequirement], option: str) -> bool:
884+
if getattr(options, option, None):
885+
return True
886+
for req in reqs:
887+
if getattr(req, option, None):
888+
return True
889+
return False
890+
891+
892+
def _install_option_ignored(
893+
install_options: List[str], reqs: List[InstallRequirement]
894+
) -> bool:
895+
for req in reqs:
896+
if (install_options or req.install_options) and not req.use_pep517:
897+
return False
898+
return True
899+
900+
901+
class LegacySetupPyOptionsCheckMode(Enum):
902+
INSTALL = 1
903+
WHEEL = 2
904+
DOWNLOAD = 3
905+
906+
907+
def check_legacy_setup_py_options(
908+
options: Values,
909+
reqs: List[InstallRequirement],
910+
mode: LegacySetupPyOptionsCheckMode,
911+
) -> None:
912+
has_install_options = _has_option(options, reqs, "install_options")
913+
has_build_options = _has_option(options, reqs, "build_options")
914+
has_global_options = _has_option(options, reqs, "global_options")
915+
legacy_setup_py_options_present = (
916+
has_install_options or has_build_options or has_global_options
917+
)
918+
if not legacy_setup_py_options_present:
919+
return
920+
921+
options.format_control.disallow_binaries()
922+
logger.warning(
923+
"Implying --no-binary=:all: due to the presence of "
924+
"--build-option / --global-option / --install-option. "
925+
"Consider using --config-settings for more flexibility.",
926+
)
927+
if mode == LegacySetupPyOptionsCheckMode.INSTALL and has_install_options:
928+
if _install_option_ignored(options.install_options, reqs):
929+
logger.warning(
930+
"Ignoring --install-option when building using PEP 517",
931+
)
932+
else:
933+
deprecated(
934+
reason=(
935+
"--install-option is deprecated because "
936+
"it forces pip to use the 'setup.py install' "
937+
"command which is itself deprecated."
938+
),
939+
issue=11358,
940+
replacement="to use --config-settings",
941+
gone_in="23.1",
942+
)

tests/functional/test_install.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,8 @@ def test_install_global_option(script: PipTestEnvironment) -> None:
842842
)
843843
assert "INITools==0.1\n" in result.stdout
844844
assert not result.files_created
845+
assert "Implying --no-binary=:all:" in result.stderr
846+
assert "Consider using --config-settings" in result.stderr
845847

846848

847849
def test_install_with_hacked_egg_info(

tests/functional/test_install_reqs.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ def test_install_option_in_requirements_file_overrides_cli(
342342
reqs_file = script.scratch_path.joinpath("reqs.txt")
343343
reqs_file.write_text("simple --install-option='-O0'")
344344

345-
script.pip(
345+
result = script.pip(
346346
"install",
347347
"--no-index",
348348
"-f",
@@ -355,6 +355,9 @@ def test_install_option_in_requirements_file_overrides_cli(
355355
simple_args = simple_sdist.args()
356356
assert "install" in simple_args
357357
assert simple_args.index("-O1") < simple_args.index("-O0")
358+
assert "Implying --no-binary=:all:" in result.stderr
359+
assert "Consider using --config-settings" in result.stderr
360+
assert "--install-option is deprecated" in result.stderr
358361

359362

360363
def test_constraints_not_installed_by_default(

tests/unit/test_req_file.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -881,5 +881,3 @@ def test_install_requirements_with_options(
881881
< args.index("install")
882882
< args.index(install_option)
883883
)
884-
assert options.format_control.no_binary == {":all:"}
885-
assert options.format_control.only_binary == set()

0 commit comments

Comments
 (0)