diff --git a/docs/source/changes.md b/docs/source/changes.md index 4e716409..3f7ce9b6 100644 --- a/docs/source/changes.md +++ b/docs/source/changes.md @@ -25,6 +25,7 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and - {pull}`573` removes the `pytask_execute_create_scheduler` hook. - {pull}`579` fixes an interaction with `--pdb` and `--trace` and task that return. The debugging modes swallowed the return and `None` was returned. Closes {issue}`574`. +- {pull}`581` simplifies the code for tracebacks and unpublishes some utility functions. ## 0.4.6 - 2024-03-13 diff --git a/docs/source/reference_guides/api.md b/docs/source/reference_guides/api.md index 22872173..4ec74a8e 100644 --- a/docs/source/reference_guides/api.md +++ b/docs/source/reference_guides/api.md @@ -334,7 +334,6 @@ resolution and execution. ## Tracebacks ```{eval-rst} -.. autofunction:: pytask.remove_internal_traceback_frames_from_exc_info .. autoclass:: pytask.Traceback ``` diff --git a/src/_pytask/build.py b/src/_pytask/build.py index e93c9ada..ef3fd857 100644 --- a/src/_pytask/build.py +++ b/src/_pytask/build.py @@ -13,7 +13,6 @@ from typing import Literal import click -from rich.traceback import Traceback from _pytask.capture_utils import CaptureMethod from _pytask.capture_utils import ShowCapture @@ -34,7 +33,7 @@ from _pytask.session import Session from _pytask.shared import parse_paths from _pytask.shared import to_list -from _pytask.traceback import remove_internal_traceback_frames_from_exc_info +from _pytask.traceback import Traceback if TYPE_CHECKING: from typing import NoReturn @@ -66,7 +65,7 @@ def pytask_unconfigure(session: Session) -> None: path.write_text(json.dumps(HashPathCache._cache)) -def build( # noqa: C901, PLR0912, PLR0913, PLR0915 +def build( # noqa: C901, PLR0912, PLR0913 *, capture: Literal["fd", "no", "sys", "tee-sys"] | CaptureMethod = CaptureMethod.FD, check_casing_of_paths: bool = True, @@ -257,9 +256,7 @@ def build( # noqa: C901, PLR0912, PLR0913, PLR0915 session = Session.from_config(config_) except (ConfigurationError, Exception): - exc_info = remove_internal_traceback_frames_from_exc_info(sys.exc_info()) - traceback = Traceback.from_exception(*exc_info) - console.print(traceback) + console.print(Traceback(sys.exc_info())) session = Session(exit_code=ExitCode.CONFIGURATION_FAILED) else: @@ -279,9 +276,7 @@ def build( # noqa: C901, PLR0912, PLR0913, PLR0915 session.exit_code = ExitCode.FAILED except Exception: # noqa: BLE001 - exc_info = remove_internal_traceback_frames_from_exc_info(sys.exc_info()) - traceback = Traceback.from_exception(*exc_info) - console.print(traceback) + console.print(Traceback(sys.exc_info())) session.exit_code = ExitCode.FAILED session.hook.pytask_unconfigure(session=session) diff --git a/src/_pytask/dag_command.py b/src/_pytask/dag_command.py index e41d4f37..9b7bdecb 100644 --- a/src/_pytask/dag_command.py +++ b/src/_pytask/dag_command.py @@ -10,7 +10,6 @@ import click import networkx as nx from rich.text import Text -from rich.traceback import Traceback from _pytask.click import ColoredCommand from _pytask.click import EnumChoice @@ -31,7 +30,7 @@ from _pytask.shared import parse_paths from _pytask.shared import reduce_names_of_multiple_nodes from _pytask.shared import to_list -from _pytask.traceback import remove_internal_traceback_frames_from_exc_info +from _pytask.traceback import Traceback class _RankDirection(enum.Enum): @@ -114,9 +113,8 @@ def dag(**raw_config: Any) -> int: except Exception: # noqa: BLE001 session.exit_code = ExitCode.FAILED - exc_info = remove_internal_traceback_frames_from_exc_info(sys.exc_info()) console.print() - console.print(Traceback.from_exception(*exc_info)) + console.print(Traceback(sys.exc_info())) console.rule(style="failed") session.hook.pytask_unconfigure(session=session) diff --git a/src/_pytask/traceback.py b/src/_pytask/traceback.py index 5282d7e3..fec29704 100644 --- a/src/_pytask/traceback.py +++ b/src/_pytask/traceback.py @@ -28,7 +28,6 @@ __all__ = [ "Traceback", - "remove_internal_traceback_frames_from_exc_info", "remove_traceback_from_exc_info", ] @@ -60,7 +59,7 @@ def __rich_console__( if self.exc_info and isinstance(self.exc_info[1], Exit): self.exc_info = remove_traceback_from_exc_info(self.exc_info) - filtered_exc_info = remove_internal_traceback_frames_from_exc_info( + filtered_exc_info = _remove_internal_traceback_frames_from_exc_info( self.exc_info, suppress=self.suppress ) @@ -80,7 +79,7 @@ def remove_traceback_from_exc_info( return (exc_info[0], exc_info[1], None) # type: ignore[return-value] -def remove_internal_traceback_frames_from_exc_info( +def _remove_internal_traceback_frames_from_exc_info( exc_info: OptionalExceptionInfo, suppress: tuple[Path, ...] = ( _PLUGGY_DIRECTORY, @@ -117,7 +116,7 @@ def _remove_internal_traceback_frames_from_exception( if exc is None: return exc - _, _, tb = remove_internal_traceback_frames_from_exc_info( + _, _, tb = _remove_internal_traceback_frames_from_exc_info( (type(exc), exc, exc.__traceback__) ) exc.__traceback__ = tb diff --git a/src/pytask/__init__.py b/src/pytask/__init__.py index b4dab4f0..41271e2c 100644 --- a/src/pytask/__init__.py +++ b/src/pytask/__init__.py @@ -71,7 +71,6 @@ from _pytask.session import Session from _pytask.task_utils import task from _pytask.traceback import Traceback -from _pytask.traceback import remove_internal_traceback_frames_from_exc_info from _pytask.typing import Product from _pytask.typing import is_task_function from _pytask.warnings_utils import WarningReport @@ -152,7 +151,6 @@ "parse_dependencies_from_task_function", "parse_products_from_task_function", "parse_warning_filter", - "remove_internal_traceback_frames_from_exc_info", "remove_marks", "set_marks", "storage",