Fix: add package install hint to ImageWriter backend error message#8795
Fix: add package install hint to ImageWriter backend error message#8795Talhax55z wants to merge 3 commits intoProject-MONAI:devfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughThe Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
monai/data/image_writer.py (1)
119-119: Avoid static backend hints that can drift from actual writer registration.Line 119 hard-codes extension/package guidance and can go stale (for example, registered formats like
jpeg,bmp,tiff, andtifare not represented). Prefer deriving the hint from a single shared mapping or from registered writers so messaging stays accurate asinit()evolves.As per coding guidelines, "Suggest any enhancements for code improving efficiency, maintainability, comprehensibility, and correctness."
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@monai/data/image_writer.py` at line 119, The raise in ImageWriter where OptionalImportError is constructed uses a hard-coded hint string for packages/extensions; change it to compute the hint dynamically from the shared writer registry used by init() (e.g., derive supported extensions/packages from the module-level writer registry or mapping such as the writers registry used by ImageWriter/init/_writer_registry) and include that generated list in the error message instead of the static "'nibabel'...'Pillow'" text; update the OptionalImportError message construction to enumerate current registered formats (fmt alternatives) and, if you have a mapping of format→package names, build the suggested package list from that mapping so the message stays accurate as init() registers new writers.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@monai/data/image_writer.py`:
- Line 119: The raise in ImageWriter where OptionalImportError is constructed
uses a hard-coded hint string for packages/extensions; change it to compute the
hint dynamically from the shared writer registry used by init() (e.g., derive
supported extensions/packages from the module-level writer registry or mapping
such as the writers registry used by ImageWriter/init/_writer_registry) and
include that generated list in the error message instead of the static
"'nibabel'...'Pillow'" text; update the OptionalImportError message construction
to enumerate current registered formats (fmt alternatives) and, if you have a
mapping of format→package names, build the suggested package list from that
mapping so the message stays accurate as init() registers new writers.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: a01a476f-c35f-4d1d-a7a7-b666bd83f1ed
📒 Files selected for processing (1)
monai/data/image_writer.py
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@monai/data/image_writer.py`:
- Around line 119-124: The supported-format message currently includes the
wildcard key EXT_WILDCARD ("*") from SUPPORTED_WRITERS, which confuses users;
before building _supported, filter SUPPORTED_WRITERS.keys() to exclude
EXT_WILDCARD (or any literal "*") and then join/sort the remaining keys so the
OptionalImportError message lists only real formats—update the code around the
OptionalImportError raise (where _supported is computed) to perform this
filtering.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 4f4813af-57cc-4a0d-a92e-4db735bdfdd6
📒 Files selected for processing (1)
monai/data/image_writer.py
Fixes #7980
Description
When no suitable ImageWriter backend is found, the error message previously
only said "No ImageWriter backend found for {fmt}." which gives the user
no actionable information.
This change adds a clear install hint to the error message, telling the
user which package to install depending on their file format.
Types of changes
./runtests.sh -f -u --net --coverage../runtests.sh --quick --unittests --disttests.make htmlcommand in thedocs/folder.