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

[PyOV] Propagate errors on imports from runtime module #20273

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
21 changes: 9 additions & 12 deletions src/bindings/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,8 @@ ov_check_python_build_conditions()

# check __init__.py files alignment

function(ov_check_init_files_alignment)
function(ov_check_init_files_alignment init_files)
# check the files in pairs
list(APPEND init_files
"${OpenVINOPython_SOURCE_DIR}/src/openvino/__init__.py"
"${OpenVINOPython_SOURCE_DIR}/src/compatibility/openvino/__init__.py"
"${OpenVINO_SOURCE_DIR}/tools/mo/openvino/__init__.py"
"${OpenVINO_SOURCE_DIR}/tools/pot/openvino/__init__.py"
"${OpenVINO_SOURCE_DIR}/tools/ovc/openvino/__init__.py"
"${OpenVINO_SOURCE_DIR}/tools/benchmark_tool/openvino/__init__.py"
"${OpenVINO_SOURCE_DIR}/tools/openvino_dev/src/openvino/__init__.py")

list(LENGTH init_files init_files_count)
math(EXPR file_loop_range "${init_files_count}-2")
foreach(init_file_idx RANGE 0 ${file_loop_range})
Expand All @@ -145,12 +136,18 @@ function(ov_check_init_files_alignment)
RESULT_VARIABLE compare_result
)
if(compare_result EQUAL 1)
message(FATAL_ERROR "The __init__.py files are misaligned: ${file1} and ${file2}")
message(FATAL_ERROR "The runtime __init__.py files are misaligned: ${file1} and ${file2}")
endif()
endforeach()
endfunction()

ov_check_init_files_alignment()
set(INIT_FILES_RUNTIME
"${OpenVINOPython_SOURCE_DIR}/src/openvino/__init__.py"
"${OpenVINOPython_SOURCE_DIR}/src/compatibility/openvino/__init__.py"
"${OpenVINO_SOURCE_DIR}/tools/ovc/openvino/__init__.py"
"${OpenVINO_SOURCE_DIR}/tools/benchmark_tool/openvino/__init__.py")
Copy link
Contributor

@ilya-lavrenov ilya-lavrenov Oct 6, 2023

Choose a reason for hiding this comment

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

do we need all these runtime copies at all?
maybe we need to keep only "${OpenVINOPython_SOURCE_DIR}/src/openvino/__init__.py" ? All other runtime modules cannot be used without OpenVINO anyway


ov_check_init_files_alignment("${INIT_FILES_RUNTIME}")

ie_option(ENABLE_PYTHON "Enables OpenVINO Python API build" ${ENABLE_PYTHON_DEFAULT})

Expand Down
82 changes: 41 additions & 41 deletions src/bindings/python/src/compatibility/openvino/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,47 @@
except ImportError:
pass

# API 2.0
try:
# Import all public modules
from openvino import runtime as runtime
from openvino import frontend as frontend
from openvino import helpers as helpers
from openvino import preprocess as preprocess
from openvino import utils as utils
from openvino.runtime import properties as properties

# Import most important classes and functions from openvino.runtime
from openvino.runtime import Model
from openvino.runtime import Core
from openvino.runtime import CompiledModel
from openvino.runtime import InferRequest
from openvino.runtime import AsyncInferQueue

from openvino.runtime import Dimension
from openvino.runtime import Strides
from openvino.runtime import PartialShape
from openvino.runtime import Shape
from openvino.runtime import Layout
from openvino.runtime import Type
from openvino.runtime import Tensor
from openvino.runtime import OVAny

from openvino.runtime import compile_model
from openvino.runtime import get_batch
from openvino.runtime import set_batch
from openvino.runtime import serialize
from openvino.runtime import shutdown
from openvino.runtime import tensor_from_file
from openvino.runtime import save_model
from openvino.runtime import layout_helpers

# Set version for openvino package
from openvino.runtime import get_version
__version__ = get_version()
except ImportError:
import warnings
warnings.warn("openvino package has problems with imports!", ImportWarning, stacklevel=2)
# #
# # API 2.0
# # This __init__.py forces checking of runtime modules to propagate errors.
# # It is not compared with init files from openvino-dev package.
# #
# Import all public modules
from openvino import runtime as runtime
from openvino import frontend as frontend
from openvino import helpers as helpers
from openvino import preprocess as preprocess
from openvino import utils as utils
from openvino.runtime import properties as properties

# Import most important classes and functions from openvino.runtime
from openvino.runtime import Model
from openvino.runtime import Core
from openvino.runtime import CompiledModel
from openvino.runtime import InferRequest
from openvino.runtime import AsyncInferQueue

from openvino.runtime import Dimension
from openvino.runtime import Strides
from openvino.runtime import PartialShape
from openvino.runtime import Shape
from openvino.runtime import Layout
from openvino.runtime import Type
from openvino.runtime import Tensor
from openvino.runtime import OVAny

from openvino.runtime import compile_model
from openvino.runtime import get_batch
from openvino.runtime import set_batch
from openvino.runtime import serialize
from openvino.runtime import shutdown
from openvino.runtime import tensor_from_file
from openvino.runtime import save_model
from openvino.runtime import layout_helpers

# Set version for openvino package
from openvino.runtime import get_version
__version__ = get_version()

# Tools
try:
Expand Down
82 changes: 41 additions & 41 deletions src/bindings/python/src/openvino/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,47 @@
except ImportError:
pass

# API 2.0
try:
# Import all public modules
from openvino import runtime as runtime
from openvino import frontend as frontend
from openvino import helpers as helpers
from openvino import preprocess as preprocess
from openvino import utils as utils
from openvino.runtime import properties as properties

# Import most important classes and functions from openvino.runtime
from openvino.runtime import Model
from openvino.runtime import Core
from openvino.runtime import CompiledModel
from openvino.runtime import InferRequest
from openvino.runtime import AsyncInferQueue

from openvino.runtime import Dimension
from openvino.runtime import Strides
from openvino.runtime import PartialShape
from openvino.runtime import Shape
from openvino.runtime import Layout
from openvino.runtime import Type
from openvino.runtime import Tensor
from openvino.runtime import OVAny

from openvino.runtime import compile_model
from openvino.runtime import get_batch
from openvino.runtime import set_batch
from openvino.runtime import serialize
from openvino.runtime import shutdown
from openvino.runtime import tensor_from_file
from openvino.runtime import save_model
from openvino.runtime import layout_helpers

# Set version for openvino package
from openvino.runtime import get_version
__version__ = get_version()
except ImportError:
import warnings
warnings.warn("openvino package has problems with imports!", ImportWarning, stacklevel=2)
# #
# # API 2.0
# # This __init__.py forces checking of runtime modules to propagate errors.
# # It is not compared with init files from openvino-dev package.
# #
# Import all public modules
from openvino import runtime as runtime
from openvino import frontend as frontend
from openvino import helpers as helpers
from openvino import preprocess as preprocess
from openvino import utils as utils
from openvino.runtime import properties as properties

# Import most important classes and functions from openvino.runtime
from openvino.runtime import Model
from openvino.runtime import Core
from openvino.runtime import CompiledModel
from openvino.runtime import InferRequest
from openvino.runtime import AsyncInferQueue

from openvino.runtime import Dimension
from openvino.runtime import Strides
from openvino.runtime import PartialShape
from openvino.runtime import Shape
from openvino.runtime import Layout
from openvino.runtime import Type
from openvino.runtime import Tensor
from openvino.runtime import OVAny

from openvino.runtime import compile_model
from openvino.runtime import get_batch
from openvino.runtime import set_batch
from openvino.runtime import serialize
from openvino.runtime import shutdown
from openvino.runtime import tensor_from_file
from openvino.runtime import save_model
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we have convert_model here?

Copy link
Contributor

Choose a reason for hiding this comment

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

it's below in a separate try / catch block.

This is because if I use only python API from build folder, OVC is not there

from openvino.runtime import layout_helpers

# Set version for openvino package
from openvino.runtime import get_version
__version__ = get_version()

# Tools
try:
Expand Down
82 changes: 41 additions & 41 deletions tools/benchmark_tool/openvino/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,47 @@
except ImportError:
pass

# API 2.0
try:
# Import all public modules
from openvino import runtime as runtime
from openvino import frontend as frontend
from openvino import helpers as helpers
from openvino import preprocess as preprocess
from openvino import utils as utils
from openvino.runtime import properties as properties

# Import most important classes and functions from openvino.runtime
from openvino.runtime import Model
from openvino.runtime import Core
from openvino.runtime import CompiledModel
from openvino.runtime import InferRequest
from openvino.runtime import AsyncInferQueue

from openvino.runtime import Dimension
from openvino.runtime import Strides
from openvino.runtime import PartialShape
from openvino.runtime import Shape
from openvino.runtime import Layout
from openvino.runtime import Type
from openvino.runtime import Tensor
from openvino.runtime import OVAny

from openvino.runtime import compile_model
from openvino.runtime import get_batch
from openvino.runtime import set_batch
from openvino.runtime import serialize
from openvino.runtime import shutdown
from openvino.runtime import tensor_from_file
from openvino.runtime import save_model
from openvino.runtime import layout_helpers

# Set version for openvino package
from openvino.runtime import get_version
__version__ = get_version()
except ImportError:
import warnings
warnings.warn("openvino package has problems with imports!", ImportWarning, stacklevel=2)
# #
# # API 2.0
# # This __init__.py forces checking of runtime modules to propagate errors.
# # It is not compared with init files from openvino-dev package.
# #
# Import all public modules
from openvino import runtime as runtime
from openvino import frontend as frontend
from openvino import helpers as helpers
from openvino import preprocess as preprocess
from openvino import utils as utils
from openvino.runtime import properties as properties

# Import most important classes and functions from openvino.runtime
from openvino.runtime import Model
from openvino.runtime import Core
from openvino.runtime import CompiledModel
from openvino.runtime import InferRequest
from openvino.runtime import AsyncInferQueue

from openvino.runtime import Dimension
from openvino.runtime import Strides
from openvino.runtime import PartialShape
from openvino.runtime import Shape
from openvino.runtime import Layout
from openvino.runtime import Type
from openvino.runtime import Tensor
from openvino.runtime import OVAny

from openvino.runtime import compile_model
from openvino.runtime import get_batch
from openvino.runtime import set_batch
from openvino.runtime import serialize
from openvino.runtime import shutdown
from openvino.runtime import tensor_from_file
from openvino.runtime import save_model
from openvino.runtime import layout_helpers

# Set version for openvino package
from openvino.runtime import get_version
__version__ = get_version()

# Tools
try:
Expand Down
22 changes: 8 additions & 14 deletions tools/openvino_dev/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,8 @@ endforeach()

# check __init__.py files alignment

function(ov_check_init_files_alignment)
function(ov_check_init_files_alignment init_files)
# check the files in pairs
list(APPEND init_files
"${OpenVINO_SOURCE_DIR}/src/bindings/python/src/openvino/__init__.py"
"${OpenVINO_SOURCE_DIR}/src/bindings/python/src/compatibility/openvino/__init__.py"
"${OpenVINO_SOURCE_DIR}/tools/mo/openvino/__init__.py"
"${OpenVINO_SOURCE_DIR}/tools/pot/openvino/__init__.py"
"${OpenVINO_SOURCE_DIR}/tools/ovc/openvino/__init__.py"
"${OpenVINO_SOURCE_DIR}/tools/benchmark_tool/openvino/__init__.py"
"${OpenVINO_SOURCE_DIR}/tools/openvino_dev/src/openvino/__init__.py")

list(LENGTH init_files init_files_count)
math(EXPR file_loop_range "${init_files_count}-2")
foreach(init_file_idx RANGE 0 ${file_loop_range})
Expand All @@ -78,14 +69,17 @@ function(ov_check_init_files_alignment)
RESULT_VARIABLE compare_result
)
if(compare_result EQUAL 1)
message(STATUS ${file1})
message(STATUS ${file2})
message(FATAL_ERROR "The __init__.py files are misaligned: ${file1} and ${file2}")
message(FATAL_ERROR "The tools __init__.py files are misaligned: ${file1} and ${file2}")
endif()
endforeach()
endfunction()

ov_check_init_files_alignment()
set(INIT_FILES_TOOLS
"${OpenVINO_SOURCE_DIR}/tools/mo/openvino/__init__.py"
"${OpenVINO_SOURCE_DIR}/tools/pot/openvino/__init__.py"
"${OpenVINO_SOURCE_DIR}/tools/openvino_dev/src/openvino/__init__.py")

ov_check_init_files_alignment("${INIT_FILES_TOOLS}")

# openvino_dev build

Expand Down
Loading
Loading