Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/13346.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Provide a hint if a system error is raised involving long filenames or path segments on Windows.
35 changes: 20 additions & 15 deletions src/pip/_internal/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import shutil
import site
from optparse import SUPPRESS_HELP, Values
from pathlib import Path

from pip._vendor.packaging.utils import canonicalize_name
from pip._vendor.requests.exceptions import InvalidProxyURL
Expand Down Expand Up @@ -774,20 +775,24 @@ def create_os_error_message(
)
parts.append(".\n")

# Suggest the user to enable Long Paths if path length is
# more than 260
if (
WINDOWS
and error.errno == errno.ENOENT
and error.filename
and len(error.filename) > 260
):
parts.append(
"HINT: This error might have occurred since "
"this system does not have Windows Long Path "
"support enabled. You can find information on "
"how to enable this at "
"https://pip.pypa.io/warnings/enable-long-paths\n"
)
# On Windows, errors like EINVAL or ENOENT may occur
# if a file or folder name exceeds 255 characters,
# or if the full path exceeds 260 characters and long path support isn't enabled.
# This condition checks for such cases and adds a hint to the error output.

if WINDOWS and error.errno in (errno.EINVAL, errno.ENOENT) and error.filename:
if any(len(part) > 255 for part in Path(error.filename).parts):
parts.append(
"HINT: This error might be caused by a file or folder name exceeding "
"255 characters, which is a Windows limitation even if long paths "
"are enabled.\n "
)
if len(error.filename) > 260:
parts.append(
"HINT: This error might have occurred since "
"this system does not have Windows Long Path "
"support enabled. You can find information on "
"how to enable this at "
"https://pip.pypa.io/warnings/enable-long-paths\n"
)
return "".join(parts).strip() + "\n"
51 changes: 51 additions & 0 deletions tests/unit/test_command_install.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import errno
import sys
from unittest import mock

import pytest
Expand Down Expand Up @@ -120,6 +121,56 @@ def test_most_cases(
"Consider checking your local proxy configuration"
' with "pip config debug".\n',
),
# Testing both long path error (ENOENT)
# and long file/folder name error (EINVAL) on Windows
pytest.param(
OSError(errno.ENOENT, "No such file or directory", f"C:{'/a'*261}"),
False,
False,
"Could not install packages due to an OSError: "
f"[Errno 2] No such file or directory: 'C:{'/a'*261}'\n"
"HINT: This error might have occurred since "
"this system does not have Windows Long Path "
"support enabled. You can find information on "
"how to enable this at "
"https://pip.pypa.io/warnings/enable-long-paths\n",
marks=pytest.mark.skipif(
sys.platform != "win32", reason="Windows-specific filename length test"
),
),
pytest.param(
OSError(errno.EINVAL, "No such file or directory", f"C:/{'a'*256}"),
False,
False,
"Could not install packages due to an OSError: "
f"[Errno 22] No such file or directory: 'C:/{'a'*256}'\n"
"HINT: This error might be caused by a file or folder name exceeding "
"255 characters, which is a Windows limitation even if long paths "
"are enabled.\n",
marks=pytest.mark.skipif(
sys.platform != "win32", reason="Windows-specific filename length test"
),
),
pytest.param(
OSError(
errno.EINVAL, "No such file or directory", f"C:{'/a'*261}/{'b'*256}"
),
False,
False,
"Could not install packages due to an OSError: "
f"[Errno 22] No such file or directory: 'C:{'/a' * 261}/{'b' * 256}'\n"
"HINT: This error might be caused by a file or folder name exceeding "
"255 characters, which is a Windows limitation even if long paths "
"are enabled.\n "
"HINT: This error might have occurred since "
"this system does not have Windows Long Path "
"support enabled. You can find information on "
"how to enable this at "
"https://pip.pypa.io/warnings/enable-long-paths\n",
marks=pytest.mark.skipif(
sys.platform != "win32", reason="Windows-specific filename length test"
),
),
],
)
def test_create_os_error_message(
Expand Down
Loading