Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return error when directory can't be added to PATH #1083

Merged
merged 2 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 15 additions & 7 deletions src/pipx/commands/ensure_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"{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,
)
)
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(
Expand Down
Loading