|
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
|
@@ -877,3 +879,51 @@ def check_invalid_constraint_type(req: InstallRequirement) -> str:
|
877 | 879 | )
|
878 | 880 |
|
879 | 881 | return problem
|
| 882 | + |
| 883 | + |
| 884 | +def _has_option(options: Values, reqs: List[InstallRequirement], option: str) -> bool: |
| 885 | + if getattr(options, option, None): |
| 886 | + return True |
| 887 | + for req in reqs: |
| 888 | + if getattr(req, option, None): |
| 889 | + return True |
| 890 | + return False |
| 891 | + |
| 892 | + |
| 893 | +class LegacySetupPyOptionsCheckMode(Enum): |
| 894 | + INSTALL = 1 |
| 895 | + WHEEL = 2 |
| 896 | + DOWNLOAD = 3 |
| 897 | + |
| 898 | + |
| 899 | +def check_legacy_setup_py_options( |
| 900 | + options: Values, |
| 901 | + reqs: List[InstallRequirement], |
| 902 | + mode: LegacySetupPyOptionsCheckMode, |
| 903 | +) -> None: |
| 904 | + has_install_options = _has_option(options, reqs, "install_options") |
| 905 | + has_build_options = _has_option(options, reqs, "build_options") |
| 906 | + has_global_options = _has_option(options, reqs, "global_options") |
| 907 | + legacy_setup_py_options_present = ( |
| 908 | + has_install_options or has_build_options or has_global_options |
| 909 | + ) |
| 910 | + if not legacy_setup_py_options_present: |
| 911 | + return |
| 912 | + |
| 913 | + options.format_control.disallow_binaries() |
| 914 | + logger.warning( |
| 915 | + "Implying --no-binary=:all: due to the presence of " |
| 916 | + "--build-option / --global-option / --install-option. " |
| 917 | + "Consider using --config-settings for more flexibility.", |
| 918 | + ) |
| 919 | + if mode == LegacySetupPyOptionsCheckMode.INSTALL and has_install_options: |
| 920 | + deprecated( |
| 921 | + reason=( |
| 922 | + "--install-option is deprecated because " |
| 923 | + "it forces pip to use the 'setup.py install' " |
| 924 | + "command which is itself deprecated." |
| 925 | + ), |
| 926 | + issue=11358, |
| 927 | + replacement="to use --config-settings", |
| 928 | + gone_in=None, |
| 929 | + ) |
0 commit comments