Skip to content
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

feat: print packages to install #8240

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

vectorvp
Copy link
Contributor

@vectorvp vectorvp commented Nov 26, 2024

Fixes #7980. Closes #8001.

Description

A few sentences describing the changes proposed in this pull request.

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.

continue
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}.")
raise OptionalImportError(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please also include the test case in test_image_rw.py to ensure the change works as expected? Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KumoLiu, should it be added as a separate class?

@KumoLiu KumoLiu requested review from ericspod and Nic-Ma November 27, 2024 03:41
@KumoLiu
Copy link
Contributor

KumoLiu commented Nov 27, 2024

Please also sign-off to resolve the DCO issue: https://github.com/Project-MONAI/MONAI/pull/8240/checks?check_run_id=33542178018 Thanks!

Comment on lines +117 to +119
error_match = re.search(r"`(.*?)`", str(e))
if error_match:
required_pkg.append(error_match.group(1))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest you modify OptionalImportError to have a member recording the name of the package that isn't present so you don't have to do a re search. This would be used here like this raise OptionalImportError(err_msg, pkg_name) in place of the original line. The other place this is raised is here where the second argument could just be None.

Copy link
Contributor Author

@vectorvp vectorvp Nov 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ericspod, If I understand you correctly:

  1. The line here should be modified to
    raise OptionalImportError(err_msg, pkg_name)
  2. In image_writer I change this line to
    raise OptionalImportError(f"No ImageWriter backend found for {fmt}.", None)
  3. Remove exception lines with re.search in image_writer.
  4. And to make it all works I should modify OptionalImportError module in monai/utils/module.py by adding a functionality to track package names that aren't present?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ericspod, If I understand you correctly:

1. The line [here](https://github.com/Project-MONAI/MONAI/blob/e73257caa79309dcce1e93abf1632f4bfd75b11f/monai/utils/module.py#L473) should be modified to
   `raise OptionalImportError(err_msg, pkg_name)`

2. In image_writer I change this [line](https://github.com/Project-MONAI/MONAI/blob/dev/monai/data/image_writer.py#L119) to
   `raise OptionalImportError(f"No ImageWriter backend found for {fmt}.", None)`

3. Remove exception lines with re.search in image_writer.

4. And to make it all works I should modify `OptionalImportError` module in monai/utils/module.py by adding a functionality to track package names that aren't present?

I think that's it, that'll allow you to get the name of the package without assumptions about the exception's error string, it'll be a more robust way of doing this going forward. Thanks!

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
3 participants