From 96424886eb3608fd1844a604bd4bedf04fde42c1 Mon Sep 17 00:00:00 2001 From: Richard Si Date: Mon, 15 Apr 2024 20:30:02 -0400 Subject: [PATCH] Gracefully skip VCS detection on broken PATH --- news/12567.bugfix.rst | 1 + src/pip/_internal/vcs/versioncontrol.py | 2 ++ tests/unit/test_vcs.py | 3 ++- 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 news/12567.bugfix.rst diff --git a/news/12567.bugfix.rst b/news/12567.bugfix.rst new file mode 100644 index 00000000000..55c6a93d6b9 --- /dev/null +++ b/news/12567.bugfix.rst @@ -0,0 +1 @@ +Gracefully skip VCS detection in pip freeze when PATH points to a non-directory path. diff --git a/src/pip/_internal/vcs/versioncontrol.py b/src/pip/_internal/vcs/versioncontrol.py index 7eef8ec898e..c0eb12ff428 100644 --- a/src/pip/_internal/vcs/versioncontrol.py +++ b/src/pip/_internal/vcs/versioncontrol.py @@ -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 diff --git a/tests/unit/test_vcs.py b/tests/unit/test_vcs.py index a52a6217e77..9fe63cc62e6 100644 --- a/tests/unit/test_vcs.py +++ b/tests/unit/test_vcs.py @@ -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