From e47d4b65e5932f1292cfa9c02f1f186d819bad37 Mon Sep 17 00:00:00 2001 From: David Manthey Date: Mon, 14 Oct 2024 10:58:03 -0400 Subject: [PATCH] Improve warnings Add warnings for when indices are not continuous from 0 --- slicer_cli_web/ctk_cli_adjustment.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/slicer_cli_web/ctk_cli_adjustment.py b/slicer_cli_web/ctk_cli_adjustment.py index a49a8e9..781249b 100644 --- a/slicer_cli_web/ctk_cli_adjustment.py +++ b/slicer_cli_web/ctk_cli_adjustment.py @@ -114,7 +114,7 @@ def parse(cls, elementTree): # noqa if self.index is not None: self.index = int(self.index) - if self.default: + if self.default is not None: try: self.default = self.parseValue(self.default) except ValueError as e: @@ -124,7 +124,7 @@ def parse(cls, elementTree): # noqa not self.isVector() and not self.isExternalType() and self.channel != 'output'): ctk_cli.module.logger.warning( - 'No provided for element of type <%s>', self.typ) + 'No provided for element of type <%s> (%s)', self.typ, self.name) if self.typ.endswith('-enumeration'): try: @@ -158,6 +158,26 @@ def _ctkCliParse(cls, elementTree): # noqa ctk_cli.module.CLIParameters.parse = _ctkCliParse +_orig_CLIModule_init = ctk_cli.CLIModule.__init__ + + +def _CLIModule_init(self, path=None, env=None, stream=None): + ret = _orig_CLIModule_init(self, path, env, stream) + indices = set() + for param in self.parameters(): + if param.index is not None: + idx = int(param.index) + if idx in indices: + ctk_cli.module.logger.warning('Parameter index %d used multiple times', idx) + indices.add(idx) + if len(indices) and (min(indices) < 0 or max(indices) >= len(indices)): + ctk_cli.module.logger.warning('Parameter indices are not continuous from 0 upwards') + + return ret + + +ctk_cli.CLIModule.__init__ = _CLIModule_init CLIModule = ctk_cli.CLIModule + __all__ = ['CLIModule']