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

[Py OV] Add deprecation warning for runtime module #27694

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/bindings/python/src/openvino/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
# # It is not compared with init files from openvino-dev package.
# #
# Import all public modules
from openvino import runtime as runtime
from openvino.utils import lazy_import
runtime = lazy_import("openvino.runtime")
from openvino import frontend as frontend
from openvino import helpers as helpers
from openvino import experimental as experimental
Expand Down
21 changes: 21 additions & 0 deletions src/bindings/python/src/openvino/runtime/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,27 @@
"""openvino module namespace, exposing factory functions for all ops and other classes."""
# noqa: F401

import warnings
warnings.simplefilter("always", DeprecationWarning)
import inspect
stack = inspect.stack()

if stack[-1].code_context is None: # python interactive mode
warnings.warn(
"The `openvino.runtime` module is deprecated and will be removed in the 2026.0 release. "
"Please replace `openvino.runtime` with `openvino` after 25.1 release.",
DeprecationWarning,
stacklevel=2
)
else:
warnings.warn(
"The `openvino.runtime` module is deprecated and will be removed in the 2026.0 release. "
"Please replace `openvino.runtime` with `openvino` after 25.1 release.\n"
f"{stack[-1].filename}:{stack[-1].lineno}:\n\t{stack[-1].code_context[0]}",
DeprecationWarning,
stacklevel=2
)

from openvino._pyopenvino import get_version

__version__ = get_version()
Expand Down
15 changes: 15 additions & 0 deletions src/bindings/python/src/openvino/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from functools import wraps
from typing import Callable, Any
from pathlib import Path
import importlib.util
from types import ModuleType


def _add_openvino_libs_to_search_path() -> None:
Expand Down Expand Up @@ -113,3 +115,16 @@ def __get__(self, obj: Any, cls: Any = None) -> Any:
_patch(func, deprecated(name, version, message, stacklevel))
return func
return decorator


def lazy_import(module_name: str) -> ModuleType:
spec = importlib.util.find_spec(module_name)
if spec is None or spec.loader is None:
raise ImportError(f"Module {module_name} not found")

loader = importlib.util.LazyLoader(spec.loader)
module = importlib.util.module_from_spec(spec)
sys.modules[module_name] = module

loader.exec_module(module)
return module
3 changes: 2 additions & 1 deletion tools/benchmark_tool/openvino/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
# # It is not compared with init files from openvino-dev package.
# #
# Import all public modules
from openvino import runtime as runtime
from openvino.utils import lazy_import
runtime = lazy_import("openvino.runtime")
from openvino import frontend as frontend
from openvino import helpers as helpers
from openvino import experimental as experimental
Expand Down
3 changes: 2 additions & 1 deletion tools/ovc/openvino/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
# # It is not compared with init files from openvino-dev package.
# #
# Import all public modules
from openvino import runtime as runtime
from openvino.utils import lazy_import
runtime = lazy_import("openvino.runtime")
from openvino import frontend as frontend
from openvino import helpers as helpers
from openvino import experimental as experimental
Expand Down
Loading