2929)
3030from .register_checks import InspectorMessage , Importance
3131from .tools import get_s3_urls_and_dandi_paths
32- from .utils import FilePathType , PathType , OptionalListOfStrings
32+ from .utils import FilePathType , PathType , OptionalListOfStrings , robust_s3_read
3333
3434INTERNAL_CONFIGS = dict (dandi = Path (__file__ ).parent / "internal_configs" / "dandi.inspector_config.yaml" )
3535
@@ -462,51 +462,30 @@ def inspect_nwb(
462462 filterwarnings (action = "ignore" , message = "No cached namespaces found in .*" )
463463 filterwarnings (action = "ignore" , message = "Ignoring cached namespace .*" )
464464
465- def _collect_all_messages (
466- nwbfile_path : FilePathType , checks : list , driver : Optional [str ] = None , skip_validate : bool = False
467- ):
468- with pynwb .NWBHDF5IO (path = nwbfile_path , mode = "r" , load_namespaces = True , driver = driver ) as io :
469- if not skip_validate :
470- validation_errors = pynwb .validate (io = io )
471- for validation_error in validation_errors :
472- yield InspectorMessage (
473- message = validation_error .reason ,
474- importance = Importance .PYNWB_VALIDATION ,
475- check_function_name = validation_error .name ,
476- location = validation_error .location ,
477- file_path = nwbfile_path ,
478- )
479-
480- try :
481- nwbfile = io .read ()
482- for inspector_message in run_checks (nwbfile = nwbfile , checks = checks ):
483- inspector_message .file_path = nwbfile_path
484- yield inspector_message
485- except OSError as ex :
486- raise ex # propagate outside private
487- except Exception as ex :
465+ with pynwb .NWBHDF5IO (path = nwbfile_path , mode = "r" , load_namespaces = True , driver = driver ) as io :
466+ if not skip_validate :
467+ validation_errors = pynwb .validate (io = io )
468+ for validation_error in validation_errors :
488469 yield InspectorMessage (
489- message = traceback .format_exc (),
490- importance = Importance .ERROR ,
491- check_function_name = f"During io.read() - { type (ex )} : { str (ex )} " ,
470+ message = validation_error .reason ,
471+ importance = Importance .PYNWB_VALIDATION ,
472+ check_function_name = validation_error .name ,
473+ location = validation_error .location ,
492474 file_path = nwbfile_path ,
493475 )
494476
495- if driver != "ros3" :
496- return _collect_all_messages (
497- nwbfile_path = nwbfile_path , checks = checks , driver = driver , skip_validate = skip_validate
498- )
499- else :
500- retries = 0
501-
502- while retries < max_retries :
503- try :
504- retries += 1
505- return _collect_all_messages (
506- nwbfile_path = nwbfile_path , checks = checks , driver = driver , skip_validate = skip_validate
507- )
508- except OSError : # Cannot curl request
509- sleep (0.1 * 2 ** retries )
477+ try :
478+ nwbfile = robust_s3_read (command = io .read , max_retries = max_retries )
479+ for inspector_message in run_checks (nwbfile = nwbfile , checks = checks ):
480+ inspector_message .file_path = nwbfile_path
481+ yield inspector_message
482+ except Exception as ex :
483+ yield InspectorMessage (
484+ message = traceback .format_exc (),
485+ importance = Importance .ERROR ,
486+ check_function_name = f"During io.read() - { type (ex )} : { str (ex )} " ,
487+ file_path = nwbfile_path ,
488+ )
510489
511490
512491def run_checks (nwbfile : pynwb .NWBFile , checks : list ):
@@ -522,7 +501,7 @@ def run_checks(nwbfile: pynwb.NWBFile, checks: list):
522501 for nwbfile_object in nwbfile .objects .values ():
523502 if check_function .neurodata_type is None or issubclass (type (nwbfile_object ), check_function .neurodata_type ):
524503 try :
525- output = check_function ( nwbfile_object )
504+ output = robust_s3_read ( command = check_function , command_args = [ nwbfile_object ] )
526505 # if an individual check fails, include it in the report and continue with the inspection
527506 except Exception :
528507 output = InspectorMessage (
0 commit comments