Skip to content

Commit

Permalink
[PyOV] Propagate errors on imports from runtime module (openvinotoolk…
Browse files Browse the repository at this point in the history
…it#20273)

Co-authored-by: Michal Lukaszewski <[email protected]>
  • Loading branch information
2 people authored and alvoron committed Nov 6, 2023
1 parent d801739 commit 790a27a
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 190 deletions.
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")

ov_check_init_files_alignment("${INIT_FILES_RUNTIME}")

ov_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
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

0 comments on commit 790a27a

Please sign in to comment.