From c4f7461657159f0379c7a763cc708f16fbb4f7c7 Mon Sep 17 00:00:00 2001 From: Panaintescu Adrian-Valentin Date: Wed, 5 Jun 2024 14:30:39 +0300 Subject: [PATCH] hotfix co_qualname not available & safer sys exception --- examples/example01.py | 13 ++++++++++++- LICENSE.md => license.md | 0 pyproject.toml | 7 ++++--- README.md => readme.md | 3 ++- src/snap4frame/core/decoder.py | 4 ++-- src/snap4frame/core/handlers/exception.py | 19 +++++++++++-------- 6 files changed, 31 insertions(+), 15 deletions(-) rename LICENSE.md => license.md (100%) rename README.md => readme.md (94%) diff --git a/examples/example01.py b/examples/example01.py index 4639c96..0c478bb 100644 --- a/examples/example01.py +++ b/examples/example01.py @@ -1,7 +1,18 @@ import random import snap4frame - +import snap4frame.processor +import snap4frame.processor.kit + +snap4frame.setup_handler( + "default", + [ + snap4frame.processor.kit.FileSaveProcessor( + create_path=True, + exists_ok=True, + ), + ], +) snap4frame.init() diff --git a/LICENSE.md b/license.md similarity index 100% rename from LICENSE.md rename to license.md diff --git a/pyproject.toml b/pyproject.toml index d610acf..9dd8dcc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "snap4frame" -version = "0.1.0" +version = "0.1.1" description = "Creates a snapshot of the python program for later analysis" authors = [ { name = "Panaintescu Adrian Valentin", email = "adrian.cert@gmail.com" }, @@ -9,8 +9,8 @@ dependencies = [ "importlib-metadata>=7.0.1", ] requires-python = ">=3.8" -readme = "README.md" -license = { text = "GPL-3.0-or-later" } +readme = "readme.md" +license = { file = "license.md" } [project.optional-dependencies] "dev" = [ @@ -24,6 +24,7 @@ msgspec = [ requests = [ "requests>=2.31.0", ] + [build-system] requires = ["pdm-backend"] build-backend = "pdm.backend" diff --git a/README.md b/readme.md similarity index 94% rename from README.md rename to readme.md index eb68544..51d632c 100644 --- a/README.md +++ b/readme.md @@ -1,4 +1,5 @@ # **snap4frame** + ### creates a snapshot of the python program for later analysis **snap4frame** is a python package that creates a snapshot of your python program for later analysis. It's designed to help developers understand the state of their program at a specific point in time, which can be useful for debugging and performance optimization. @@ -50,4 +51,4 @@ We welcome contributions to snap4frame! Please see our [contributing guide](CONT ## License -Snap4frame is licensed under the [MIT License](LICENSE). +Snap4frame is licensed under the [MIT License](license.md). diff --git a/src/snap4frame/core/decoder.py b/src/snap4frame/core/decoder.py index dcdac2e..296d30a 100644 --- a/src/snap4frame/core/decoder.py +++ b/src/snap4frame/core/decoder.py @@ -25,7 +25,7 @@ class TracebackFrameDecoder(TracebackDecoder): config: types.Parameters = types.Parameters(config.FRAME_DECODER) def decode(self, data: TracebackType): - frame_name = data.tb_frame.f_code.co_qualname + frame_name = data.tb_frame.f_code.co_name frame_file = Path(data.tb_frame.f_code.co_filename) frame_locals = data.tb_frame.f_locals @@ -53,7 +53,7 @@ def decode(self, data: Optional[TracebackType]): iter_stack: Iterator[TracebackType] = reversed(raw_stack) for tb_obj in iter_stack: - frame_name = tb_obj.tb_frame.f_code.co_qualname + frame_name = tb_obj.tb_frame.f_code.co_name if self.config.exclude_frames and any( fnmatch(frame_name, pth) for pth in self.config.exclude_frames diff --git a/src/snap4frame/core/handlers/exception.py b/src/snap4frame/core/handlers/exception.py index 5612735..5268c5f 100644 --- a/src/snap4frame/core/handlers/exception.py +++ b/src/snap4frame/core/handlers/exception.py @@ -35,15 +35,18 @@ def handle_exception( Returns: None """ - traceback = exception.__traceback__ - stacktrace = list(self.traceback_decoder.decode(traceback)) - report = SnapFrameReport( - stacktrace=stacktrace, - context=self.context_reporter(), - value=str(exception), - ) + try: + traceback = exception.__traceback__ + stacktrace = list(self.traceback_decoder.decode(traceback)) + report = SnapFrameReport( + stacktrace=stacktrace, + context=self.context_reporter(), + value=str(exception), + ) - return self.event_handler.emit(report, kind=kind) + return self.event_handler.emit(report, kind=kind) + except Exception: + pass def exception_hook(self, type, value, traceback): """