Skip to content

Commit 67e7aa2

Browse files
Visualization Lint (#169)
* - Fix not capturing error from visualization lint - enable linting of visualization table Close #134 * Fixed Problem in visualization due to wrong call and linbter not raising an error but just returning false.
1 parent 56bf65c commit 67e7aa2

2 files changed

Lines changed: 37 additions & 5 deletions

File tree

src/petab_gui/controllers/mother_controller.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -836,9 +836,10 @@ def new_file(self):
836836
def check_model(self):
837837
"""Check the consistency of the model. And log the results."""
838838
capture_handler = CaptureLogHandler()
839-
logger = logging.getLogger("petab.v1.lint") # Target the specific
840-
# logger
841-
logger.addHandler(capture_handler)
839+
logger_lint = logging.getLogger("petab.v1.lint")
840+
logger_vis = logging.getLogger("petab.v1.visualize.lint")
841+
logger_lint.addHandler(capture_handler)
842+
logger_vis.addHandler(capture_handler)
842843

843844
try:
844845
# Run the consistency check
@@ -871,7 +872,8 @@ def check_model(self):
871872
self.logger.log_message(msg, color="red")
872873
finally:
873874
# Always remove the capture handler
874-
logger.removeHandler(capture_handler)
875+
logger_lint.removeHandler(capture_handler)
876+
logger_vis.removeHandler(capture_handler)
875877

876878
def unsaved_changes_change(self, unsaved_changes: bool):
877879
self.unsaved_changes = unsaved_changes
@@ -1154,3 +1156,7 @@ def _show_help_welcome(self):
11541156
msg.exec()
11551157
if dont.isChecked():
11561158
settings.setValue("help_mode/welcome_disabled", True)
1159+
1160+
def get_current_problem(self):
1161+
"""Get the current PEtab problem from the model."""
1162+
return self.model.current_petab_problem

src/petab_gui/controllers/table_controllers.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Classes for the controllers of the tables in the GUI."""
22

3+
import logging
34
import re
45
from collections.abc import Sequence
56
from pathlib import Path
@@ -22,7 +23,12 @@
2223
PandasTableModel,
2324
)
2425
from ..settings_manager import settings_manager
25-
from ..utils import ConditionInputDialog, get_selected, process_file
26+
from ..utils import (
27+
CaptureLogHandler,
28+
ConditionInputDialog,
29+
get_selected,
30+
process_file,
31+
)
2632
from ..views.other_views import DoseTimeDialog
2733
from ..views.table_view import (
2834
ColumnSuggestionDelegate,
@@ -1316,6 +1322,26 @@ def __init__(
13161322
mother_controller=mother_controller,
13171323
)
13181324

1325+
@linter_wrapper(additional_error_check=True)
1326+
def check_petab_lint(
1327+
self,
1328+
row_data: pd.DataFrame = None,
1329+
row_name: str = None,
1330+
col_name: str = None,
1331+
):
1332+
"""Check a number of rows of the model with petablint."""
1333+
problem = self.mother_controller.get_current_problem()
1334+
capture_handler = CaptureLogHandler()
1335+
logger_vis = logging.getLogger("petab.v1.visualize.lint")
1336+
logger_vis.addHandler(capture_handler)
1337+
errors = petab.visualize.lint.validate_visualization_df(problem)
1338+
if not errors:
1339+
return not errors
1340+
captured_output = "<br>&nbsp;&nbsp;&nbsp;&nbsp;".join(
1341+
capture_handler.get_formatted_messages()
1342+
)
1343+
raise ValueError(captured_output)
1344+
13191345
def setup_completers(self):
13201346
"""Set completers for the visualization table."""
13211347
table_view = self.view.table_view

0 commit comments

Comments
 (0)