Enabled wheel packaging (#3582)
* Added onnx support for C samples * Added wheel packaging configuration * ADD cmake option * Small refactoring * Fixes for linux env * Fixed macOS issues * removed test code * Added requirements file * Added myriad plugin * [PIP] Runtime wheel packaging v2 * Added rpath logic * Setting rpath for bindings * Formatting fixes * Move target project 1 directory above * Added target dependencies * Added blacklist for runtime libs * Corrected blacklist scope * Added wheel packaging configuration * ADD cmake option * Small refactoring * Fixes for linux env * Fixed macOS issues * removed test code * Added requirements file * Added myriad plugin * [PIP] Runtime wheel packaging v2 * Added rpath logic * Setting rpath for bindings * Formatting fixes * Move target project 1 directory above * Added blacklist for runtime libs * Changed lib exstention om macOS * ADD cmake option * Revert "ADD cmake option" This reverts commit 36f98c713bb337a160f9af6c7c79c4371fdfc45f. * Revert "Changed lib exstention om macOS" This reverts commit 80086fe1230b64fbcf396de82bc731c10f738eae. * Revert "Merge branch 'feature/wheel_pack' of https://github.com/mryzhov/openvino into feature/wheel_pack" This reverts commit 7560d9ab55edc1f8877b83821542570060fb13d8, reversing changes made to c287798f994dcefc074a06ff7c3ef86222674cc7. * Revert "Added onnx support for C samples" This reverts commit 26c595ac136d99bd576d307d33ca15feb15f81e4. * Fixed merge issues * Fixed typo in mac tool * Code review fixes * Simplified deps and added fatal error code review fixes * Removed test data * Fixed setup.py review comments * Removed apache 2.0 license * Review fixes * fixed pylint issues * Fixed python api install directory * Using cmake detected python binary * Changed wheel build directory * Renamed subdir from install to wheel * Removed pylint log * Made license, description and requirements configurable by cmake options Those files may be changed in CI * Changed variable name * Glob instead of os.walk * Corrected package name in description * Added wheel building instructions to readme * small typo fix * Changes to support CI build 1) Setup.py can be run without cmake build 2) Wheel metadata can be set by environment variables 3) Cmake build uses configuration from .env file * Removed unused file
This commit is contained in:
@@ -8,6 +8,9 @@ cmake_minimum_required (VERSION 3.13)
|
||||
project (ie_python_api)
|
||||
|
||||
option(ENABLE_CONDA_FOLDER "Create output folder with conda python bindings" OFF)
|
||||
option(ENABLE_WHEEL "Create wheel package" OFF)
|
||||
|
||||
set(PYTHON_BRIDGE_CPACK_PATH "python")
|
||||
|
||||
string(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} ARCH)
|
||||
if(ARCH STREQUAL "x86_64" OR ARCH STREQUAL "amd64") # Windows detects Intel's 64-bit CPU as AMD64
|
||||
@@ -59,6 +62,10 @@ if (ENABLE_TESTS)
|
||||
add_subdirectory(src/openvino/test_utils)
|
||||
endif()
|
||||
|
||||
if(ENABLE_WHEEL)
|
||||
add_subdirectory(wheel)
|
||||
endif()
|
||||
|
||||
# Check Cython version
|
||||
if(CYTHON_VERSION VERSION_LESS "0.29")
|
||||
message(FATAL_ERROR "OpenVINO Python API needs at least Cython version 0.29, found version ${CYTHON_VERSION}")
|
||||
@@ -71,11 +78,11 @@ endif()
|
||||
ie_cpack_add_component(${PYTHON_VERSION} REQUIRED)
|
||||
|
||||
install(FILES requirements.txt
|
||||
DESTINATION python/${PYTHON_VERSION}
|
||||
DESTINATION ${PYTHON_BRIDGE_CPACK_PATH}/${PYTHON_VERSION}
|
||||
COMPONENT ${PYTHON_VERSION})
|
||||
|
||||
install(PROGRAMS src/openvino/__init__.py
|
||||
DESTINATION python/${PYTHON_VERSION}/openvino
|
||||
DESTINATION ${PYTHON_BRIDGE_CPACK_PATH}/${PYTHON_VERSION}/openvino
|
||||
COMPONENT ${PYTHON_VERSION})
|
||||
|
||||
ie_cpack(${PYTHON_VERSION})
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
- Microsoft\* Visual Studio 2015 or later on Windows\*
|
||||
- gcc 4.8 or later on Linux
|
||||
- Python 2.7 or higher on Linux\*
|
||||
- Python 3.4 or higher on Windows\*
|
||||
- Python 3.6 or higher on Windows\*
|
||||
|
||||
## Prerequisites
|
||||
|
||||
@@ -46,6 +46,27 @@ You need to run Inference Engine build with the following flags:
|
||||
Then build generated solution INFERENCE_ENGINE_DRIVER.sln using Microsoft\* Visual Studio or run `cmake --build . --config Release` to build from the command line.
|
||||
|
||||
|
||||
## Building Python wheel
|
||||
1) Install Inference Engine Python API dependencies:
|
||||
```bash
|
||||
pip3 install -r wheel/requirements-dev.txt
|
||||
```
|
||||
2) Install the *patchelf* tool on Linux only:
|
||||
```shellscript
|
||||
sudo apt install patchelf
|
||||
```
|
||||
3) Run Inference Engine build with the following options:
|
||||
|
||||
```shellscript
|
||||
-DENABLE_PYTHON=ON
|
||||
-DENABLE_WHEEL=ON
|
||||
```
|
||||
If you need to include other components to the package you need to enable them too.
|
||||
For example, to include ngraph python API:
|
||||
```shellscript
|
||||
-NGRAPH_PYTHON_BUILD_ENABLE=ON
|
||||
```
|
||||
|
||||
## Running sample
|
||||
|
||||
Before running the Python samples:
|
||||
|
||||
@@ -72,10 +72,10 @@ add_custom_command(TARGET ${TARGET_NAME}
|
||||
# install
|
||||
|
||||
install(TARGETS ${INSTALLED_TARGETS}
|
||||
RUNTIME DESTINATION python/${PYTHON_VERSION}/openvino/inference_engine COMPONENT ${PYTHON_VERSION}
|
||||
ARCHIVE DESTINATION python/${PYTHON_VERSION}/openvino/inference_engine COMPONENT ${PYTHON_VERSION}
|
||||
LIBRARY DESTINATION python/${PYTHON_VERSION}/openvino/inference_engine COMPONENT ${PYTHON_VERSION})
|
||||
RUNTIME DESTINATION ${PYTHON_BRIDGE_CPACK_PATH}/${PYTHON_VERSION}/openvino/inference_engine COMPONENT ${PYTHON_VERSION}
|
||||
ARCHIVE DESTINATION ${PYTHON_BRIDGE_CPACK_PATH}/${PYTHON_VERSION}/openvino/inference_engine COMPONENT ${PYTHON_VERSION}
|
||||
LIBRARY DESTINATION ${PYTHON_BRIDGE_CPACK_PATH}/${PYTHON_VERSION}/openvino/inference_engine COMPONENT ${PYTHON_VERSION})
|
||||
|
||||
install(PROGRAMS __init__.py
|
||||
DESTINATION python/${PYTHON_VERSION}/openvino/inference_engine
|
||||
DESTINATION ${PYTHON_BRIDGE_CPACK_PATH}/${PYTHON_VERSION}/openvino/inference_engine
|
||||
COMPONENT ${PYTHON_VERSION})
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
if sys.platform == "win32":
|
||||
# PIP installs openvino dlls 3 directories above in openvino.libs by default
|
||||
# and this path needs to be visible to the openvino modules
|
||||
#
|
||||
# If you're using a custom installation of openvino,
|
||||
# add the location of openvino dlls to your system PATH.
|
||||
openvino_dll = os.path.join(os.path.dirname(__file__), "..", "..", "..", "openvino.libs")
|
||||
os.environ["PATH"] = os.path.abspath(openvino_dll) + ";" + os.environ["PATH"]
|
||||
|
||||
from .ie_api import *
|
||||
__all__ = ['IENetwork', "TensorDesc", "IECore", "Blob", "PreProcessInfo", "get_version"]
|
||||
__version__ = get_version()
|
||||
|
||||
16
inference-engine/ie_bridges/python/wheel/.env.in
Normal file
16
inference-engine/ie_bridges/python/wheel/.env.in
Normal file
@@ -0,0 +1,16 @@
|
||||
WHEEL_PACKAGE_NAME=${WHEEL_PACKAGE_NAME}
|
||||
WHEEL_VERSION=${WHEEL_VERSION}
|
||||
WHEEL_LICENCE_TYPE=${WHEEL_LICENCE_TYPE}
|
||||
WHEEL_AUTHOR=${WHEEL_AUTHOR}
|
||||
WHEEL_AUTHOR_EMAIL=${WHEEL_AUTHOR_EMAIL}
|
||||
WHEEL_DESC=${WHEEL_DESC}
|
||||
WHEEL_LICENSE=${WHEEL_LICENSE}
|
||||
WHEEL_REQUIREMENTS=${WHEEL_REQUIREMENTS}
|
||||
WHEEL_OVERVIEW=${WHEEL_OVERVIEW}
|
||||
|
||||
CMAKE_BUILD_DIR=${CMAKE_BINARY_DIR}
|
||||
CORE_LIBS_DIR=${IE_CPACK_RUNTIME_PATH}
|
||||
PLUGINS_LIBS_DIR=${PLUGINS_LIBS_DIR}
|
||||
NGRAPH_LIBS_DIR=${NGRAPH_LIBS_DIR}
|
||||
TBB_LIBS_DIR=${TBB_LIBS_DIR}
|
||||
PY_PACKAGES_DIR=${PY_PACKAGES_DIR}
|
||||
49
inference-engine/ie_bridges/python/wheel/CMakeLists.txt
Normal file
49
inference-engine/ie_bridges/python/wheel/CMakeLists.txt
Normal file
@@ -0,0 +1,49 @@
|
||||
# Copyright (C) 2018-2021 Intel Corporation
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
set(WHEEL_PACKAGE_NAME "openvino" CACHE STRING "Name of the package")
|
||||
set(WHEEL_LICENCE_TYPE "OSI Approved :: Apache Software License" CACHE STRING "License type for the package")
|
||||
set(WHEEL_AUTHOR "Intel Corporation" CACHE STRING "Package author’s name")
|
||||
set(WHEEL_AUTHOR_EMAIL "openvino_pushbot@intel.com" CACHE STRING "Email address of the package author")
|
||||
set(WHEEL_DESC "Inference Engine Python* API" CACHE STRING "Short, summary description of the package")
|
||||
set(WHEEL_VERSION "0.0.0" CACHE STRING "Version of this release")
|
||||
set(WHEEL_BUILD "000" CACHE STRING "Build number of this release")
|
||||
set(WHEEL_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE" CACHE STRING "Wheel license file")
|
||||
set(WHEEL_REQUIREMENTS "${CMAKE_CURRENT_SOURCE_DIR}/meta/openvino.requirements.txt" CACHE STRING "Wheel requirements.txt file")
|
||||
set(WHEEL_OVERVIEW "${CMAKE_CURRENT_SOURCE_DIR}/meta/pypi_overview.md" CACHE STRING "WHEEL_AUTHOR detailed description")
|
||||
|
||||
set(SETUP_PY "${CMAKE_CURRENT_SOURCE_DIR}/setup.py")
|
||||
set(SETUP_ENV "${CMAKE_CURRENT_SOURCE_DIR}/.env.in")
|
||||
|
||||
set(CORE_LIBS_DIR ${IE_CPACK_RUNTIME_PATH})
|
||||
set(PLUGINS_LIBS_DIR ${IE_CPACK_RUNTIME_PATH})
|
||||
set(NGRAPH_LIBS_DIR ${IE_CPACK_IE_DIR}/../ngraph/lib)
|
||||
set(PY_PACKAGES_DIR ${PYTHON_BRIDGE_CPACK_PATH}/${PYTHON_VERSION})
|
||||
set(TBB_LIBS_DIR deployment_tools/inference_engine/external/tbb/lib)
|
||||
|
||||
|
||||
if(APPLE)
|
||||
set(WHEEL_PLATFORM macosx_10_15_x86_64)
|
||||
elseif(UNIX)
|
||||
set(WHEEL_PLATFORM manylinux2014_x86_64)
|
||||
elseif(WIN32)
|
||||
set(WHEEL_PLATFORM win_amd64)
|
||||
set(TBB_LIBS_DIR deployment_tools/inference_engine/external/tbb/bin)
|
||||
else()
|
||||
message(FATAL_ERROR "This platform is not supported")
|
||||
endif()
|
||||
|
||||
configure_file(${SETUP_ENV} "${CMAKE_CURRENT_SOURCE_DIR}/.env")
|
||||
|
||||
add_custom_target(ie_wheel ALL DEPENDS ie_libraries ie_plugins ie_api _pyngraph)
|
||||
|
||||
add_custom_command(TARGET ie_wheel
|
||||
POST_BUILD
|
||||
COMMAND ${PYTHON_EXECUTABLE} ${SETUP_PY} bdist_wheel
|
||||
--dist-dir ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/wheels
|
||||
--build=${WHEEL_BUILD}
|
||||
--plat-name=${WHEEL_PLATFORM}
|
||||
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
|
||||
COMMENT "Building Python wheel ${WHEEL_PACKAGE_NAME}"
|
||||
VERBATIM
|
||||
)
|
||||
@@ -0,0 +1 @@
|
||||
numpy>=1.16.3
|
||||
@@ -0,0 +1,32 @@
|
||||
## OpenVINO™ Toolkit
|
||||
|
||||
OpenVINO™ toolkit quickly deploys applications and solutions that emulate human vision. Based on Convolutional Neural Networks (CNNs), the toolkit extends computer vision (CV) workloads across Intel® hardware, maximizing performance. The OpenVINO™ toolkit includes the Deep Learning Deployment Toolkit (DLDT).
|
||||
|
||||
OpenVINO™ toolkit:
|
||||
|
||||
- Enables CNN-based deep learning inference on the edge
|
||||
- Supports heterogeneous execution across an Intel® CPU, Intel® Integrated Graphics, Intel® FPGA, Intel® Neural Compute Stick 2, and Intel® Vision Accelerator Design with Intel® Movidius™ VPUs
|
||||
- Speeds time-to-market via an easy-to-use library of computer vision functions and pre-optimized kernels
|
||||
- Includes optimized calls for computer vision standards, including OpenCV\* and OpenCL™
|
||||
|
||||
Operating Systems:
|
||||
- Ubuntu* 18.04 long-term support (LTS), 64-bit
|
||||
- Windows* 10, 64-bit
|
||||
- macOS* 10.15, 64-bit
|
||||
|
||||
## Install the Runtime Package Using the PyPI Repository
|
||||
1. Set up and update pip to the highest version:
|
||||
```sh
|
||||
python3 -m pip install --upgrade pip
|
||||
```
|
||||
2. Install the Intel® distribution of OpenVINO™ toolkit:
|
||||
```sh
|
||||
pip install openvino
|
||||
```
|
||||
|
||||
3. Verify that the package is installed:
|
||||
```sh
|
||||
python3 -c "from openvino.inference_engine import IECore"
|
||||
```
|
||||
|
||||
Now you are ready to develop and run your application.
|
||||
@@ -0,0 +1,3 @@
|
||||
setuptools>=53.0.0
|
||||
wheel>=0.36.2
|
||||
python-decouple>=3.4
|
||||
326
inference-engine/ie_bridges/python/wheel/setup.py
Normal file
326
inference-engine/ie_bridges/python/wheel/setup.py
Normal file
@@ -0,0 +1,326 @@
|
||||
"""
|
||||
Copyright (C) 2018-2021 Intel Corporation
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
This conversation was marked as resolved by dkurt
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
"""
|
||||
|
||||
import os.path
|
||||
import sys
|
||||
import errno
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from shutil import copyfile
|
||||
from distutils.command.install import install
|
||||
from distutils.command.build import build
|
||||
from distutils.errors import DistutilsSetupError
|
||||
from distutils.file_util import copy_file
|
||||
from setuptools import setup, find_packages, Extension
|
||||
from setuptools.command.build_ext import build_ext
|
||||
from setuptools.command.build_clib import build_clib
|
||||
from decouple import config
|
||||
|
||||
WHEEL_LIBS_INSTALL_DIR = "openvino.libs"
|
||||
PYTHON_VERSION = f"python{sys.version_info.major}.{sys.version_info.minor}"
|
||||
|
||||
# The following variables can be defined in environment or .env file
|
||||
CMAKE_BUILD_DIR = os.path.normpath(config('CMAKE_BUILD_DIR', "."))
|
||||
CORE_LIBS_DIR = os.path.normpath(config('CORE_LIBS_DIR', ''))
|
||||
PLUGINS_LIBS_DIR = os.path.normpath(config('PLUGINS_LIBS_DIR', ''))
|
||||
NGRAPH_LIBS_DIR = os.path.normpath(config('NGRAPH_LIBS_DIR', ''))
|
||||
TBB_LIBS_DIR = os.path.normpath(config('TBB_LIBS_DIR', ''))
|
||||
PY_PACKAGES_DIR = os.path.normpath(config('PY_PACKAGES_DIR', ''))
|
||||
LIBS_RPATH = "$ORIGIN" if sys.platform == "linux" else "@loader_path"
|
||||
|
||||
LIB_INSTALL_CFG = {
|
||||
"ie_libs": {
|
||||
'name': 'core',
|
||||
'prefix': 'libs.core',
|
||||
'install_dir': CORE_LIBS_DIR,
|
||||
'rpath': LIBS_RPATH,
|
||||
},
|
||||
"hetero_plugin": {
|
||||
'name': 'hetero',
|
||||
'prefix': 'libs.plugins',
|
||||
'install_dir': PLUGINS_LIBS_DIR,
|
||||
},
|
||||
"gpu_plugin": {
|
||||
'name': 'cldnn',
|
||||
'prefix': 'libs.plugins',
|
||||
'install_dir': PLUGINS_LIBS_DIR,
|
||||
},
|
||||
"cpu_plugin": {
|
||||
'name': 'mkldnn',
|
||||
'prefix': 'libs.plugins',
|
||||
'install_dir': PLUGINS_LIBS_DIR
|
||||
},
|
||||
"multi_plugin": {
|
||||
'name': 'multi',
|
||||
'prefix': 'libs.plugins',
|
||||
'install_dir': PLUGINS_LIBS_DIR
|
||||
},
|
||||
"myriad_plugin": {
|
||||
'name': 'myriad',
|
||||
'prefix': 'libs.plugins',
|
||||
'install_dir': PLUGINS_LIBS_DIR,
|
||||
},
|
||||
"ngraph_libs": {
|
||||
'name': 'ngraph',
|
||||
'prefix': 'libs.ngraph',
|
||||
'install_dir': NGRAPH_LIBS_DIR,
|
||||
'rpath': LIBS_RPATH,
|
||||
},
|
||||
"tbb_libs": {
|
||||
'name': 'tbb',
|
||||
'prefix': 'libs.tbb',
|
||||
'install_dir': TBB_LIBS_DIR
|
||||
},
|
||||
}
|
||||
|
||||
PY_INSTALL_CFG = {
|
||||
"ie_py": {
|
||||
'name': PYTHON_VERSION,
|
||||
'prefix': 'site-packages',
|
||||
'install_dir': PY_PACKAGES_DIR
|
||||
},
|
||||
"ngraph_py": {
|
||||
'name': f"pyngraph_{PYTHON_VERSION}",
|
||||
'prefix': 'site-packages',
|
||||
'install_dir': PY_PACKAGES_DIR
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class PrebuiltExtension(Extension):
|
||||
"""Initialize Extension"""
|
||||
def __init__(self, name, sources, *args, **kwargs):
|
||||
if len(sources) != 1:
|
||||
nln = '\n'
|
||||
raise DistutilsSetupError(
|
||||
f"PrebuiltExtension can accept only one source, but got: {nln}{nln.join(sources)}"
|
||||
)
|
||||
super().__init__(name, sources, *args, **kwargs)
|
||||
|
||||
|
||||
class CustomBuild(build):
|
||||
"""Custom implementation of build_clib"""
|
||||
def run(self):
|
||||
self.run_command('build_clib')
|
||||
build.run(self)
|
||||
|
||||
|
||||
class CustomInstall(install):
|
||||
"""Enable build_clib during the installation"""
|
||||
def run(self):
|
||||
self.run_command('build_clib')
|
||||
install.run(self)
|
||||
|
||||
|
||||
class PrepareLibs(build_clib):
|
||||
"""Prepare prebuilt libraries"""
|
||||
def run(self):
|
||||
self.configure(LIB_INSTALL_CFG)
|
||||
self.configure(PY_INSTALL_CFG)
|
||||
|
||||
def configure(self, install_cfg):
|
||||
"""Collect prebuilt libraries. Install them to the temp directories, set rpath."""
|
||||
for comp, comp_data in install_cfg.items():
|
||||
install_prefix = comp_data.get('prefix')
|
||||
install_dir = comp_data.get('install_dir')
|
||||
if install_dir and not os.path.isabs(install_dir):
|
||||
install_dir = os.path.join(install_prefix, install_dir)
|
||||
self.announce(f"Installing {comp}", level=3)
|
||||
self.spawn(["cmake",
|
||||
"--install", CMAKE_BUILD_DIR,
|
||||
"--prefix", install_prefix,
|
||||
"--component", comp_data.get('name')])
|
||||
# set rpath if applicable
|
||||
if sys.platform != "win32" and comp_data.get('rpath'):
|
||||
lib_pattern = "*.so" if sys.platform == "linux" else "*.dylib"
|
||||
for path in Path(install_dir).glob(lib_pattern):
|
||||
set_rpath(comp_data['rpath'], path)
|
||||
|
||||
|
||||
class CopyExt(build_ext):
|
||||
"""Copy extension files to the build directory"""
|
||||
def run(self):
|
||||
for extension in self.extensions:
|
||||
if not isinstance(extension, PrebuiltExtension):
|
||||
raise DistutilsSetupError(
|
||||
f"copy_ext can accept PrebuiltExtension only, but got {extension.name}")
|
||||
src = extension.sources[0]
|
||||
dst = self.get_ext_fullpath(extension.name)
|
||||
os.makedirs(os.path.dirname(dst), exist_ok=True)
|
||||
# setting relative path to find dlls
|
||||
if sys.platform != "win32":
|
||||
rpath = os.path.relpath(get_package_dir(PY_INSTALL_CFG), os.path.dirname(src))
|
||||
if sys.platform == "linux":
|
||||
rpath = os.path.join("$ORIGIN", rpath, WHEEL_LIBS_INSTALL_DIR)
|
||||
elif sys.platform == "darwin":
|
||||
rpath = os.path.join("@loader_path", rpath, WHEEL_LIBS_INSTALL_DIR)
|
||||
set_rpath(rpath, src)
|
||||
|
||||
copy_file(src, dst, verbose=self.verbose, dry_run=self.dry_run)
|
||||
|
||||
|
||||
def is_tool(name):
|
||||
"""Check if the command-line tool is available"""
|
||||
try:
|
||||
devnull = subprocess.DEVNULL
|
||||
subprocess.Popen([name], stdout=devnull, stderr=devnull).communicate()
|
||||
except OSError as error:
|
||||
if error.errno == errno.ENOENT:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def set_rpath(rpath, executable):
|
||||
"""Setting rpath for linux and macOS libraries"""
|
||||
print(f"Setting rpath {rpath} for {executable}")
|
||||
cmd = ""
|
||||
rpath_tool = ""
|
||||
if sys.platform == "linux":
|
||||
rpath_tool = "patchelf"
|
||||
cmd = [rpath_tool, "--set-rpath", rpath, executable]
|
||||
elif sys.platform == "darwin":
|
||||
rpath_tool = "install_name_tool"
|
||||
cmd = [rpath_tool, "-add_rpath", rpath, executable]
|
||||
else:
|
||||
sys.exit(f"Unsupported platform: {sys.platform}")
|
||||
|
||||
if is_tool(rpath_tool):
|
||||
ret_info = subprocess.run(cmd, check=True)
|
||||
if ret_info.returncode != 0:
|
||||
sys.exit(f"Could not set rpath: {rpath} for {executable}")
|
||||
else:
|
||||
sys.exit(f"Could not found {rpath_tool} on the system, "
|
||||
f"please make sure that this tool is installed")
|
||||
|
||||
|
||||
def find_data_files(src_dirs):
|
||||
"""Collect package data files from src_dirs"""
|
||||
# The install directory for data_files should be a relative path.
|
||||
# It is interpreted relative to the installation prefix
|
||||
# (Python’s sys.prefix for system installations; site.USER_BASE for user installations).
|
||||
if sys.platform == "win32":
|
||||
install_subdir = f"Lib/site-packages/{WHEEL_LIBS_INSTALL_DIR}"
|
||||
else:
|
||||
install_subdir = f"lib/{PYTHON_VERSION}/site-packages/{WHEEL_LIBS_INSTALL_DIR}"
|
||||
# additional blacklist filter, just to fix cmake install issues
|
||||
data_blacklist = ['.lib', '.pdb', '_debug.dll', '_debug.dylib']
|
||||
data_files = []
|
||||
for src_dir in src_dirs:
|
||||
local_base_dir = Path(src_dir)
|
||||
for file_path in local_base_dir.rglob('*'):
|
||||
file_name = os.path.basename(file_path)
|
||||
dir_name = os.path.dirname(file_path)
|
||||
if file_path.is_file() and not any(file_name.endswith(ext) for ext in data_blacklist):
|
||||
data_files.append([
|
||||
os.path.join(install_subdir, os.path.relpath(dir_name, local_base_dir)),
|
||||
[str(file_path)]
|
||||
])
|
||||
return data_files
|
||||
|
||||
|
||||
def find_prebuilt_extensions(search_dirs):
|
||||
"""collect prebuilt python extensions"""
|
||||
extensions = []
|
||||
ext_pattern = ""
|
||||
if sys.platform == "linux":
|
||||
ext_pattern = "**/*.so"
|
||||
elif sys.platform == "win32":
|
||||
ext_pattern = "**/*.pyd"
|
||||
elif sys.platform == "darwin":
|
||||
ext_pattern = "**/*.so"
|
||||
for base_dir in search_dirs:
|
||||
for path in Path(base_dir).glob(ext_pattern):
|
||||
relpath = path.relative_to(base_dir)
|
||||
if relpath.parent != ".":
|
||||
package_names = str(relpath.parent).split(os.path.sep)
|
||||
else:
|
||||
package_names = []
|
||||
package_names.append(path.name.split(".", 1)[0])
|
||||
name = ".".join(package_names)
|
||||
extensions.append(PrebuiltExtension(name, sources=[str(path)]))
|
||||
return extensions
|
||||
|
||||
|
||||
def get_description(desc_file_path):
|
||||
"""read description from README.md"""
|
||||
with open(desc_file_path, "r", encoding="utf-8") as fstream:
|
||||
description = fstream.read()
|
||||
return description
|
||||
|
||||
|
||||
def get_dependencies(requirements_file_path):
|
||||
"""read dependencies from requirements.txt"""
|
||||
with open(requirements_file_path, "r", encoding="utf-8") as fstream:
|
||||
dependencies = fstream.read()
|
||||
return dependencies
|
||||
|
||||
|
||||
def get_dir_list(install_cfg):
|
||||
"""collect all available directories with libs or python packages"""
|
||||
dirs = []
|
||||
for comp_info in install_cfg.values():
|
||||
cfg_prefix = comp_info.get('prefix')
|
||||
cfg_dir = comp_info.get('install_dir')
|
||||
if cfg_dir:
|
||||
if not os.path.isabs(cfg_dir):
|
||||
cfg_dir = os.path.join(cfg_prefix, cfg_dir)
|
||||
if cfg_dir not in dirs:
|
||||
dirs.append(cfg_dir)
|
||||
return dirs
|
||||
|
||||
|
||||
def get_package_dir(install_cfg):
|
||||
"""
|
||||
Get python package path based on config
|
||||
All the packages should be located in one directory
|
||||
"""
|
||||
py_package_path = ""
|
||||
dirs = get_dir_list(install_cfg)
|
||||
if len(dirs) != 0:
|
||||
# setup.py support only one package directory, all modules should be located there
|
||||
py_package_path = dirs[0]
|
||||
return py_package_path
|
||||
|
||||
|
||||
platforms = ["linux", "win32", "darwin"]
|
||||
if not any(pl in sys.platform for pl in platforms):
|
||||
sys.exit("Unsupported platform: {}, expected: {}".format(sys.platform, "linux, win32, darwin"))
|
||||
|
||||
# copy license file into the build directory
|
||||
package_license = config('WHEEL_LICENSE', '')
|
||||
if os.path.exists(package_license):
|
||||
copyfile(package_license, "LICENSE")
|
||||
|
||||
setup(
|
||||
version=config('WHEEL_VERSION', '0.0.0'),
|
||||
author_email=config('WHEEL_AUTHOR_EMAIL', 'openvino_pushbot@intel.com'),
|
||||
name=config('WHEEL_PACKAGE_NAME', 'openvino'),
|
||||
license=config('WHEEL_LICENCE_TYPE', 'OSI Approved :: Apache Software License'),
|
||||
author=config('WHEEL_AUTHOR', 'Intel Corporation'),
|
||||
description=config('WHEEL_DESC', 'Inference Engine Python* API'),
|
||||
install_requires=get_dependencies(config('WHEEL_REQUIREMENTS', "requirements.txt")),
|
||||
long_description=get_description(config('WHEEL_OVERVIEW', 'pypi_overview.md')),
|
||||
long_description_content_type="text/markdown",
|
||||
cmdclass={
|
||||
"build": CustomBuild,
|
||||
"install": CustomInstall,
|
||||
"build_clib": PrepareLibs,
|
||||
"build_ext": CopyExt,
|
||||
},
|
||||
ext_modules=find_prebuilt_extensions(get_dir_list(PY_INSTALL_CFG)),
|
||||
packages=find_packages(','.join(get_dir_list(PY_INSTALL_CFG))),
|
||||
package_dir={'': get_package_dir(PY_INSTALL_CFG)},
|
||||
data_files=find_data_files(get_dir_list(LIB_INSTALL_CFG)),
|
||||
zip_safe=False,
|
||||
)
|
||||
@@ -27,10 +27,15 @@ if sys.platform == "win32":
|
||||
# ngraph.dll is installed 3 directories above by default
|
||||
# and this path needs to be visible to the _pyngraph module
|
||||
#
|
||||
# If you're using a custom installation of nGraph,
|
||||
# add the location of ngraph.dll to your system PATH.
|
||||
ngraph_dll = os.path.join(os.path.dirname(__file__), "..", "..", "..")
|
||||
os.environ["PATH"] = os.path.abspath(ngraph_dll) + ";" + os.environ["PATH"]
|
||||
|
||||
# PIP installs openvino and ngraph dlls 2 directories above in openvino.libs by default
|
||||
# and this path needs to be visible to the _pyngraph modules
|
||||
#
|
||||
openvino_dlls = os.path.join(os.path.dirname(__file__), "..", "..", "openvino.libs")
|
||||
# If you're using a custom installation of openvino,
|
||||
# add the location of openvino dlls to your system PATH.
|
||||
os.environ["PATH"] = os.path.abspath(openvino_dlls) + ";" + os.path.abspath(ngraph_dll) + ";" + os.environ["PATH"]
|
||||
|
||||
from _pyngraph import Dimension
|
||||
from _pyngraph import Function
|
||||
|
||||
Reference in New Issue
Block a user