Skip to content

Commit

Permalink
Reraise sensible errors from auto_chmod (#4593)
Browse files Browse the repository at this point in the history
  • Loading branch information
abravalheri authored Aug 27, 2024
2 parents 8ec5b5a + ef2957a commit 903604b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions newsfragments/4593.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Reraise error from ``setuptools.command.easy_install.auto_chmod`` instead of nonsensical ``TypeError: 'Exception' object is not subscriptable`` -- by :user:`Avasam`
13 changes: 8 additions & 5 deletions setuptools/command/easy_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from collections.abc import Iterable
from glob import glob
from sysconfig import get_path
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Callable, TypeVar

from jaraco.text import yield_lines

Expand Down Expand Up @@ -89,6 +89,8 @@
'get_exe_prefixes',
]

_T = TypeVar("_T")


def is_64bit():
return struct.calcsize("P") == 8
Expand Down Expand Up @@ -1786,13 +1788,14 @@ def _first_line_re():
return re.compile(first_line_re.pattern.decode())


def auto_chmod(func, arg, exc):
# Must match shutil._OnExcCallback
def auto_chmod(func: Callable[..., _T], arg: str, exc: BaseException) -> _T:
"""shutils onexc callback to automatically call chmod for certain functions."""
# Only retry for scenarios known to have an issue
if func in [os.unlink, os.remove] and os.name == 'nt':
chmod(arg, stat.S_IWRITE)
return func(arg)
et, ev, _ = sys.exc_info()
# TODO: This code doesn't make sense. What is it trying to do?
raise (ev[0], ev[1] + (" %s %s" % (func, arg))) # pyright: ignore[reportOptionalSubscript, reportIndexIssue]
raise exc


def update_dist_caches(dist_path, fix_zipimporter_caches):
Expand Down

0 comments on commit 903604b

Please sign in to comment.