diff --git a/CHANGELOG.md b/CHANGELOG.md index 80a94c15c..c5d9176a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Upcoming +### Improvements + +* Exposed progress bar control to `inspect_all` and `run_checks` to allow compatibility with more generic visualizations of inspection progress related to the NWB GUIDED. [#443](https://github.com/NeurodataWithoutBorders/nwbinspector/pull/443) + # v0.4.34 ### Fixes diff --git a/src/nwbinspector/__init__.py b/src/nwbinspector/__init__.py index bad199d9b..c73d0f208 100644 --- a/src/nwbinspector/__init__.py +++ b/src/nwbinspector/__init__.py @@ -1,6 +1,13 @@ from .version import __version__ from .register_checks import available_checks, Importance -from .nwbinspector import inspect_all, inspect_nwbfile, inspect_nwbfile_object, run_checks, load_config +from .nwbinspector import ( + InspectorOutputJSONEncoder, + inspect_all, + inspect_nwbfile, + inspect_nwbfile_object, + run_checks, + load_config, +) from .nwbinspector import inspect_nwb # TODO: remove after 7/1/2023 from .checks.ecephys import * from .checks.general import * diff --git a/src/nwbinspector/nwbinspector.py b/src/nwbinspector/nwbinspector.py index dd80b6de6..13a9ff014 100644 --- a/src/nwbinspector/nwbinspector.py +++ b/src/nwbinspector/nwbinspector.py @@ -581,9 +581,10 @@ def inspect_nwbfile( ) try: - nwbfile_object = robust_s3_read(command=io.read, max_retries=max_retries) + in_memory_nwbfile = robust_s3_read(command=io.read, max_retries=max_retries) + for inspector_message in inspect_nwbfile_object( - nwbfile_object=nwbfile_object, + nwbfile_object=in_memory_nwbfile, checks=checks, config=config, ignore=ignore, @@ -686,16 +687,39 @@ def inspect_nwbfile_object( yield inspector_message -def run_checks(nwbfile: pynwb.NWBFile, checks: list): +def run_checks( + nwbfile: pynwb.NWBFile, + checks: list, + progress_bar_class: Optional[tqdm] = None, + progress_bar_options: Optional[dict] = None, +) -> Iterable[InspectorMessage]: """ Run checks on an open NWBFile object. Parameters ---------- - nwbfile : NWBFile - checks : list + nwbfile : pynwb.NWBFile + The in-memory pynwb.NWBFile object to run the checks on. + checks : list of check functions + The list of check functions that will be run on the in-memory pynwb.NWBFile object. + progress_bar_class : type of tqdm.tqdm, optional + The specific child class of tqdm.tqdm to use to make progress bars. + Defaults to not displaying progress per set of checks over an invidiual file. + progress_bar_options : dict, optional + Dictionary of keyword arguments to pass directly to the `progress_bar_class`. + + Yields + ------ + results : a generator of InspectorMessage objects + A generator that returns a message on each iteration, if any are triggered by downstream conditions. + Otherwise, has length zero (if cast as `list`), or raises `StopIteration` (if explicitly calling `next`). """ - for check_function in checks: + if progress_bar_class is not None: + check_progress = progress_bar_class(iterable=checks, total=len(checks), **progress_bar_options) + else: + check_progress = checks + + for check_function in check_progress: for nwbfile_object in nwbfile.objects.values(): if check_function.neurodata_type is None or issubclass(type(nwbfile_object), check_function.neurodata_type): try: