Skip to content

Commit

Permalink
save errors from initialization, create dependency errors only during…
Browse files Browse the repository at this point in the history
… valid scans
  • Loading branch information
swashko committed Jan 12, 2024
1 parent 66a2beb commit 3674835
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
14 changes: 5 additions & 9 deletions modelscan/modelscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand All @@ -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}"
)
Expand All @@ -57,21 +58,16 @@ 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(
self,
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)
Expand Down
4 changes: 4 additions & 0 deletions modelscan/scanners/h5/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
4 changes: 4 additions & 0 deletions modelscan/scanners/keras/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions modelscan/scanners/saved_model/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 3674835

Please sign in to comment.