Improve missing image writer dependency hints#8989
Conversation
Signed-off-by: NiketGirdhar22 <niketgirdhar2004@gmail.com>
|
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 as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
Estimated code review effort: 3 (Moderate) | ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
monai/data/image_writer.py (1)
95-140: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueAdd
Returnssection toresolve_writerdocstring.The docstring now has
ArgsandRaisesbut is missing aReturnssection documenting the return type and value. As per coding guidelines, Google-style docstrings should describe each return value.📝 Proposed docstring addition
error_if_not_found: whether to raise an error if no suitable image writer is found. if True , raise an ``OptionalImportError``, otherwise return an empty tuple. Default is ``True``. + Returns: + A tuple of available ``ImageWriter`` classes matching the given extension. + Raises: OptionalImportError: When no registered writer is available. If candidate writers require missing optional dependencies, the error includes commands for installing them.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@monai/data/image_writer.py` around lines 95 - 140, The resolve_writer docstring is missing documentation for its return value. Add a Google-style Returns section to resolve_writer describing that it returns a tuple of available ImageWriter classes, or an empty tuple when error_if_not_found is false and no writer is available.Source: Path instructions
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@monai/data/image_writer.py`:
- Around line 95-140: The resolve_writer docstring is missing documentation for
its return value. Add a Google-style Returns section to resolve_writer
describing that it returns a tuple of available ImageWriter classes, or an empty
tuple when error_if_not_found is false and no writer is available.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 28492799-bf75-4726-b58a-c3e68c762102
📒 Files selected for processing (4)
monai/data/image_writer.pymonai/utils/module.pytests/data/test_image_rw.pytests/utils/test_require_pkg.py
Signed-off-by: NiketGirdhar22 <niketgirdhar2004@gmail.com>
|
Addressed the CodeRabbit Returns-section nitpick in commit efb6588. |
|
Thanks @NiketGirdhar22 for this version of the solution, it aligns with my original idea and looks good so far. If there's further work to be done please do so and we can review again. |
Fixes #7980.
Description
Improve the error raised when
resolve_writercannot find an available image writer by including actionable installation commands for the actual candidate backends.Rather than maintaining a separate extension-to-package table, this change records the missing dependency name on
OptionalImportErrorinrequire_pkg.resolve_writercollects that information from its registered candidate writers and formats one or more installation hints. This keeps the guidance aligned withSUPPORTED_WRITERS, including wildcard formats and custom registrations that userequire_pkg.For example, saving PNG without Pillow now reports:
This is a non-breaking, error-message-only enhancement.
I am aware of the existing proposals for #7980, particularly #8761, #8625, and #8240. This draft uses the package metadata approach previously suggested in the review of #8240 and is opened for maintainer guidance on whether to proceed independently or coordinate with an existing PR.
Changes
OptionalImportError.name.PILimport name to the installablepillowdistribution.OptionalImportErrorbehavior.Types of changes
./runtests.sh -f -u --net --coverage.Test results
tests.utils.test_require_pkg: 7 passedtests.utils.test_optional_import: 12 passedThe complete
tests.data.test_image_rwmodule requires optional image backends not installed in the minimal local environment. Its pre-existing NRRD assertion requiresitkornibabel; the new tests do not require those dependencies and pass independently.