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

Gracefully skip VCS detection on broken PATH #12627

Merged
merged 1 commit into from
May 5, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions news/12567.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Gracefully skip VCS detection in pip freeze when PATH points to a non-directory path.
2 changes: 2 additions & 0 deletions src/pip/_internal/vcs/versioncontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,8 @@ def run_command(
log_failed_cmd=log_failed_cmd,
stdout_only=stdout_only,
)
except NotADirectoryError:
raise BadCommand(f"Cannot find command {cls.name!r} - invalid PATH")
except FileNotFoundError:
# errno.ENOENT = no such file or directory
# In other words, the VCS executable isn't available
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/test_vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,9 @@ def test_version_control__get_url_rev_and_auth__no_revision(url: str) -> None:
[
(FileNotFoundError, r"Cannot find command '{name}'"),
(PermissionError, r"No permission to execute '{name}'"),
(NotADirectoryError, "Cannot find command '{name}' - invalid PATH"),
],
ids=["FileNotFoundError", "PermissionError"],
ids=["FileNotFoundError", "PermissionError", "NotADirectoryError"],
)
def test_version_control__run_command__fails(
vcs_cls: Type[VersionControl], exc_cls: Type[Exception], msg_re: str
Expand Down