-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix paths & setup.py install * fix linter issues * remove extra spaces * fix CI issues * remove extra lines * fix indent
- Loading branch information
Showing
1 changed file
with
44 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
import errno | ||
import subprocess # nosec | ||
import typing | ||
import platform | ||
import multiprocessing | ||
from fnmatch import fnmatchcase | ||
from pathlib import Path | ||
|
@@ -19,18 +20,32 @@ | |
from setuptools import setup, find_namespace_packages, Extension | ||
from setuptools.command.build_ext import build_ext | ||
from setuptools.command.build_clib import build_clib | ||
from setuptools.command.install import install | ||
from decouple import config | ||
|
||
WHEEL_LIBS_INSTALL_DIR = os.path.join('openvino', 'libs') | ||
WHEEL_LIBS_PACKAGE = 'openvino.libs' | ||
PYTHON_VERSION = f'python{sys.version_info.major}.{sys.version_info.minor}' | ||
|
||
LIBS_DIR = 'bin' if platform.system() == 'Windows' else 'lib' | ||
CONFIG = 'Release' if platform.system() == 'Windows' else '' | ||
|
||
machine = platform.machine() | ||
if machine == 'x86_64' or machine == 'AMD64': | ||
ARCH = 'intel64' | ||
elif machine == 'X86': | ||
ARCH = 'ia32' | ||
elif machine == 'arm': | ||
ARCH = 'arm' | ||
elif machine == 'aarch64': | ||
ARCH = 'arm64' | ||
|
||
# The following variables can be defined in environment or .env file | ||
CMAKE_BUILD_DIR = config('CMAKE_BUILD_DIR', '.') | ||
CORE_LIBS_DIR = config('CORE_LIBS_DIR', 'deployment_tools/inference_engine/lib/intel64') | ||
PLUGINS_LIBS_DIR = config('PLUGINS_LIBS_DIR', 'deployment_tools/inference_engine/lib/intel64') | ||
CORE_LIBS_DIR = config('CORE_LIBS_DIR', f'deployment_tools/inference_engine/{LIBS_DIR}/{ARCH}/{CONFIG}') | ||
PLUGINS_LIBS_DIR = config('PLUGINS_LIBS_DIR', f'deployment_tools/inference_engine/{LIBS_DIR}/{ARCH}/{CONFIG}') | ||
NGRAPH_LIBS_DIR = config('NGRAPH_LIBS_DIR', 'deployment_tools/ngraph/lib') | ||
TBB_LIBS_DIR = config('TBB_LIBS_DIR', 'deployment_tools/inference_engine/external/tbb/lib') | ||
TBB_LIBS_DIR = config('TBB_LIBS_DIR', f'deployment_tools/inference_engine/external/tbb/{LIBS_DIR}') | ||
PY_PACKAGES_DIR = config('PY_PACKAGES_DIR', f'python/{PYTHON_VERSION}') | ||
LIBS_RPATH = '$ORIGIN' if sys.platform == 'linux' else '@loader_path' | ||
|
||
|
@@ -159,10 +174,10 @@ def run(self): | |
|
||
# if setup.py is directly called use CMake to build product | ||
if CMAKE_BUILD_DIR == '.': | ||
openvino_root_dir = os.path.normpath(os.path.join(CMAKE_BUILD_DIR, '../../../../')) | ||
self.announce('Configuring cmake project', level=3) | ||
|
||
self.spawn(['cmake', '-H' + openvino_root_dir, '-B' + self.build_temp, | ||
# set path to the root of OpenVINO CMakeList file | ||
openvino_root_dir = Path(__file__).resolve().parents[4] | ||
self.announce(f'Configuring cmake project: {openvino_root_dir}', level=3) | ||
self.spawn(['cmake', '-H' + str(openvino_root_dir), '-B' + self.build_temp, | ||
'-DCMAKE_BUILD_TYPE={type}'.format(type=self.config), | ||
'-DENABLE_PYTHON=ON', | ||
'-DNGRAPH_ONNX_FRONTEND_ENABLE=ON']) | ||
|
@@ -171,8 +186,8 @@ def run(self): | |
self.spawn(['cmake', '--build', self.build_temp, | ||
'--config', self.config, '-j', str(self.jobs)]) | ||
CMAKE_BUILD_DIR = self.build_temp | ||
|
||
self.run_command('build_clib') | ||
|
||
build.run(self) | ||
# Copy extra package_data content filtered by find_packages | ||
dst = Path(self.build_lib) | ||
|
@@ -237,6 +252,10 @@ class CopyExt(build_ext): | |
"""Copy extension files to the build directory""" | ||
|
||
def run(self): | ||
if len(self.extensions) == 1: | ||
self.run_command('build_clib') | ||
self.extensions = [] | ||
self.extensions = find_prebuilt_extensions(get_dir_list(PY_INSTALL_CFG)) | ||
for extension in self.extensions: | ||
if not isinstance(extension, PrebuiltExtension): | ||
raise DistutilsSetupError(f'copy_ext can accept PrebuiltExtension only, but got {extension.name}') | ||
|
@@ -251,10 +270,17 @@ def run(self): | |
elif sys.platform == 'darwin': | ||
rpath = os.path.join('@loader_path', rpath, WHEEL_LIBS_INSTALL_DIR) | ||
set_rpath(rpath, os.path.realpath(src)) | ||
|
||
copy_file(src, dst, verbose=self.verbose, dry_run=self.dry_run) | ||
|
||
|
||
class CustomInstall(install): | ||
"""Enable build_clib during the installation""" | ||
|
||
def run(self): | ||
self.run_command('build') | ||
install.run(self) | ||
|
||
|
||
class CustomClean(clean): | ||
"""Clean up staging directories""" | ||
|
||
|
@@ -350,6 +376,8 @@ def find_prebuilt_extensions(search_dirs): | |
ext_pattern = '**/*.so' | ||
for base_dir in search_dirs: | ||
for path in Path(base_dir).glob(ext_pattern): | ||
if path.match('openvino/libs/*'): | ||
continue | ||
relpath = path.relative_to(base_dir) | ||
if relpath.parent != '.': | ||
package_names = str(relpath.parent).split(os.path.sep) | ||
|
@@ -358,6 +386,8 @@ def find_prebuilt_extensions(search_dirs): | |
package_names.append(path.name.split('.', 1)[0]) | ||
name = '.'.join(package_names) | ||
extensions.append(PrebuiltExtension(name, sources=[str(path)])) | ||
if not extensions: | ||
extensions.append(PrebuiltExtension('openvino', sources=[str('setup.py')])) | ||
return extensions | ||
|
||
|
||
|
@@ -413,12 +443,13 @@ def get_package_dir(install_cfg): | |
|
||
packages = find_namespace_packages(get_package_dir(PY_INSTALL_CFG)) | ||
package_data: typing.Dict[str, list] = {} | ||
|
||
pkg_name = config('WHEEL_PACKAGE_NAME', 'openvino') | ||
ext_modules = find_prebuilt_extensions(get_dir_list(PY_INSTALL_CFG)) if pkg_name == 'openvino' else [] | ||
|
||
setup( | ||
version=config('WHEEL_VERSION', '0.0.0'), | ||
author_email=config('WHEEL_AUTHOR_EMAIL', '[email protected]'), | ||
name=config('WHEEL_PACKAGE_NAME', 'openvino'), | ||
name=pkg_name, | ||
license=config('WHEEL_LICENCE_TYPE', 'OSI Approved :: Apache Software License'), | ||
author=config('WHEEL_AUTHOR', 'Intel Corporation'), | ||
description=config('WHEEL_DESC', 'Inference Engine Python* API'), | ||
|
@@ -429,11 +460,12 @@ def get_package_dir(install_cfg): | |
url=config('WHEEL_URL', 'https://docs.openvinotoolkit.org/latest/index.html'), | ||
cmdclass={ | ||
'build': CustomBuild, | ||
'install': CustomInstall, | ||
'build_clib': PrepareLibs, | ||
'build_ext': CopyExt, | ||
'clean': CustomClean, | ||
}, | ||
ext_modules=find_prebuilt_extensions(get_dir_list(PY_INSTALL_CFG)), | ||
ext_modules=ext_modules, | ||
packages=packages, | ||
package_dir={'': get_package_dir(PY_INSTALL_CFG)}, | ||
package_data=package_data, | ||
|