From 36748352849135c6de674e5f2099d1bd01be0aa0 Mon Sep 17 00:00:00 2001 From: Sam Washko Date: Thu, 11 Jan 2024 16:16:11 -0800 Subject: [PATCH] save errors from initialization, create dependency errors only during valid scans --- modelscan/modelscan.py | 14 +++++--------- modelscan/scanners/h5/scan.py | 4 ++++ modelscan/scanners/keras/scan.py | 4 ++++ modelscan/scanners/saved_model/scan.py | 4 ++++ 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/modelscan/modelscan.py b/modelscan/modelscan.py index 10fe267..2ab397e 100644 --- a/modelscan/modelscan.py +++ b/modelscan/modelscan.py @@ -26,6 +26,7 @@ def __init__( # Output self._issues = Issues() self._errors: List[Error] = [] + self._init_errors: List[Error] = [] self._skipped: List[str] = [] self._scanned: List[str] = [] self._input_path: str = "" @@ -47,7 +48,7 @@ def _load_scanners(self, scanners_to_load: List[str]) -> None: scanner_classes[scanner_path] = scanner_class except Exception as e: logger.error(f"Error importing scanner {scanner_path}") - self._errors.append( + self._init_errors.append( ModelScanError( scanner_path, f"Error importing scanner {scanner_path}: {e}" ) @@ -57,14 +58,7 @@ def _load_scanners(self, scanners_to_load: List[str]) -> None: for scanner_class, scanner in scanner_classes.items(): is_enabled: bool = self._settings["scanners"][scanner_class]["enabled"] if is_enabled: - dep_error = scanner.handle_binary_dependencies() - if dep_error: - logger.info( - f"Skipping {scanner.full_name()} as it is missing dependencies" - ) - self._errors.append(dep_error) - else: - scanners_to_run.append(scanner) + scanners_to_run.append(scanner) self._scanners_to_run = scanners_to_run def scan( @@ -72,6 +66,8 @@ def scan( path: Union[str, Path], ) -> Dict[str, Any]: self._issues = Issues() + self._errors = [] + self._errors.extend(self._init_errors) self._skipped = [] self._scanned = [] self._input_path = str(path) diff --git a/modelscan/scanners/h5/scan.py b/modelscan/scanners/h5/scan.py index ceac067..e992966 100644 --- a/modelscan/scanners/h5/scan.py +++ b/modelscan/scanners/h5/scan.py @@ -29,6 +29,10 @@ def scan( ): return None + dep_error = self.handle_binary_dependencies() + if dep_error: + return ScanResults([], [dep_error]) + if data: logger.warning( "H5 scanner got data bytes. It only support direct file scanning." diff --git a/modelscan/scanners/keras/scan.py b/modelscan/scanners/keras/scan.py index 8c13002..cf8cbe7 100644 --- a/modelscan/scanners/keras/scan.py +++ b/modelscan/scanners/keras/scan.py @@ -25,6 +25,10 @@ def scan( ): return None + dep_error = self.handle_binary_dependencies() + if dep_error: + return ScanResults([], [dep_error]) + try: with zipfile.ZipFile(data or source, "r") as zip: file_names = zip.namelist() diff --git a/modelscan/scanners/saved_model/scan.py b/modelscan/scanners/saved_model/scan.py index 8fa3ee4..e928ff8 100644 --- a/modelscan/scanners/saved_model/scan.py +++ b/modelscan/scanners/saved_model/scan.py @@ -35,6 +35,10 @@ def scan( ): return None + dep_error = self.handle_binary_dependencies() + if dep_error: + return ScanResults([], [dep_error]) + if data: results = self._scan(source, data)