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

Validation of python snippets #19102

Closed
Closed
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
1 change: 0 additions & 1 deletion cmake/developer_package/shellcheck/shellcheck.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ function(ie_shellcheck_process)
continue()
endif()

get_filename_component(dir_name "${script}" DIRECTORY)
string(REPLACE "${IE_SHELLCHECK_DIRECTORY}" "${CMAKE_BINARY_DIR}/shellcheck" output_file ${script})
set(output_file "${output_file}.txt")
get_filename_component(script_name "${script}" NAME)
Expand Down
40 changes: 36 additions & 4 deletions docs/snippets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,42 @@ endif()
# ADDITIONAL_INCLUDE_DIRECTORIES
# $<TARGET_PROPERTY:openvino::runtime,INTERFACE_INCLUDE_DIRECTORIES>)

#
# Check python snippets
#

if(ENABLE_PYTHON AND NOT CMAKE_CROSSCOMPILING)
find_package(PythonInterp REQUIRED)

file(GLOB_RECURSE PYTHON_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.py")
set(PYTHON_SNIPPETS_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/python_snippets")

if(OV_GENERATOR_MULTI_CONFIG)
set(PYTHON_BRIDGE_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/$<CONFIG>/python)
else()
set(PYTHON_BRIDGE_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/python)
endif()

foreach(python_snippet IN LISTS PYTHON_SOURCES)
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}" "${PYTHON_SNIPPETS_OUTPUT_DIR}" output_file ${python_snippet})
add_custom_command(OUTPUT ${output_file}
COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=${PYTHON_BRIDGE_OUTPUT_DIRECTORY}
${PYTHON_EXECUTABLE} ${python_snippet}
COMMAND ${CMAKE_COMMAND} -E touch ${output_file}
DEPENDS ${python_snippet} ie_api pyopenvino ov_frontends ov_plugins
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMENT "Check python docs snippet ${python_snippet}"
VERBATIM)
list(APPEND outputs ${output_file})
endforeach()

add_custom_target(${TARGET_NAME}_python ALL DEPENDS ${outputs})
endif()

#
# Example
#

# Detect OpenVINO
find_package(OpenVINO QUIET
PATHS "${CMAKE_BINARY_DIR}"
Expand All @@ -99,10 +135,6 @@ if(NOT OpenVINO_FOUND)
set(OpenVINO_DIR ${CMAKE_BINARY_DIR})
endif()

#
# Example
#

set(TARGET_NAME "ov_integration_snippet")
# [cmake:integration_example_cpp]
cmake_minimum_required(VERSION 3.10)
Expand Down
4 changes: 2 additions & 2 deletions docs/snippets/ov_dynamic_shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#! [import]

#! [reshape_undefined]
Core = ov.Core()
model = core.read_model(model.xml)
core = ov.Core()
model = core.read_model("model.xml")

# Set first dimension to be dynamic while keeping others static
model.reshape([-1, 3, 224, 224])
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/ov_multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def MULTI_0():

# Read a network in IR, PaddlePaddle, or ONNX format:
model = core.read_model(model_path)

# Option 1
# Pre-configure MULTI globally with explicitly defined devices,
# and compile the model on MULTI using the newly specified default device list.
Expand Down
3 changes: 2 additions & 1 deletion docs/snippets/ov_network_state_intro.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ def low_latency_2_example():
states = infer_request.query_state()
for state in states:
name = state.get_name()
if (name == state_name):
if name == state_name:
# some actions
#! [ov:low_latency_2]
pass

#! [ov:low_latency_2_use_parameters]
manager.register_pass(LowLatency2(False))
Expand Down