Skip to content

Commit

Permalink
Merge pull request #12627 from ichard26/not-a-directory-path
Browse files Browse the repository at this point in the history
Gracefully skip VCS detection on broken PATH
  • Loading branch information
pradyunsg committed May 5, 2024
2 parents 4caa6c3 + 9642488 commit fa7566d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
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 @@ -641,6 +641,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

0 comments on commit fa7566d

Please sign in to comment.