|
8 | 8 | import sys
|
9 | 9 | import uuid
|
10 | 10 | import zipfile
|
| 11 | +from enum import Enum |
| 12 | +from optparse import Values |
11 | 13 | from typing import Any, Collection, Dict, Iterable, List, Optional, Sequence, Union
|
12 | 14 |
|
13 | 15 | from pip._vendor.packaging.markers import Marker
|
@@ -876,3 +878,65 @@ def check_invalid_constraint_type(req: InstallRequirement) -> str:
|
876 | 878 | )
|
877 | 879 |
|
878 | 880 | 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 | + ) |
0 commit comments