-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix: print install hint when no suitable ImageWriter found #8761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -116,7 +116,22 @@ def resolve_writer(ext_name, error_if_not_found=True) -> Sequence: | |
| except Exception: # other writer init errors indicating it exists | ||
| avail_writers.append(_writer) | ||
| if not avail_writers and error_if_not_found: | ||
| raise OptionalImportError(f"No ImageWriter backend found for {fmt}.") | ||
| install_hints: dict = { | ||
| "nii": "nibabel", | ||
| "nii.gz": "nibabel", | ||
| "mha": "itk", | ||
| "mhd": "itk", | ||
| "nrrd": "itk", | ||
| "png": "pillow", | ||
| "jpg": "pillow", | ||
| "jpeg": "pillow", | ||
| "tif": "pillow", | ||
| "tiff": "pillow", | ||
| "bmp": "pillow", | ||
| } | ||
| hint = install_hints.get(fmt) | ||
| extra = f" Try installing the required package: pip install {hint}" if hint else "" | ||
| raise OptionalImportError(f"No ImageWriter backend found for '{fmt}'.{extra}") | ||
|
Comment on lines
+119
to
+134
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add regression tests for the new install-hint behavior. Line 119 through Line 134 changes user-facing error output and format mapping, but no tests are included here. Please add cases for As per coding guidelines, "Ensure new or modified definitions will be covered by existing or new unit tests." 🧰 Tools🪛 Ruff (0.15.2)[warning] 134-134: Avoid specifying long messages outside the exception class (TRY003) 🤖 Prompt for AI Agents |
||
| writer_tuple = ensure_tuple(avail_writers) | ||
| SUPPORTED_WRITERS[fmt] = writer_tuple | ||
| return writer_tuple | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would put this dictionary into a global variable at the top of this file. A name like
FILETYPE_HINTor something else sticking to the all-caps convention would work. This keeps the dictionary easily found and modifiable at runtime.