|
26 | 26 | from pipx.constants import ( |
27 | 27 | EXIT_CODE_OK, |
28 | 28 | EXIT_CODE_SPECIFIED_PYTHON_EXECUTABLE_NOT_FOUND, |
| 29 | + FETCH_PYTHON, |
29 | 30 | MINIMUM_PYTHON_VERSION, |
30 | 31 | WINDOWS, |
31 | 32 | ExitCode, |
| 33 | + FetchPythonOptions, |
| 34 | + _validate_fetch_python, |
32 | 35 | ) |
33 | 36 | from pipx.emojis import hazard |
34 | 37 | from pipx.interpreter import ( |
@@ -247,11 +250,8 @@ def run_pipx_command(args: argparse.Namespace, subparsers: Dict[str, argparse.Ar |
247 | 250 |
|
248 | 251 | if "python" in args: |
249 | 252 | python_flag_passed = bool(args.python) |
250 | | - fetch_missing_python = args.fetch_missing_python |
251 | 253 | try: |
252 | | - interpreter = find_python_interpreter( |
253 | | - args.python or DEFAULT_PYTHON, fetch_missing_python=fetch_missing_python |
254 | | - ) |
| 254 | + interpreter = find_python_interpreter(args.python or DEFAULT_PYTHON, args.fetch_python) |
255 | 255 | args.python = interpreter |
256 | 256 | except InterpreterResolutionError as e: |
257 | 257 | logger.debug("Failed to resolve interpreter:", exc_info=True) |
@@ -459,13 +459,24 @@ def add_python_options(parser: argparse.ArgumentParser) -> None: |
459 | 459 | f"or the full path to the executable. Requires Python {MINIMUM_PYTHON_VERSION} or above." |
460 | 460 | ), |
461 | 461 | ) |
462 | | - parser.add_argument( |
463 | | - "--fetch-missing-python", |
464 | | - action="store_true", |
| 462 | + fetch_python_group = parser.add_mutually_exclusive_group() |
| 463 | + fetch_python_group.add_argument( |
| 464 | + "--fetch-python", |
| 465 | + type=FetchPythonOptions, |
| 466 | + choices=list(FetchPythonOptions), |
| 467 | + default=FETCH_PYTHON, |
465 | 468 | help=( |
466 | | - "Whether to fetch a standalone python build from GitHub if the specified python version is not found locally on the system." |
| 469 | + f"Whether to fetch a standalone python build from GitHub. If set to {FetchPythonOptions.MISSING}, " |
| 470 | + "only downloads if the specified python version is not found locally on the system." |
| 471 | + "Defaults to value of the PIPX_FETCH_PYTHON environment variable." |
467 | 472 | ), |
468 | 473 | ) |
| 474 | + fetch_python_group.add_argument( |
| 475 | + "--fetch-missing-python", |
| 476 | + action="store_const", |
| 477 | + const=FetchPythonOptions.MISSING, |
| 478 | + help="Deprecated: Alias for --fetch-python=missing", |
| 479 | + ) |
469 | 480 |
|
470 | 481 |
|
471 | 482 | def _add_install(subparsers: argparse._SubParsersAction, shared_parser: argparse.ArgumentParser) -> None: |
@@ -1170,6 +1181,7 @@ def cli() -> ExitCode: |
1170 | 1181 | """Entry point from command line""" |
1171 | 1182 | try: |
1172 | 1183 | hide_cursor() |
| 1184 | + _validate_fetch_python() |
1173 | 1185 | parser, subparsers = get_command_parser() |
1174 | 1186 | argcomplete.autocomplete(parser) |
1175 | 1187 | parsed_pipx_args = parser.parse_args() |
|
0 commit comments