|
13 | 13 | from functools import partial |
14 | 14 | from optparse import SUPPRESS_HELP, Option, OptionGroup |
15 | 15 |
|
| 16 | +from pip._internal.exceptions import CommandError |
16 | 17 | from pip._internal.index import ( |
17 | 18 | FormatControl, fmt_ctl_handle_mutual_exclude, fmt_ctl_no_binary, |
18 | 19 | ) |
@@ -60,6 +61,45 @@ def getname(n): |
60 | 61 | ) |
61 | 62 |
|
62 | 63 |
|
| 64 | +def check_dist_restriction(options, check_target=False): |
| 65 | + """Function for determining if custom platform options are allowed. |
| 66 | +
|
| 67 | + :param options: The OptionParser options. |
| 68 | + :param check_target: Whether or not to check if --target is being used. |
| 69 | + """ |
| 70 | + dist_restriction_set = any([ |
| 71 | + options.python_version, |
| 72 | + options.platform, |
| 73 | + options.abi, |
| 74 | + options.implementation, |
| 75 | + ]) |
| 76 | + |
| 77 | + binary_only = FormatControl(set(), {':all:'}) |
| 78 | + sdist_dependencies_allowed = ( |
| 79 | + options.format_control != binary_only and |
| 80 | + not options.ignore_dependencies |
| 81 | + ) |
| 82 | + |
| 83 | + # Installations or downloads using dist restrictions must not combine |
| 84 | + # source distributions and dist-specific wheels, as they are not |
| 85 | + # gauranteed to be locally compatible. |
| 86 | + if dist_restriction_set and sdist_dependencies_allowed: |
| 87 | + raise CommandError( |
| 88 | + "When restricting platform and interpreter constraints using " |
| 89 | + "--python-version, --platform, --abi, or --implementation, " |
| 90 | + "either --no-deps must be set, or --only-binary=:all: must be " |
| 91 | + "set and --no-binary must not be set (or must be set to " |
| 92 | + ":none:)." |
| 93 | + ) |
| 94 | + |
| 95 | + if check_target: |
| 96 | + if dist_restriction_set and not options.target_dir: |
| 97 | + raise CommandError( |
| 98 | + "Can not use any platform or abi specific options unless " |
| 99 | + "installing via '--target'" |
| 100 | + ) |
| 101 | + |
| 102 | + |
63 | 103 | ########### |
64 | 104 | # options # |
65 | 105 | ########### |
@@ -406,6 +446,61 @@ def only_binary(): |
406 | 446 | ) |
407 | 447 |
|
408 | 448 |
|
| 449 | +platform = partial( |
| 450 | + Option, |
| 451 | + '--platform', |
| 452 | + dest='platform', |
| 453 | + metavar='platform', |
| 454 | + default=None, |
| 455 | + help=("Only use wheels compatible with <platform>. " |
| 456 | + "Defaults to the platform of the running system."), |
| 457 | +) |
| 458 | + |
| 459 | + |
| 460 | +python_version = partial( |
| 461 | + Option, |
| 462 | + '--python-version', |
| 463 | + dest='python_version', |
| 464 | + metavar='python_version', |
| 465 | + default=None, |
| 466 | + help=("Only use wheels compatible with Python " |
| 467 | + "interpreter version <version>. If not specified, then the " |
| 468 | + "current system interpreter minor version is used. A major " |
| 469 | + "version (e.g. '2') can be specified to match all " |
| 470 | + "minor revs of that major version. A minor version " |
| 471 | + "(e.g. '34') can also be specified."), |
| 472 | +) |
| 473 | + |
| 474 | + |
| 475 | +implementation = partial( |
| 476 | + Option, |
| 477 | + '--implementation', |
| 478 | + dest='implementation', |
| 479 | + metavar='implementation', |
| 480 | + default=None, |
| 481 | + help=("Only use wheels compatible with Python " |
| 482 | + "implementation <implementation>, e.g. 'pp', 'jy', 'cp', " |
| 483 | + " or 'ip'. If not specified, then the current " |
| 484 | + "interpreter implementation is used. Use 'py' to force " |
| 485 | + "implementation-agnostic wheels."), |
| 486 | +) |
| 487 | + |
| 488 | + |
| 489 | +abi = partial( |
| 490 | + Option, |
| 491 | + '--abi', |
| 492 | + dest='abi', |
| 493 | + metavar='abi', |
| 494 | + default=None, |
| 495 | + help=("Only use wheels compatible with Python " |
| 496 | + "abi <abi>, e.g. 'pypy_41'. If not specified, then the " |
| 497 | + "current interpreter abi tag is used. Generally " |
| 498 | + "you will need to specify --implementation, " |
| 499 | + "--platform, and --python-version when using " |
| 500 | + "this option."), |
| 501 | +) |
| 502 | + |
| 503 | + |
409 | 504 | def prefer_binary(): |
410 | 505 | return Option( |
411 | 506 | "--prefer-binary", |
|
0 commit comments