-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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 1 commit
b809c77
6a5238f
e35f6fd
c2274ff
5fc5be5
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,23 @@ 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}.") | ||
| # map common extensions to their required package | ||
| install_hints: dict = { | ||
| "nii": "nibabel", | ||
| "nii.gz": "nibabel", | ||
| "mha": "itk", | ||
| "mhd": "itk", | ||
| "nrrd": "itk", | ||
|
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. This list is not exhaustive. A longer list is available here. Also, NRRD format can have
Member
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. Hi @yashnaiduu please have a look into adding more to the dictionary. |
||
| "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}") | ||
|
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 | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.