Skip to content

Commit 681db29

Browse files
authored
Merge branch 'master' into vs/ci_test
2 parents 13803ae + 83e2c06 commit 681db29

File tree

18 files changed

+146
-34
lines changed

18 files changed

+146
-34
lines changed

.github/workflows/test_accuracy.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ jobs:
4444
pip install typing_extensions==4.12.2
4545
cmake ../tests/cpp/accuracy/
4646
make -j
47+
- name: Build CPP-PY Bindings
48+
run: |
49+
source venv/bin/activate
50+
pip install src/cpp/py_bindings
4751
- name: Run CPP Test
4852
run: |
4953
build/test_accuracy -d data -p tests/python/accuracy/public_scope.json
54+
- name: Run CPP-PY Bindings Test
55+
run: |
56+
source venv/bin/activate
57+
pip list
58+
pytest --data=./data --config=./tests/python/accuracy/public_scope.json tests/cpp/accuracy/test_bindings.py

examples/cpp/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ endmacro()
9292

9393
find_package(OpenCV REQUIRED COMPONENTS imgcodecs)
9494

95-
set (ENABLE_PY_BINDINGS OFF)
9695
add_subdirectory(../../src/cpp ${Samples_BINARY_DIR}/src/cpp)
9796

9897
add_example(NAME asynchronous_api SOURCES ./asynchronous_api/main.cpp DEPENDENCIES model_api)

src/cpp/CMakeLists.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
cmake_minimum_required(VERSION 3.26)
66

7-
option(ENABLE_PY_BINDINGS "Enables building python bindings package" ON)
8-
97
# Multi config generators such as Visual Studio ignore CMAKE_BUILD_TYPE. Multi config generators are configured with
108
# CMAKE_CONFIGURATION_TYPES, but limiting options in it completely removes such build options
119
get_property(GENERATOR_IS_MULTI_CONFIG_VAR GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
@@ -77,10 +75,6 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "^GNU|(Apple)?Clang$")
7775
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
7876
endif()
7977

80-
if (ENABLE_PY_BINDINGS)
81-
add_subdirectory(py_bindings)
82-
endif()
83-
8478
include(GenerateExportHeader)
8579

8680
generate_export_header(model_api)

src/cpp/py_bindings/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.whl
2+
*.dll
3+
*.so*

src/cpp/py_bindings/CMakeLists.txt

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,17 @@
22
# SPDX-License-Identifier: Apache-2.0
33
#
44

5+
cmake_minimum_required(VERSION 3.26)
6+
7+
if(WIN32)
8+
set(CMAKE_GENERATOR_TOOLSET "v142")
9+
endif()
10+
11+
12+
add_subdirectory(../ model_api/cpp)
13+
514
set(Python_FIND_VIRTUALENV FIRST)
15+
project(_vision_api LANGUAGES CXX)
616
find_package(Python COMPONENTS Interpreter Development REQUIRED)
717

818
execute_process(
@@ -11,17 +21,19 @@ execute_process(
1121
find_package(nanobind CONFIG REQUIRED)
1222

1323

14-
file(GLOB BINDINGS_SOURCES ./*.cpp)
15-
file(GLOB BINDINGS_HEADERS ./*.hpp)
24+
file(GLOB BINDINGS_SOURCES src/vision_api/*.cpp)
25+
file(GLOB BINDINGS_HEADERS src/vision_api/*.hpp)
1626

17-
nanobind_add_module(py_model_api NB_STATIC STABLE_ABI LTO ${BINDINGS_SOURCES} ${BINDINGS_HEADERS})
27+
message(INFO ${BINDINGS_SOURCES})
28+
29+
nanobind_add_module(_vision_api NB_STATIC STABLE_ABI LTO ${BINDINGS_SOURCES} ${BINDINGS_HEADERS})
30+
31+
set_target_properties(_vision_api PROPERTIES
32+
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
33+
)
1834

19-
target_link_libraries(py_model_api PRIVATE model_api)
35+
target_link_libraries(_vision_api PRIVATE model_api)
2036

21-
nanobind_add_stub(
22-
py_model_api_stub
23-
MODULE py_model_api
24-
OUTPUT py_model_api.pyi
25-
PYTHON_PATH $<TARGET_FILE_DIR:py_model_api>
26-
DEPENDS py_model_api
37+
install(TARGETS _vision_api
38+
LIBRARY DESTINATION vision_api # Same place relative to package
2739
)

src/cpp/py_bindings/pyproject.toml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[build-system]
2+
requires = ["scikit-build-core >=0.4.3", "nanobind >=1.3.2"]
3+
build-backend = "scikit_build_core.build"
4+
5+
[project]
6+
name = "vision_api"
7+
version = "0.3.0.2"
8+
requires-python = ">=3.9"
9+
authors = [
10+
{name = "Intel(R) Corporation"},
11+
]
12+
maintainers = [
13+
{name = "Intel(R) Corporation"},
14+
]
15+
description = "Model API: model wrappers and pipelines for inference with OpenVINO"
16+
readme = "../../python/README.md"
17+
classifiers = [
18+
"License :: OSI Approved :: Apache Software License",
19+
"Programming Language :: Python :: 3.9"
20+
]
21+
22+
[project.urls]
23+
Homepage = "https://github.com/open-edge-platform/model_api"
24+
25+
[tool.scikit-build]
26+
# Protect the configuration against future changes in scikit-build-core
27+
minimum-version = "0.4"
28+
# Setuptools-style build caching in a local directory
29+
build-dir = "build/{wheel_tag}"
30+
# Build stable ABI wheels for CPython 3.12+
31+
wheel.py-api = "cp312"
32+
sdist.include = ["*.so*"]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
try:
5+
from openvino import Core
6+
7+
_ = Core() # Triggers loading of shared libs like libopenvino.so
8+
except Exception as e:
9+
raise ImportError(f"Failed to initialize OpenVINO runtime: {e}")
10+
11+
from ._vision_api import ClassificationModel
12+
13+
__all__ = [ClassificationModel]
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)