Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 29 additions & 10 deletions src/manage/install_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
)
from .fsutils import ensure_tree, rmtree, unlink
from .indexutils import Index
from .logging import CONSOLE_MAX_WIDTH, LOGGER, ProgressPrinter
from .logging import CONSOLE_MAX_WIDTH, LOGGER, ProgressPrinter, VERBOSE
from .pathutils import Path, PurePath
from .tagutils import install_matches_any, tag_or_range
from .urlutils import (
Expand Down Expand Up @@ -286,7 +286,7 @@
}


def update_all_shortcuts(cmd, path_warning=True):
def update_all_shortcuts(cmd):
LOGGER.debug("Updating global shortcuts")
alias_written = set()
shortcut_written = {}
Expand Down Expand Up @@ -329,25 +329,43 @@
for k, (_, cleanup) in SHORTCUT_HANDLERS.items():
cleanup(cmd, shortcut_written.get(k, []))

if path_warning and cmd.global_dir and cmd.global_dir.is_dir() and any(cmd.global_dir.glob("*.exe")):

def print_cli_shortcuts(cmd):
if cmd.global_dir and cmd.global_dir.is_dir() and any(cmd.global_dir.glob("*.exe")):
try:
if not any(cmd.global_dir.match(p) for p in os.getenv("PATH", "").split(os.pathsep) if p):
LOGGER.info("")
LOGGER.info("!B!Global shortcuts directory is not on PATH. " +
"Add it for easy access to global Python commands.!W!")
"Add it for easy access to global Python aliases.!W!")
LOGGER.info("!B!Directory to add: !Y!%s!W!", cmd.global_dir)
LOGGER.info("")
return

Check warning on line 342 in src/manage/install_command.py

View check run for this annotation

Codecov / codecov/patch

src/manage/install_command.py#L342

Added line #L342 was not covered by tests
except Exception:
LOGGER.debug("Failed to display PATH warning", exc_info=True)
return

Check warning on line 345 in src/manage/install_command.py

View check run for this annotation

Codecov / codecov/patch

src/manage/install_command.py#L345

Added line #L345 was not covered by tests


def print_cli_shortcuts(cmd):
installs = cmd.get_installs()
seen = set()
tags = getattr(cmd, "tags", None)
seen = set("python.exe".casefold())
verbose = LOGGER.would_log_to_console(VERBOSE)

Check warning on line 350 in src/manage/install_command.py

View check run for this annotation

Codecov / codecov/patch

src/manage/install_command.py#L348-L350

Added lines #L348 - L350 were not covered by tests
for i in installs:
aliases = sorted(a["name"] for a in i["alias"] if a["name"].casefold() not in seen)
seen.update(n.casefold() for n in aliases)
if not install_matches_any(i, cmd.tags):
# We only show windowed aliases if -v is enabled. But we log them as
# debug info unconditionally. This involves a bit of a dance to keep the
# 'windowed' flag around and then drop entries based on whether
# LOGGER.verbose would be printed to the console.
aliases = sorted((a["name"], a.get("windowed", 0)) for a in i["alias"]

Check warning on line 356 in src/manage/install_command.py

View check run for this annotation

Codecov / codecov/patch

src/manage/install_command.py#L356

Added line #L356 was not covered by tests
if a["name"].casefold() not in seen)
seen.update(n.casefold() for n, *_ in aliases)

Check warning on line 358 in src/manage/install_command.py

View check run for this annotation

Codecov / codecov/patch

src/manage/install_command.py#L358

Added line #L358 was not covered by tests
if not verbose:
if i.get("default"):
LOGGER.debug("%s will be launched by !G!python.exe!W!", i["display-name"])
LOGGER.debug("%s will be launched by %s", i["display-name"],

Check warning on line 362 in src/manage/install_command.py

View check run for this annotation

Codecov / codecov/patch

src/manage/install_command.py#L361-L362

Added lines #L361 - L362 were not covered by tests
", ".join([n for n, *_ in aliases]))
aliases = [n for n, w in aliases if not w]

Check warning on line 364 in src/manage/install_command.py

View check run for this annotation

Codecov / codecov/patch

src/manage/install_command.py#L364

Added line #L364 was not covered by tests
else:
aliases = [n for n, *_ in aliases]

Check warning on line 366 in src/manage/install_command.py

View check run for this annotation

Codecov / codecov/patch

src/manage/install_command.py#L366

Added line #L366 was not covered by tests

if tags and not install_matches_any(i, cmd.tags):
continue
if i.get("default") and aliases:
LOGGER.info("%s will be launched by !G!python.exe!W! and also %s",
Expand Down Expand Up @@ -545,6 +563,7 @@
else:
LOGGER.info("Refreshing install registrations.")
update_all_shortcuts(cmd)
print_cli_shortcuts(cmd)

Check warning on line 566 in src/manage/install_command.py

View check run for this annotation

Codecov / codecov/patch

src/manage/install_command.py#L566

Added line #L566 was not covered by tests
LOGGER.debug("END install_command.execute")
return

Expand Down
2 changes: 1 addition & 1 deletion src/manage/uninstall_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,6 @@
LOGGER.debug("TRACEBACK:", exc_info=True)

if to_uninstall:
update_all_shortcuts(cmd, path_warning=False)
update_all_shortcuts(cmd)

Check warning on line 130 in src/manage/uninstall_command.py

View check run for this annotation

Codecov / codecov/patch

src/manage/uninstall_command.py#L130

Added line #L130 was not covered by tests

LOGGER.debug("END uninstall_command.execute")