Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyCBakerPhD committed Aug 23, 2024
1 parent 3d27550 commit ecec5b8
Show file tree
Hide file tree
Showing 4 changed files with 306 additions and 56 deletions.
8 changes: 7 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@
install_requires=install_requires,
# zarr<2.18.0 because of https://github.com/NeurodataWithoutBorders/nwbinspector/pull/460
extras_require=dict(dandi=["dandi>=0.39.2", "zarr<2.18.0", "remfile"], zarr=["hdmf_zarr>=0.3.0", "zarr<2.18.0"]),
entry_points={"console_scripts": ["nwbinspector=nwbinspector._inspection_cli:_inspect_all_cli"]},
entry_points={
"console_scripts": [
"nwbinspector=nwbinspector._nwb_inspection_cli:_inspect_all_cli",
"inspect_dandiset=nwbinspector._inspect_dandiset_cli:_inspect_dandiset_cli",
"inspect_dandi_file_path=nwbinspector._inspect_dandi_file_path_cli:_inspect_dandi_file_path_cli",
],
},
license="BSD-3-Clause",
classifiers=[
"Development Status :: 4 - Beta",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import click

from ._formatting import _get_report_header
from . import Importance, inspect_all, format_messages, print_to_console, save_report, __version__
from . import Importance, inspect_all, format_messages, print_to_console, save_report
from .utils import strtobool
from ._dandi_inspection import inspect_dandiset, inspect_dandi_file_path

Expand All @@ -22,7 +22,6 @@
required=True,
type=str,
)
@click.option("--modules", help="Modules to import prior to reading the file(s).")
@click.option(
"--report-file-path",
default=None,
Expand All @@ -37,43 +36,45 @@
@click.option("--ignore", help="Comma-separated names of checks to skip.")
@click.option("--select", help="Comma-separated names of checks to run.")
@click.option(
"--threshold",
default="BEST_PRACTICE_SUGGESTION",
type=click.Choice(["CRITICAL", "BEST_PRACTICE_VIOLATION", "BEST_PRACTICE_SUGGESTION"]),
"--importance_threshold",
help="Ignores tests with an assigned importance below this threshold.",
type=click.Choice(["CRITICAL", "BEST_PRACTICE_VIOLATION", "BEST_PRACTICE_SUGGESTION"]),
default="BEST_PRACTICE_SUGGESTION",
)
@click.option("--config", help="Name of config or path of config .yaml file that overwrites importance of checks.")
@click.option("--json-file-path", help="Write json output to this location.")
@click.option("--json-file-path", help="Write JSON output to this location.")
@click.option("--n-jobs", help="Number of jobs to use in parallel.", default=1)
@click.option("--skip-validate", help="Skip the PyNWB validation step.", is_flag=True)
@click.option(
"--skip-validate",
help="Skip the PyNWB validation step.",
is_flag=True,
required=False,
default=False,
)
@click.option(
"--detailed",
help=(
"If file_path is the last of 'levels' (the default), identical checks will be aggregated in the display. "
"Use '--detailed' to see the complete report."
"Use `--detailed` to see the complete report."
),
is_flag=True,
required=False,
default=False,
)
@click.option("--progress-bar", help="Set this flag to False to disable display of the progress bar.")
@click.option(
"--stream",
help=(
"Stream data from the DANDI archive. If the 'path' is a local copy of the target DANDISet, specifying this "
"flag will still force the data to be streamed instead of using the local copy. To use the local copy, simply "
"remove this flag. Requires the Read Only S3 (ros3) driver to be installed with h5py."
),
is_flag=True,
"--progress-bar",
help="Set this flag to False to disable display of the progress bar.",
type=str,
required=False,
)
@click.option(
"--version-id",
help=(
"When 'path' is a six-digit DANDISet ID, this further specifies which version of " "the DANDISet to inspect."
),
"--modules",
help="Modules to import prior to reading the file(s). Necessary for registration of custom checks functions.",
type=str,
required=False,
)
@click.version_option(__version__)
def _inspect_dandiset_cli(
path: str,
modules: Optional[str] = None,
dandiset_id: str,
report_file_path: str = None,
levels: str = None,
reverse: Optional[str] = None,
Expand All @@ -87,38 +88,20 @@ def _inspect_dandiset_cli(
skip_validate: bool = False,
detailed: bool = False,
progress_bar: Optional[str] = None,
stream: bool = False,
version_id: Optional[str] = None,
modules: Optional[str] = None,
):
"""
Run the NWBInspector via the command line.
path :
Path to either a local NWBFile, a local folder containing NWBFiles, a link to a dataset on
DANDI archive (i.e., https://dandiarchive.org/dandiset/{dandiset_id}/{version_id}), or a six-digit Dandiset ID.
"""
"""Run the NWBInspector via the command line."""
levels = ["importance", "file_path"] if levels is None else levels.split(",")
modules = [] if modules is None else modules.split(",")
reverse = [False] * len(levels) if reverse is None else [strtobool(x) for x in reverse.split(",")]
progress_bar = strtobool(progress_bar) if progress_bar is not None else True
modules = [] if modules is None else modules.split(",")

if config is not None:
config = load_config(filepath_or_keyword=config)
if stream:
url_path = path if path.startswith("https://") else None
if url_path:
dandiset_id, version_id = url_path.split("/")[-2:]
path = dandiset_id
assert url_path or re.fullmatch(
pattern="^[0-9]{6}$", string=path
), "'--stream' flag was enabled, but 'path' is neither a full link to the DANDI archive nor a DANDISet ID."
if Path(path).is_dir():
warn(
f"The local DANDISet '{path}' exists, but the '--stream' flag was used. "
"NWBInspector will use S3 streaming from DANDI. To use local data, remove the '--stream' flag."
)

messages = list(
inspect_all(
path=path,
inspect_dandiset(
dandiset_id=dandiset_id,
modules=modules,
ignore=ignore if ignore is None else ignore.split(","),
select=select if select is None else select.split(","),
Expand All @@ -131,13 +114,15 @@ def _inspect_dandiset_cli(
version_id=version_id,
)
)

if json_file_path is not None:
if Path(json_file_path).exists() and not overwrite:
raise FileExistsError(f"The file {json_file_path} already exists! Specify the '-o' flag to overwrite.")
with open(file=json_file_path, mode="w") as fp:
json_report = dict(header=_get_report_header(), messages=messages)
json.dump(obj=json_report, fp=fp, cls=InspectorOutputJSONEncoder)
print(f"{os.linesep*2}Report saved to {str(Path(json_file_path).absolute())}!{os.linesep}")

formatted_messages = format_messages(messages=messages, levels=levels, reverse=reverse, detailed=detailed)
print_to_console(formatted_messages=formatted_messages)
if report_file_path is not None:
Expand All @@ -146,7 +131,12 @@ def _inspect_dandiset_cli(


@click.command("--inspect_dandi_file_path")
@click.argument("path")
@click.option(
"--dandi_file_path",
help="The path to the Dandifile as seen on the archive; e.g., 'sub-123_ses-456+ecephys.nwb'.",
required=True,
type=str,
)
@click.option("--modules", help="Modules to import prior to reading the file(s).")
@click.option(
"--report-file-path",
Expand Down Expand Up @@ -195,8 +185,7 @@ def _inspect_dandiset_cli(
"When 'path' is a six-digit DANDISet ID, this further specifies which version of " "the DANDISet to inspect."
),
)
@click.version_option(__version__)
def _inspect_dandiset_cli(
def _inspect_dandi_file_path_cli(
path: str,
modules: Optional[str] = None,
report_file_path: str = None,
Expand Down
Loading

0 comments on commit ecec5b8

Please sign in to comment.