Skip to content

Commit 804876b

Browse files
committed
Improves alias list messages after installation.
Fixes #83
1 parent 78b92c8 commit 804876b

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

src/manage/install_command.py

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
)
1111
from .fsutils import ensure_tree, rmtree, unlink
1212
from .indexutils import Index
13-
from .logging import CONSOLE_MAX_WIDTH, LOGGER, ProgressPrinter
13+
from .logging import CONSOLE_MAX_WIDTH, LOGGER, ProgressPrinter, VERBOSE
1414
from .pathutils import Path, PurePath
1515
from .tagutils import install_matches_any, tag_or_range
1616
from .urlutils import (
@@ -286,7 +286,7 @@ def _cleanup_arp_entries(cmd, install_shortcut_pairs):
286286
}
287287

288288

289-
def update_all_shortcuts(cmd, path_warning=True):
289+
def update_all_shortcuts(cmd):
290290
LOGGER.debug("Updating global shortcuts")
291291
alias_written = set()
292292
shortcut_written = {}
@@ -329,25 +329,43 @@ def update_all_shortcuts(cmd, path_warning=True):
329329
for k, (_, cleanup) in SHORTCUT_HANDLERS.items():
330330
cleanup(cmd, shortcut_written.get(k, []))
331331

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")):
333335
try:
334336
if not any(cmd.global_dir.match(p) for p in os.getenv("PATH", "").split(os.pathsep) if p):
335337
LOGGER.info("")
336338
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!")
338340
LOGGER.info("!B!Directory to add: !Y!%s!W!", cmd.global_dir)
339341
LOGGER.info("")
342+
return
340343
except Exception:
341344
LOGGER.debug("Failed to display PATH warning", exc_info=True)
345+
return
342346

343-
344-
def print_cli_shortcuts(cmd):
345347
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)
347351
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):
351369
continue
352370
if i.get("default") and aliases:
353371
LOGGER.info("%s will be launched by !G!python.exe!W! and also %s",
@@ -545,6 +563,7 @@ def execute(cmd):
545563
else:
546564
LOGGER.info("Refreshing install registrations.")
547565
update_all_shortcuts(cmd)
566+
print_cli_shortcuts(cmd)
548567
LOGGER.debug("END install_command.execute")
549568
return
550569

src/manage/uninstall_command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,6 @@ def execute(cmd):
127127
LOGGER.debug("TRACEBACK:", exc_info=True)
128128

129129
if to_uninstall:
130-
update_all_shortcuts(cmd, path_warning=False)
130+
update_all_shortcuts(cmd)
131131

132132
LOGGER.debug("END uninstall_command.execute")

0 commit comments

Comments
 (0)