From ccf9c91492da4f012e71db5f6968bc822257bbb6 Mon Sep 17 00:00:00 2001 From: meowmeow Date: Thu, 12 Oct 2023 01:25:08 +0000 Subject: [PATCH 1/2] Return error when directory can't be added to PATH --- CHANGELOG.md | 1 + src/pipx/commands/ensure_path.py | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da15e33efd..bf10d5052c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ - Pass `--no-input` to pip when output is not piped to parent stdout - Fix program name in generated manual page - Print all environment variables in `pipx environment` +- Return an error message when directory can't be added to PATH successfully ## 1.2.0 diff --git a/src/pipx/commands/ensure_path.py b/src/pipx/commands/ensure_path.py index 8151177b51..9361c1ebfa 100644 --- a/src/pipx/commands/ensure_path.py +++ b/src/pipx/commands/ensure_path.py @@ -61,14 +61,22 @@ def ensure_path(location: Path, *, force: bool) -> Tuple[bool, bool]: in_current_path = userpath.in_current_path(location_str) if force or (not in_current_path and not need_shell_restart): - userpath.append(location_str, "pipx") - print( - pipx_wrap( - f"Success! Added {location_str} to the PATH environment variable.", - subsequent_indent=" " * 4, + path_added = userpath.append(location_str, "pipx") + if not path_added: + print( + pipx_wrap( + f"{location_str} is not added to the PATH environment variable successfully. " + f"You may need to add {location_str} to it manually.", + subsequent_indent=" " * 4, + ) + ) + else: + print( + pipx_wrap( + f"Success! Added {location_str} to the PATH environment variable.", + subsequent_indent=" " * 4, + ) ) - ) - path_added = True need_shell_restart = userpath.need_shell_restart(location_str) elif not in_current_path and need_shell_restart: print( From 150cfb0520b2bc193592e112f6f035ba74e4378b Mon Sep 17 00:00:00 2001 From: meowmeowcat <68463158+meowmeowmeowcat@users.noreply.github.com> Date: Thu, 12 Oct 2023 21:29:47 +0800 Subject: [PATCH 2/2] Update message --- src/pipx/commands/ensure_path.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pipx/commands/ensure_path.py b/src/pipx/commands/ensure_path.py index 9361c1ebfa..6e3de6ffe0 100644 --- a/src/pipx/commands/ensure_path.py +++ b/src/pipx/commands/ensure_path.py @@ -65,8 +65,8 @@ def ensure_path(location: Path, *, force: bool) -> Tuple[bool, bool]: if not path_added: print( pipx_wrap( - f"{location_str} is not added to the PATH environment variable successfully. " - f"You may need to add {location_str} to it manually.", + f"{hazard} {location_str} is not added to the PATH environment variable successfully. " + f"You may need to add it to PATH manually.", subsequent_indent=" " * 4, ) )