|
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,25 +329,43 @@ 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): |
345 | 347 | installs = cmd.get_installs() |
346 | | - seen = set() |
| 348 | + tags = getattr(cmd, "tags", None) |
| 349 | + seen = set("python.exe".casefold()) |
| 350 | + verbose = LOGGER.would_log_to_console(VERBOSE) |
347 | 351 | 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): |
| 352 | + # We only show windowed aliases if -v is enabled. But we log them as |
| 353 | + # debug info unconditionally. This involves a bit of a dance to keep the |
| 354 | + # 'windowed' flag around and then drop entries based on whether |
| 355 | + # LOGGER.verbose would be printed to the console. |
| 356 | + aliases = sorted((a["name"], a.get("windowed", 0)) for a in i["alias"] |
| 357 | + if a["name"].casefold() not in seen) |
| 358 | + seen.update(n.casefold() for n, *_ in aliases) |
| 359 | + if not verbose: |
| 360 | + if i.get("default"): |
| 361 | + LOGGER.debug("%s will be launched by !G!python.exe!W!", i["display-name"]) |
| 362 | + LOGGER.debug("%s will be launched by %s", i["display-name"], |
| 363 | + ", ".join([n for n, *_ in aliases])) |
| 364 | + aliases = [n for n, w in aliases if not w] |
| 365 | + else: |
| 366 | + aliases = [n for n, *_ in aliases] |
| 367 | + |
| 368 | + if tags and not install_matches_any(i, cmd.tags): |
351 | 369 | continue |
352 | 370 | if i.get("default") and aliases: |
353 | 371 | LOGGER.info("%s will be launched by !G!python.exe!W! and also %s", |
@@ -545,6 +563,7 @@ def execute(cmd): |
545 | 563 | else: |
546 | 564 | LOGGER.info("Refreshing install registrations.") |
547 | 565 | update_all_shortcuts(cmd) |
| 566 | + print_cli_shortcuts(cmd) |
548 | 567 | LOGGER.debug("END install_command.execute") |
549 | 568 | return |
550 | 569 |
|
|
0 commit comments