Skip to content

Commit 9456281

Browse files
authored
refactor: drop redundant exc_info parameter from backend exception wrapper (#1161)
## Description Drops the `exc_info` parameter from the backend exception wrapper. I don't recall why we had this originally - possibly for Python 2 compat? ## Changelog <!-- All PRs should include a changelog fragment in docs/changelog/ --> - [x] Added changelog fragment: `docs/changelog/<pr_number>.<type>.rst` - Types: `feature`, `bugfix`, `doc`, `removal`, `misc` - Example: `123.feature.rst` containing `` Add custom backend support - by :user:`yourname` `` ## Checklist - [x] Tests pass locally (`tox`) - [x] Code follows project style (`tox -e fix`) - [x] Type checks pass (`tox -e type`) - [x] Documentation builds (`tox -e docs`)
1 parent 3e7a445 commit 9456281

5 files changed

Lines changed: 9 additions & 25 deletions

File tree

docs/changelog/1161.removal.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove ``exc_info`` parameter and attribute from ``BuildBackendException``. - by :user:`layday`

src/build/__main__.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,9 @@ def _handle_build_error(*, env_dir: str | None, sdist_extract_dir: StrPath | Non
297297
_cprint('{yellow}TIP{reset} {}', hint, file=sys.stderr)
298298
_error(str(e))
299299

300-
if e.exc_info[0] is not None:
301-
tb_lines = traceback.format_exception(e.exc_info[0], e.exc_info[1], e.exc_info[2], limit=-1)
302-
tb = ''.join(tb_lines)
303-
else: # pragma: no cover
304-
tb = traceback.format_exc(limit=-1)
300+
inner_exception = e.exception
301+
tb_lines = traceback.format_exception(inner_exception, limit=-1)
302+
tb = ''.join(tb_lines)
305303
_cprint('\n{dim}{}{reset}\n', tb.strip('\n'))
306304
_cprint('{yellow}TIP{reset} {}', hint, file=sys.stderr)
307305
_error(str(e))

src/build/_builder.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -409,12 +409,8 @@ def _handle_backend(self, hook: str) -> Generator[None]:
409409
try:
410410
yield
411411
except pyproject_hooks.BackendUnavailable as exception:
412-
raise BuildBackendException(
413-
exception,
414-
f"Backend '{self._backend}' is not available.",
415-
sys.exc_info(),
416-
) from None
412+
raise BuildBackendException(exception, f"Backend '{self._backend}' is not available.") from None
417413
except subprocess.CalledProcessError as exception:
418414
raise BuildBackendException(exception, f'Backend subprocess exited when trying to invoke {hook}') from None
419415
except Exception as exception:
420-
raise BuildBackendException(exception, exc_info=sys.exc_info()) from None
416+
raise BuildBackendException(exception) from None

src/build/_exceptions.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
if TYPE_CHECKING:
77
import subprocess
8-
import types
98

109

1110
class BuildException(Exception):
@@ -23,15 +22,9 @@ def __init__(
2322
self,
2423
exception: Exception,
2524
description: str | None = None,
26-
exc_info: tuple[type[BaseException], BaseException, types.TracebackType] | tuple[None, None, None] = (
27-
None,
28-
None,
29-
None,
30-
),
3125
) -> None:
3226
super().__init__()
3327
self.exception = exception
34-
self.exc_info = exc_info
3528
self._description = description
3629

3730
def __str__(self) -> str:

tests/test_main.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -862,14 +862,10 @@ def test_entrypoint(mocker: pytest_mock.MockerFixture) -> None:
862862
def test_handle_build_error_build_backend_exception(mocker: pytest_mock.MockerFixture) -> None:
863863
mocker.patch('build.__main__._error', side_effect=SystemExit(1))
864864

865-
exc = ValueError('test error')
866-
try:
867-
raise exc
868-
except ValueError:
869-
exc_info = sys.exc_info()
870-
871865
with pytest.raises(SystemExit), build.__main__._handle_build_error(env_dir=None, sdist_extract_dir=None):
872-
raise build.BuildBackendException(exc, exc_info=exc_info)
866+
raise build.BuildBackendException(
867+
ValueError('test error'),
868+
)
873869

874870

875871
def test_handle_build_error_prints_debug_tip_on_subprocess_failure(

0 commit comments

Comments
 (0)