Skip to content

Commit fa7566d

Browse files
authored
Merge pull request #12627 from ichard26/not-a-directory-path
Gracefully skip VCS detection on broken PATH
2 parents 4caa6c3 + 9642488 commit fa7566d

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
@@ -641,6 +641,8 @@ def run_command(
641641
log_failed_cmd=log_failed_cmd,
642642
stdout_only=stdout_only,
643643
)
644+
except NotADirectoryError:
645+
raise BadCommand(f"Cannot find command {cls.name!r} - invalid PATH")
644646
except FileNotFoundError:
645647
# errno.ENOENT = no such file or directory
646648
# 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)