Skip to content

Conversation

@songhahaha66
Copy link

Fixes #7980 .

Description

Add dependency hints to image writer errors

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • Breaking change (fix or new feature that would cause existing functionality to change).
  • New tests added to cover the changes.
  • Integration tests passed locally by running ./runtests.sh -f -u --net --coverage.
  • Quick tests passed locally by running ./runtests.sh --quick --unittests --disttests.
  • In-line docstrings updated.
  • Documentation updated, tested make html command in the docs/ folder.

Signed-off-by: songhahaha66 <songhahaha66@qq.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 5, 2025

Walkthrough

A dependency hints system is introduced to enhance error messages when image writers fail to load due to missing external packages. A new module-level dictionary WRITER_DEPENDENCY_HINTS maps writer classes to package names and installation commands. The resolve_writer function collects these hints when writers fail to import and constructs detailed error messages recommending specific package installations based on the requested image format. A corresponding test verifies error messages properly include the dependency hints.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Dictionary mappings: Verify WRITER_DEPENDENCY_HINTS correctly associates each writer class (ITKWriter, NibabelWriter, PILWriter) with the correct package names and installation commands
  • Error message construction: Check logic that differentiates between single vs. multiple hints and formats the final error message appropriately
  • Test coverage: Confirm the test properly validates that hints appear in error messages and cleanup is handled correctly

Pre-merge checks and finishing touches

✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed Title clearly summarizes the main change: adding dependency hints to image writer errors.
Description check ✅ Passed Description covers the fix reference, main change, and marks relevant checkbox items, though some optional fields remain unchecked.
Linked Issues check ✅ Passed Changes directly address issue #7980: error messages now include actionable dependency hints (package names and install commands) when writers are missing.
Out of Scope Changes check ✅ Passed All changes are scoped to the stated objective: adding dependency hints to image writer errors and testing the feature.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between e72145c and 6bbc534.

📒 Files selected for processing (2)
  • monai/data/image_writer.py (3 hunks)
  • tests/data/test_image_rw.py (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py

⚙️ CodeRabbit configuration file

Review the Python code for quality and correctness. Ensure variable names adhere to PEP8 style guides, are sensible and informative in regards to their function, though permitting simple names for loop and comprehension variables. Ensure routine names are meaningful in regards to their function and use verbs, adjectives, and nouns in a semantically appropriate way. Docstrings should be present for all definition which describe each variable, return value, and raised exception in the appropriate section of the Google-style of docstrings. Examine code for logical error or inconsistencies, and suggest what may be changed to addressed these. Suggest any enhancements for code improving efficiency, maintainability, comprehensibility, and correctness. Ensure new or modified definitions will be covered by existing or new unit tests.

Files:

  • tests/data/test_image_rw.py
  • monai/data/image_writer.py
🪛 Ruff (0.14.3)
monai/data/image_writer.py

121-121: Do not catch blind exception: Exception

(BLE001)


137-137: Avoid specifying long messages outside the exception class

(TRY003)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (19)
  • GitHub Check: min-dep-pytorch (2.7.1)
  • GitHub Check: min-dep-pytorch (2.8.0)
  • GitHub Check: min-dep-pytorch (2.6.0)
  • GitHub Check: min-dep-py3 (3.11)
  • GitHub Check: min-dep-py3 (3.12)
  • GitHub Check: min-dep-os (ubuntu-latest)
  • GitHub Check: min-dep-py3 (3.10)
  • GitHub Check: min-dep-pytorch (2.5.1)
  • GitHub Check: min-dep-os (macOS-latest)
  • GitHub Check: min-dep-py3 (3.9)
  • GitHub Check: min-dep-os (windows-latest)
  • GitHub Check: flake8-py3 (pytype)
  • GitHub Check: flake8-py3 (codeformat)
  • GitHub Check: quick-py3 (windows-latest)
  • GitHub Check: build-docs
  • GitHub Check: flake8-py3 (mypy)
  • GitHub Check: quick-py3 (ubuntu-latest)
  • GitHub Check: quick-py3 (macOS-latest)
  • GitHub Check: packaging
🔇 Additional comments (2)
tests/data/test_image_rw.py (1)

154-178: Hint coverage looks solid.
Thanks for validating the OptionalImportError surfaces both the package name and install command.

monai/data/image_writer.py (1)

110-137: Error hint messaging reads well.
The sorted hint aggregation keeps the OptionalImportError actionable without altering existing flows.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Print what package should be installed when suitable writer is missing

2 participants