|
10 | 10 | ) |
11 | 11 | from .fsutils import ensure_tree, rmtree, unlink |
12 | 12 | from .indexutils import Index |
13 | | -from .logging import CONSOLE_MAX_WIDTH, LOGGER, ProgressPrinter |
| 13 | +from .logging import CONSOLE_MAX_WIDTH, LOGGER, ProgressPrinter, VERBOSE |
14 | 14 | from .pathutils import Path, PurePath |
15 | 15 | from .tagutils import install_matches_any, tag_or_range |
16 | 16 | from .urlutils import ( |
@@ -286,7 +286,7 @@ def _cleanup_arp_entries(cmd, install_shortcut_pairs): |
286 | 286 | } |
287 | 287 |
|
288 | 288 |
|
289 | | -def update_all_shortcuts(cmd, path_warning=True): |
| 289 | +def update_all_shortcuts(cmd): |
290 | 290 | LOGGER.debug("Updating global shortcuts") |
291 | 291 | alias_written = set() |
292 | 292 | shortcut_written = {} |
@@ -329,34 +329,48 @@ def update_all_shortcuts(cmd, path_warning=True): |
329 | 329 | for k, (_, cleanup) in SHORTCUT_HANDLERS.items(): |
330 | 330 | cleanup(cmd, shortcut_written.get(k, [])) |
331 | 331 |
|
332 | | - if path_warning and cmd.global_dir and cmd.global_dir.is_dir() and any(cmd.global_dir.glob("*.exe")): |
| 332 | + |
| 333 | +def print_cli_shortcuts(cmd): |
| 334 | + if cmd.global_dir and cmd.global_dir.is_dir() and any(cmd.global_dir.glob("*.exe")): |
333 | 335 | try: |
334 | 336 | if not any(cmd.global_dir.match(p) for p in os.getenv("PATH", "").split(os.pathsep) if p): |
335 | 337 | LOGGER.info("") |
336 | 338 | LOGGER.info("!B!Global shortcuts directory is not on PATH. " + |
337 | | - "Add it for easy access to global Python commands.!W!") |
| 339 | + "Add it for easy access to global Python aliases.!W!") |
338 | 340 | LOGGER.info("!B!Directory to add: !Y!%s!W!", cmd.global_dir) |
339 | 341 | LOGGER.info("") |
| 342 | + return |
340 | 343 | except Exception: |
341 | 344 | LOGGER.debug("Failed to display PATH warning", exc_info=True) |
| 345 | + return |
342 | 346 |
|
343 | | - |
344 | | -def print_cli_shortcuts(cmd): |
| 347 | + from .installs import get_install_alias_names |
345 | 348 | installs = cmd.get_installs() |
346 | | - seen = set() |
| 349 | + tags = getattr(cmd, "tags", None) |
| 350 | + seen = {"python.exe".casefold()} |
| 351 | + verbose = LOGGER.would_log_to_console(VERBOSE) |
347 | 352 | for i in installs: |
348 | | - aliases = sorted(a["name"] for a in i["alias"] if a["name"].casefold() not in seen) |
349 | | - seen.update(n.casefold() for n in aliases) |
350 | | - if not install_matches_any(i, cmd.tags): |
| 353 | + # We need to pre-filter aliases before getting the nice names. |
| 354 | + aliases = [a for a in i.get("alias", ()) if a["name"].casefold() not in seen] |
| 355 | + seen.update(n["name"].casefold() for n in aliases) |
| 356 | + if not verbose: |
| 357 | + if i.get("default"): |
| 358 | + LOGGER.debug("%s will be launched by !G!python.exe!W!", i["display-name"]) |
| 359 | + names = get_install_alias_names(aliases, windowed=True) |
| 360 | + LOGGER.debug("%s will be launched by %s", i["display-name"], ", ".join(names)) |
| 361 | + |
| 362 | + if tags and not install_matches_any(i, cmd.tags): |
351 | 363 | continue |
352 | | - if i.get("default") and aliases: |
| 364 | + |
| 365 | + names = get_install_alias_names(aliases, windowed=False) |
| 366 | + if i.get("default") and names: |
353 | 367 | LOGGER.info("%s will be launched by !G!python.exe!W! and also %s", |
354 | | - i["display-name"], ", ".join(aliases)) |
| 368 | + i["display-name"], ", ".join(names)) |
355 | 369 | elif i.get("default"): |
356 | 370 | LOGGER.info("%s will be launched by !G!python.exe!W!.", i["display-name"]) |
357 | | - elif aliases: |
| 371 | + elif names: |
358 | 372 | LOGGER.info("%s will be launched by %s", |
359 | | - i["display-name"], ", ".join(aliases)) |
| 373 | + i["display-name"], ", ".join(names)) |
360 | 374 | else: |
361 | 375 | LOGGER.info("Installed %s to %s", i["display-name"], i["prefix"]) |
362 | 376 |
|
@@ -545,6 +559,7 @@ def execute(cmd): |
545 | 559 | else: |
546 | 560 | LOGGER.info("Refreshing install registrations.") |
547 | 561 | update_all_shortcuts(cmd) |
| 562 | + print_cli_shortcuts(cmd) |
548 | 563 | LOGGER.debug("END install_command.execute") |
549 | 564 | return |
550 | 565 |
|
|
0 commit comments