|
5 | 5 | from argparse import Action, ArgumentParser, ArgumentTypeError, Namespace
|
6 | 6 | from typing import IO, Any, NoReturn, Sequence
|
7 | 7 |
|
| 8 | +from tox.tox_env.python.pip.req.util import handle_binary_option |
| 9 | + |
8 | 10 |
|
9 | 11 | class _OurArgumentParser(ArgumentParser):
|
10 | 12 | def print_usage(self, file: IO[str] | None = None) -> None: # noqa: U100
|
@@ -33,8 +35,8 @@ def _global_options(parser: ArgumentParser) -> None:
|
33 | 35 | parser.add_argument("-r", "--requirement", action=AddUniqueAction, dest="requirements")
|
34 | 36 | parser.add_argument("-e", "--editable", action=AddUniqueAction, dest="editables")
|
35 | 37 | parser.add_argument("-f", "--find-links", action=AddUniqueAction)
|
36 |
| - parser.add_argument("--no-binary") |
37 |
| - parser.add_argument("--only-binary") |
| 38 | + parser.add_argument("--no-binary", action=BinaryAction, nargs="+") |
| 39 | + parser.add_argument("--only-binary", action=BinaryAction, nargs="+") |
38 | 40 | parser.add_argument("--prefer-binary", action="store_true", default=False)
|
39 | 41 | parser.add_argument("--require-hashes", action="store_true", default=False)
|
40 | 42 | parser.add_argument("--pre", action="store_true", default=False)
|
@@ -90,3 +92,25 @@ def __call__(
|
90 | 92 | current = getattr(namespace, self.dest)
|
91 | 93 | if values not in current:
|
92 | 94 | current.append(values)
|
| 95 | + |
| 96 | + |
| 97 | +class BinaryAction(Action): |
| 98 | + def __call__( |
| 99 | + self, |
| 100 | + parser: ArgumentParser, # noqa: U100 |
| 101 | + namespace: Namespace, |
| 102 | + values: str | Sequence[Any] | None, |
| 103 | + option_string: str | None = None, # noqa: U100 |
| 104 | + ) -> None: |
| 105 | + if getattr(namespace, "no_binary", None) is None: |
| 106 | + namespace.no_binary = set() |
| 107 | + if getattr(namespace, "only_binary", None) is None: |
| 108 | + namespace.only_binary = set() |
| 109 | + |
| 110 | + args = ( |
| 111 | + (namespace.no_binary, namespace.only_binary) |
| 112 | + if self.dest == "no_binary" |
| 113 | + else (namespace.only_binary, namespace.no_binary) |
| 114 | + ) |
| 115 | + assert values is not None |
| 116 | + handle_binary_option(values[0], *args) |
0 commit comments