From 989f1d3cc9a0a7e0ab373c30e321c921c9cb5e57 Mon Sep 17 00:00:00 2001 From: PaulJonasJost Date: Mon, 22 Sep 2025 16:57:28 +0200 Subject: [PATCH 1/2] - Fix not capturing error from visualization lint - enable linting of visualization table Close #134 --- src/petab_gui/controllers/mother_controller.py | 14 ++++++++++---- src/petab_gui/controllers/table_controllers.py | 13 ++++++++++++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/petab_gui/controllers/mother_controller.py b/src/petab_gui/controllers/mother_controller.py index 5a72af0..1f1212b 100644 --- a/src/petab_gui/controllers/mother_controller.py +++ b/src/petab_gui/controllers/mother_controller.py @@ -836,9 +836,10 @@ def new_file(self): def check_model(self): """Check the consistency of the model. And log the results.""" capture_handler = CaptureLogHandler() - logger = logging.getLogger("petab.v1.lint") # Target the specific - # logger - logger.addHandler(capture_handler) + logger_lint = logging.getLogger("petab.v1.lint") + logger_vis = logging.getLogger("petab.v1.visualize.lint") + logger_lint.addHandler(capture_handler) + logger_vis.addHandler(capture_handler) try: # Run the consistency check @@ -867,7 +868,8 @@ def check_model(self): self.logger.log_message(msg, color="red") finally: # Always remove the capture handler - logger.removeHandler(capture_handler) + logger_lint.removeHandler(capture_handler) + logger_vis.removeHandler(capture_handler) def unsaved_changes_change(self, unsaved_changes: bool): self.unsaved_changes = unsaved_changes @@ -1150,3 +1152,7 @@ def _show_help_welcome(self): msg.exec() if dont.isChecked(): settings.setValue("help_mode/welcome_disabled", True) + + def get_current_problem(self): + """Get the current PEtab problem from the model.""" + return self.model.current_petab_problem diff --git a/src/petab_gui/controllers/table_controllers.py b/src/petab_gui/controllers/table_controllers.py index 0c99b0c..9f55a1d 100644 --- a/src/petab_gui/controllers/table_controllers.py +++ b/src/petab_gui/controllers/table_controllers.py @@ -71,7 +71,7 @@ def __init__( self.undo_stack = undo_stack self.model.undo_stack = undo_stack self.check_petab_lint_mode = True - if model.table_type in ["simulation", "visualization"]: + if model.table_type in ["simulation"]: self.check_petab_lint_mode = False self.mother_controller = mother_controller self.view.table_view.setModel(self.proxy_model) @@ -1315,3 +1315,14 @@ def __init__( undo_stack=undo_stack, mother_controller=mother_controller, ) + + @linter_wrapper(additional_error_check=True) + def check_petab_lint( + self, + row_data: pd.DataFrame = None, + row_name: str = None, + col_name: str = None, + ): + """Check a number of rows of the model with petablint.""" + problem = self.mother_controller.get_current_problem() + return petab.visualize.validate_visualization_df(problem) From afd9d621cd92881ef3e3b566fa823afeee0c08e2 Mon Sep 17 00:00:00 2001 From: PaulJonasJost Date: Tue, 23 Sep 2025 11:09:39 +0200 Subject: [PATCH 2/2] Fixed Problem in visualization due to wrong call and linbter not raising an error but just returning false. --- .../controllers/table_controllers.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/petab_gui/controllers/table_controllers.py b/src/petab_gui/controllers/table_controllers.py index 9f55a1d..b583ea1 100644 --- a/src/petab_gui/controllers/table_controllers.py +++ b/src/petab_gui/controllers/table_controllers.py @@ -1,5 +1,6 @@ """Classes for the controllers of the tables in the GUI.""" +import logging import re from collections.abc import Sequence from pathlib import Path @@ -22,7 +23,12 @@ PandasTableModel, ) from ..settings_manager import settings_manager -from ..utils import ConditionInputDialog, get_selected, process_file +from ..utils import ( + CaptureLogHandler, + ConditionInputDialog, + get_selected, + process_file, +) from ..views.other_views import DoseTimeDialog from ..views.table_view import ( ColumnSuggestionDelegate, @@ -1325,4 +1331,13 @@ def check_petab_lint( ): """Check a number of rows of the model with petablint.""" problem = self.mother_controller.get_current_problem() - return petab.visualize.validate_visualization_df(problem) + capture_handler = CaptureLogHandler() + logger_vis = logging.getLogger("petab.v1.visualize.lint") + logger_vis.addHandler(capture_handler) + errors = petab.visualize.lint.validate_visualization_df(problem) + if not errors: + return not errors + captured_output = "
    ".join( + capture_handler.get_formatted_messages() + ) + raise ValueError(captured_output)