-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Print missing packages to install when no suitable ImageWriter is found #9142
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 |
|---|---|---|
|
|
@@ -311,8 +311,18 @@ def __init__(self, required_version, name): | |
| class OptionalImportError(ImportError): | ||
| """ | ||
| Could not import APIs from an optional dependency. | ||
|
|
||
| Args: | ||
| msg: the error message. | ||
| pkg_name: name of the missing package that caused the import error, if known. | ||
| It is used to provide installation hints to the users. Defaults to ``None``. | ||
|
|
||
| """ | ||
|
|
||
| def __init__(self, msg: str = "", pkg_name: str | None = None): | ||
| super().__init__(msg) | ||
| self.pkg_name = pkg_name | ||
|
Comment on lines
+322
to
+324
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. 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win Preserve the
As per path instructions, “Review the Python code for quality and correctness.” 🤖 Prompt for AI AgentsSource: Path instructions |
||
|
|
||
|
|
||
| def optional_import( | ||
| module: str, | ||
|
|
@@ -464,6 +474,12 @@ def require_pkg( | |
| raise_error: if True, raise `OptionalImportError` error if the required package is not installed | ||
| or the version doesn't match requirement, if False, print the error in a warning. | ||
|
|
||
| Raises: | ||
| OptionalImportError: When ``raise_error`` is True and the required package is not installed or its | ||
| version doesn't match the requirement. The error records the name of the package to install | ||
| in ``pkg_name``, with the required version constraint appended when ``version`` is specified | ||
| (e.g. ``itk>=5.2``), so that installation hints install a compatible version. | ||
|
|
||
| """ | ||
|
|
||
| def _decorator(obj): | ||
|
|
@@ -476,7 +492,12 @@ def _wrapper(*args, **kwargs): | |
| if not has: | ||
| err_msg = f"required package `{pkg_name}` is not installed or the version doesn't match requirement." | ||
| if raise_error: | ||
| raise OptionalImportError(err_msg) | ||
| name = pkg_name | ||
| if version: | ||
| # record the version constraint so that installation hints install a compatible | ||
| # version; `>=` is assumed for any `version_checker` other than `exact_version` | ||
| name = f"{pkg_name}{'==' if version_checker is exact_version else '>='}{version}" | ||
|
Comment on lines
+497
to
+499
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. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Do not infer
As per path instructions, “Examine code for logical error or inconsistencies.” 🤖 Prompt for AI AgentsSource: Path instructions |
||
| raise OptionalImportError(err_msg, pkg_name=name) | ||
| else: | ||
| warnings.warn(err_msg) | ||
|
|
||
|
|
||
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.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Give version-mismatch errors an upgrade hint.
When
require_pkgrejects an installed package because its version does not match, Line 135 still recommendspip installwithout a version constraint. That command may leave the incompatible version in place. Preserve the failure reason and suggest an upgrade or the required version for this case.As per path instructions, “Examine code for logical error or inconsistencies.”
🤖 Prompt for AI Agents
Source: Path instructions