Skip to content

Make OpenVINO fully optional in Anomalib #2719

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

Conversation

samet-akcay
Copy link
Contributor

📝 Description

This PR fixes an issue where OpenVINO was being imported at the module level, causing the dependency to be required even when not using OpenVINO functionality. The changes make OpenVINO truly optional by:

  • Moving the OpenVINO import inside a TYPE_CHECKING block
  • Using string literal type hints for OpenVINO types
  • Maintaining proper runtime checks for OpenVINO availability
  • 🛠️ Fixes How to cancel warnings #2694

✨ Changes

  • Moved from openvino.runtime.utils.data_helpers.wrappers import OVDict into a TYPE_CHECKING block
  • Changed type hint from OVDict to "OVDict" to avoid runtime import
  • Kept the runtime check module_available("openvino") in __init__

Benefits

  • Users can now run anomalib without OpenVINO installed
  • OpenVINO is only imported when actually using the OpenVINO inferencer
  • Type checking tools still work correctly
  • Follows Python best practices for optional dependencies

Select what type of change your PR is:

  • 🐞 Bug fix (non-breaking change which fixes an issue)
  • 🔨 Refactor (non-breaking change which refactors the code base)
  • 🚀 New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 Documentation update
  • 🔒 Security update

✅ Checklist

Before you submit your pull request, please make sure you have completed the following steps:

  • 📋 I have summarized my changes in the CHANGELOG and followed the guidelines for my type of change (skip for minor changes, documentation updates, and test enhancements).
  • 📚 I have made the necessary updates to the documentation (if applicable).
  • 🧪 I have written tests that support my changes and prove that my fix is effective or my feature works (if applicable).

For more information about code review checklists, see the Code Review Checklist.

Signed-off-by: Samet Akcay <samet.akcay@intel.com>
@samet-akcay samet-akcay merged commit 6e3a659 into open-edge-platform:main May 22, 2025
9 of 10 checks passed
@samet-akcay samet-akcay deleted the fix/convert-ovdict-import-for-type-checking branch May 22, 2025 14:38
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.

How to cancel warnings
2 participants