Skip to content

Commit 9642488

Browse files
committed
Gracefully skip VCS detection on broken PATH
1 parent 800c124 commit 9642488

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

news/12567.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Gracefully skip VCS detection in pip freeze when PATH points to a non-directory path.

src/pip/_internal/vcs/versioncontrol.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,8 @@ def run_command(
652652
log_failed_cmd=log_failed_cmd,
653653
stdout_only=stdout_only,
654654
)
655+
except NotADirectoryError:
656+
raise BadCommand(f"Cannot find command {cls.name!r} - invalid PATH")
655657
except FileNotFoundError:
656658
# errno.ENOENT = no such file or directory
657659
# In other words, the VCS executable isn't available

tests/unit/test_vcs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,9 @@ def test_version_control__get_url_rev_and_auth__no_revision(url: str) -> None:
444444
[
445445
(FileNotFoundError, r"Cannot find command '{name}'"),
446446
(PermissionError, r"No permission to execute '{name}'"),
447+
(NotADirectoryError, "Cannot find command '{name}' - invalid PATH"),
447448
],
448-
ids=["FileNotFoundError", "PermissionError"],
449+
ids=["FileNotFoundError", "PermissionError", "NotADirectoryError"],
449450
)
450451
def test_version_control__run_command__fails(
451452
vcs_cls: Type[VersionControl], exc_cls: Type[Exception], msg_re: str

0 commit comments

Comments
 (0)