Refactored setup.py; used pip wheel to build package (#17991)
This commit is contained in:
1 parent
dd02a0f440
commit
90a0e5f81a
3 files changed
+143
-132
No files matched your search
@@ -125,8 +125,8 @@ if(OpenVINO_SOURCE_DIR OR OpenVINODeveloperPackage_FOUND)
|
||||
|
||||
install(FILES ${OpenVINOPython_SOURCE_DIR}/requirements.txt
|
||||
DESTINATION ${OV_CPACK_PYTHONDIR}
|
||||
COMPONENT ${OV_CPACK_COMP_PYTHON_OPENVINO}_${pyversion}
|
||||
${OV_CPACK_COMP_PYTHON_OPENVINO_EXCLUDE_ALL})
|
||||
COMPONENT ${OV_CPACK_COMP_OPENVINO_DEV_REQ_FILES}
|
||||
${OV_CPACK_COMP_OPENVINO_DEV_REQ_FILES_EXCLUDE_ALL})
|
||||
|
||||
install(DIRECTORY ${OpenVINOPython_SOURCE_DIR}/tests
|
||||
DESTINATION tests/${PROJECT_NAME}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
#
|
||||
|
||||
include(${pyopenvino_SOURCE_DIR}/frontend/frontend_module.cmake)
|
||||
frontend_module(py_tensorflow_frontend tensorflow tests)
|
||||
frontend_module(py_tensorflow_frontend tensorflow ${OV_CPACK_COMP_PYTHON_OPENVINO}_${pyversion})
|
||||
+140
-129
@@ -42,109 +42,110 @@ elif machine == "aarch64" or machine == "arm64" or machine == "ARM64":
|
||||
|
||||
# The following variables can be defined in environment or .env file
|
||||
SCRIPT_DIR = Path(__file__).resolve().parents[0]
|
||||
CMAKE_BUILD_DIR = os.getenv("CMAKE_BUILD_DIR", ".")
|
||||
OPENVINO_BUILD_DIR = os.getenv("OPENVINO_BUILD_DIR", CMAKE_BUILD_DIR)
|
||||
OPENVINO_PYTHON_BUILD_DIR = os.getenv("OPENVINO_PYTHON_BUILD_DIR", CMAKE_BUILD_DIR)
|
||||
WORKING_DIR = Path.cwd()
|
||||
OPENVINO_SOURCE_DIR = SCRIPT_DIR.parents[3]
|
||||
OPENVINO_BUILD_DIR = os.getenv("OPENVINO_BUILD_DIR")
|
||||
OPENVINO_PYTHON_BUILD_DIR = os.getenv("OPENVINO_PYTHON_BUILD_DIR", OPENVINO_BUILD_DIR)
|
||||
OV_RUNTIME_LIBS_DIR = os.getenv("OV_RUNTIME_LIBS_DIR", f"runtime/{LIBS_DIR}/{ARCH}/{CONFIG}")
|
||||
TBB_LIBS_DIR = os.getenv("TBB_LIBS_DIR", f"runtime/3rdparty/tbb/{LIBS_DIR}")
|
||||
PUGIXML_LIBS_DIR = os.getenv("PUGIXML_LIBS_DIR", f"runtime/3rdparty/pugixml/{LIBS_DIR}")
|
||||
PY_PACKAGES_DIR = os.getenv("PY_PACKAGES_DIR", f"python/{PYTHON_VERSION}")
|
||||
PY_PACKAGES_DIR = os.getenv("PY_PACKAGES_DIR", "python")
|
||||
LIBS_RPATH = "$ORIGIN" if sys.platform == "linux" else "@loader_path"
|
||||
|
||||
LIB_INSTALL_CFG = {
|
||||
"ie_libs": {
|
||||
"name": "core",
|
||||
"prefix": "libs.core",
|
||||
"prefix": f"{WORKING_DIR}/build/libs.core",
|
||||
"install_dir": OV_RUNTIME_LIBS_DIR,
|
||||
"rpath": LIBS_RPATH,
|
||||
"binary_dir": OPENVINO_BUILD_DIR,
|
||||
},
|
||||
"hetero_plugin": {
|
||||
"name": "hetero",
|
||||
"prefix": "libs.hetero",
|
||||
"prefix": f"{WORKING_DIR}/build/libs.hetero",
|
||||
"install_dir": OV_RUNTIME_LIBS_DIR,
|
||||
"rpath": LIBS_RPATH,
|
||||
"binary_dir": OPENVINO_BUILD_DIR,
|
||||
},
|
||||
"gpu_plugin": {
|
||||
"name": "gpu",
|
||||
"prefix": "libs.gpu",
|
||||
"prefix": f"{WORKING_DIR}/build/libs.gpu",
|
||||
"install_dir": OV_RUNTIME_LIBS_DIR,
|
||||
"rpath": LIBS_RPATH,
|
||||
"binary_dir": OPENVINO_BUILD_DIR,
|
||||
},
|
||||
"cpu_plugin": {
|
||||
"name": "cpu",
|
||||
"prefix": "libs.cpu",
|
||||
"prefix": f"{WORKING_DIR}/build/libs.cpu",
|
||||
"install_dir": OV_RUNTIME_LIBS_DIR,
|
||||
"rpath": LIBS_RPATH,
|
||||
"binary_dir": OPENVINO_BUILD_DIR,
|
||||
},
|
||||
"multi_plugin": {
|
||||
"name": "multi",
|
||||
"prefix": "libs.multi",
|
||||
"prefix": f"{WORKING_DIR}/build/libs.multi",
|
||||
"install_dir": OV_RUNTIME_LIBS_DIR,
|
||||
"rpath": LIBS_RPATH,
|
||||
"binary_dir": OPENVINO_BUILD_DIR,
|
||||
},
|
||||
"batch_plugin": {
|
||||
"name": "batch",
|
||||
"prefix": "libs.batch",
|
||||
"prefix": f"{WORKING_DIR}/build/libs.batch",
|
||||
"install_dir": OV_RUNTIME_LIBS_DIR,
|
||||
"rpath": LIBS_RPATH,
|
||||
"binary_dir": OPENVINO_BUILD_DIR,
|
||||
},
|
||||
"tbb_libs": {
|
||||
"name": "tbb",
|
||||
"prefix": "libs.tbb",
|
||||
"prefix": f"{WORKING_DIR}/build/libs.tbb",
|
||||
"install_dir": TBB_LIBS_DIR,
|
||||
"rpath": LIBS_RPATH,
|
||||
"binary_dir": OPENVINO_BUILD_DIR,
|
||||
},
|
||||
"pugixml_libs": {
|
||||
"name": "pugixml",
|
||||
"prefix": "libs.pugixml",
|
||||
"prefix": f"{WORKING_DIR}/build/libs.pugixml",
|
||||
"install_dir": PUGIXML_LIBS_DIR,
|
||||
"binary_dir": OPENVINO_BUILD_DIR,
|
||||
},
|
||||
"ir_libs": {
|
||||
"name": "ir",
|
||||
"prefix": "libs.ir",
|
||||
"prefix": f"{WORKING_DIR}/build/libs.ir",
|
||||
"install_dir": OV_RUNTIME_LIBS_DIR,
|
||||
"rpath": LIBS_RPATH,
|
||||
"binary_dir": OPENVINO_BUILD_DIR,
|
||||
},
|
||||
"paddle_libs": {
|
||||
"name": "paddle",
|
||||
"prefix": "libs.paddle",
|
||||
"prefix": f"{WORKING_DIR}/build/libs.paddle",
|
||||
"install_dir": OV_RUNTIME_LIBS_DIR,
|
||||
"rpath": LIBS_RPATH,
|
||||
"binary_dir": OPENVINO_BUILD_DIR,
|
||||
},
|
||||
"pytorch_libs": {
|
||||
"name": "pytorch",
|
||||
"prefix": "libs.pytorch",
|
||||
"prefix": f"{WORKING_DIR}/build/libs.pytorch",
|
||||
"install_dir": OV_RUNTIME_LIBS_DIR,
|
||||
"rpath": LIBS_RPATH,
|
||||
"binary_dir": OPENVINO_BUILD_DIR,
|
||||
},
|
||||
"onnx_libs": {
|
||||
"name": "onnx",
|
||||
"prefix": "libs.onnx",
|
||||
"prefix": f"{WORKING_DIR}/build/libs.onnx",
|
||||
"install_dir": OV_RUNTIME_LIBS_DIR,
|
||||
"rpath": LIBS_RPATH,
|
||||
"binary_dir": OPENVINO_BUILD_DIR,
|
||||
},
|
||||
"tensorflow_libs": {
|
||||
"name": "tensorflow",
|
||||
"prefix": "libs.tensorflow",
|
||||
"prefix": f"{WORKING_DIR}/build/libs.tensorflow",
|
||||
"install_dir": OV_RUNTIME_LIBS_DIR,
|
||||
"rpath": LIBS_RPATH,
|
||||
"binary_dir": OPENVINO_BUILD_DIR,
|
||||
},
|
||||
"tensorflow_lite_libs": {
|
||||
"name": "tensorflow_lite",
|
||||
"prefix": "libs.tensorflow_lite",
|
||||
"prefix": f"{WORKING_DIR}/build/libs.tensorflow_lite",
|
||||
"install_dir": OV_RUNTIME_LIBS_DIR,
|
||||
"rpath": LIBS_RPATH,
|
||||
"binary_dir": OPENVINO_BUILD_DIR,
|
||||
@@ -152,21 +153,21 @@ LIB_INSTALL_CFG = {
|
||||
}
|
||||
|
||||
PY_INSTALL_CFG = {
|
||||
"ie_py": {
|
||||
"pyie": {
|
||||
"name": f"pyie_{PYTHON_VERSION}",
|
||||
"prefix": "site-packages",
|
||||
"prefix": f"{WORKING_DIR}/build/site-packages",
|
||||
"install_dir": PY_PACKAGES_DIR,
|
||||
"binary_dir": OPENVINO_PYTHON_BUILD_DIR,
|
||||
},
|
||||
"ngraph_py": {
|
||||
"pyngraph": {
|
||||
"name": f"pyngraph_{PYTHON_VERSION}",
|
||||
"prefix": "site-packages",
|
||||
"prefix": f"{WORKING_DIR}/build/site-packages",
|
||||
"install_dir": PY_PACKAGES_DIR,
|
||||
"binary_dir": OPENVINO_PYTHON_BUILD_DIR,
|
||||
},
|
||||
"pyopenvino": {
|
||||
"name": f"pyopenvino_{PYTHON_VERSION}",
|
||||
"prefix": "site-packages",
|
||||
"prefix": f"{WORKING_DIR}/build/site-packages",
|
||||
"install_dir": PY_PACKAGES_DIR,
|
||||
"binary_dir": OPENVINO_PYTHON_BUILD_DIR,
|
||||
},
|
||||
@@ -235,29 +236,33 @@ class CustomBuild(build):
|
||||
# if setup.py is directly called use CMake to build product
|
||||
if OPENVINO_BUILD_DIR == ".":
|
||||
# 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", "-S" + str(openvino_root_dir),
|
||||
self.announce(f"Configuring cmake project: {OPENVINO_SOURCE_DIR}", level=3)
|
||||
self.spawn(["cmake", "-S" + str(OPENVINO_SOURCE_DIR),
|
||||
"-B" + self.build_temp,
|
||||
self.cmake_args,
|
||||
"-DCMAKE_BUILD_TYPE={type}".format(type=self.config),
|
||||
"-DENABLE_PYTHON=ON",
|
||||
"-DBUILD_SHARED_LIBS=ON"
|
||||
"-DENABLE_WHEEL=OFF",
|
||||
"-DENABLE_NCC_STYLE=OFF",
|
||||
"-DENABLE_CPPLINT=OFF",
|
||||
"-DENABLE_TEMPLATE=OFF",
|
||||
"-DENABLE_COMPILE_TOOL=OFF"
|
||||
"-DENABLE_SAMPLES=OFF"])
|
||||
|
||||
self.announce("Building binaries", level=3)
|
||||
self.spawn(["cmake", "--build", self.build_temp,
|
||||
"--config", self.config,
|
||||
"-j", str(self.jobs)])
|
||||
"--parallel", str(self.jobs)])
|
||||
OPENVINO_BUILD_DIR = self.build_temp
|
||||
# perform installation
|
||||
self.run_command("build_clib")
|
||||
|
||||
build.run(self)
|
||||
# Copy extra package_data content filtered by find_packages
|
||||
dst = Path(self.build_lib)
|
||||
src = Path(get_package_dir(PY_INSTALL_CFG))
|
||||
|
||||
# Copy extra package_data content filtered by 'copy_package_data'
|
||||
exclude = ignore_patterns("*ez_setup*", "*__pycache__*", "*.egg-info*")
|
||||
src, dst = Path(PACKAGE_DIR), Path(self.build_lib)
|
||||
for path in src.glob("**/*"):
|
||||
if path.is_dir() or exclude(str(path)):
|
||||
continue
|
||||
@@ -267,12 +272,12 @@ class CustomBuild(build):
|
||||
|
||||
|
||||
class PrepareLibs(build_clib):
|
||||
"""Prepare prebuilt libraries."""
|
||||
"""Install prebuilt libraries."""
|
||||
|
||||
def run(self):
|
||||
self.configure(LIB_INSTALL_CFG)
|
||||
self.configure(PY_INSTALL_CFG)
|
||||
self.generate_package(get_install_dirs_list(LIB_INSTALL_CFG))
|
||||
self.copy_package_data(get_install_dirs_list(LIB_INSTALL_CFG))
|
||||
|
||||
def configure(self, install_cfg):
|
||||
"""Collect prebuilt libraries. Install them to the temp directories, set rpath."""
|
||||
@@ -280,7 +285,9 @@ class PrepareLibs(build_clib):
|
||||
install_prefix = comp_data.get("prefix")
|
||||
install_dir = comp_data.get("install_dir")
|
||||
binary_dir = comp_data.get("binary_dir")
|
||||
if install_dir and not os.path.isabs(install_dir):
|
||||
|
||||
# perform installation steps if we are not given a full path
|
||||
if not os.path.isabs(install_dir):
|
||||
self.announce(f"Installing {comp}", level=3)
|
||||
self.spawn(["cmake", "--install", binary_dir,
|
||||
"--prefix", install_prefix,
|
||||
@@ -288,6 +295,7 @@ class PrepareLibs(build_clib):
|
||||
"--strip",
|
||||
"--component", comp_data.get("name")])
|
||||
install_dir = os.path.join(install_prefix, install_dir)
|
||||
|
||||
# set rpath if applicable
|
||||
if sys.platform != "win32" and comp_data.get("rpath"):
|
||||
# after tbb libraries on mac arm64 are signed, setting rpath for them will report error:
|
||||
@@ -311,55 +319,69 @@ class PrepareLibs(build_clib):
|
||||
break
|
||||
return real_name
|
||||
|
||||
def generate_package(self, src_dirs):
|
||||
"""Collect package data files from preinstalled dirs and put all runtime libraries to the subpackage."""
|
||||
# additional blacklist filter, just to fix cmake install issues
|
||||
blacklist_patterns = ["^.*\\.lib$", "^.*\\.pdb$", "^.*_debug\\.dll$", "^.*_debug\\.\\d*\\.dylib$", "^.*_debug\\.so\\.\\d*$", "^.*\\.la$"]
|
||||
package_dir = os.path.join(get_package_dir(PY_INSTALL_CFG), WHEEL_LIBS_INSTALL_DIR)
|
||||
def resolve_symlinks(self, local_base_dir: Path):
|
||||
"""Resolves symlinks after installation via cmake install.
|
||||
|
||||
Wheel package content must not contain symlinks. The block handles two kinds of soft links,
|
||||
take the library on Linux as an example.
|
||||
1. The first case: there are two soft links pointing to the real file,
|
||||
- input is libX.so->libX.so.Y and libX.so.Y->libX.so.Y.Z (e.g. hwloc library in oneTBB package).
|
||||
- input is libX.so->libX.so.Y.Z and libX.so.Y->libX.so.Y.Z (e.g. oneTBB library).
|
||||
2. The second case: there is one soft link pointing to the real file.
|
||||
Process results of the above two cases: remove soft links(libX.so and libX.so.Y), rename libX.so.Y.Z to libX.so.Y.
|
||||
"""
|
||||
# step 1:
|
||||
# record real files and its symlinks {real file: soft link}
|
||||
# if there are two soft links pointing to the same file, like libX.so and libX.so.Y(including the above two cases),
|
||||
# only record the libX.so.Y and remove libX.so
|
||||
file_dict = {}
|
||||
for symlink in local_base_dir.rglob("*"):
|
||||
if symlink.is_symlink():
|
||||
real_name = self.get_reallink(symlink)
|
||||
if real_name in file_dict:
|
||||
link_file_name_old = os.path.basename(file_dict[real_name])
|
||||
link_file_name_new = os.path.basename(symlink)
|
||||
if len(link_file_name_new) > len(link_file_name_old):
|
||||
# replace libX.so/libX.dylib with libX.so.Y/libX.Y.dylib
|
||||
self.announce(f"Unlink symlink {file_dict[real_name]}, use {symlink} instead", level=3)
|
||||
os.unlink(file_dict[real_name])
|
||||
file_dict[real_name] = symlink
|
||||
else:
|
||||
self.announce(f"Unlink symlink {symlink}, use {file_dict[real_name]} instead", level=3)
|
||||
os.unlink(symlink)
|
||||
else:
|
||||
file_dict[real_name] = symlink
|
||||
|
||||
# step 2:
|
||||
# according to the corresponding relationship (file_dict),
|
||||
# remove the reserved soft link and rename the real file to the name of its soft link
|
||||
for real_name, symlink in file_dict.items():
|
||||
os.unlink(symlink)
|
||||
os.rename(real_name, symlink)
|
||||
self.announce(f"Resolved symlink {symlink} as {real_name}", level=3)
|
||||
|
||||
def copy_package_data(self, src_dirs):
|
||||
"""Collect package data files (clibs and other plugin support files) from preinstalled dirs and put all runtime libraries to the subpackage."""
|
||||
package_clibs_dir = os.path.join(PACKAGE_DIR, WHEEL_LIBS_INSTALL_DIR)
|
||||
os.makedirs(package_clibs_dir, exist_ok=True)
|
||||
|
||||
for src_dir in src_dirs:
|
||||
local_base_dir = Path(src_dir)
|
||||
# Wheel package content must not contain symlinks
|
||||
# the block handles two kinds of soft links, take the library on linux as an example
|
||||
# the first case: there are two soft links pointing to the real file,
|
||||
# input is libX.so->libX.so.Y and libX.so.Y->libX.so.Y.Z (e.g. hwloc library in oneTBB package)
|
||||
# input is libX.so->libX.so.Y.Z and libX.so.Y->libX.so.Y.Z (e.g. oneTBB library)
|
||||
# the second case: there is one soft link pointing to the real file
|
||||
# process results of the above two cases: remove soft links(libX.so and libX.so.Y), rename libX.so.Y.Z to libX.so.Y
|
||||
file_dict = {}
|
||||
# step 1:
|
||||
# record real files and its symlinks {real file: soft link}
|
||||
# if there are two soft links pointing to the same file, like libX.so and libX.so.Y(including the above two cases),
|
||||
# only record the libX.so.Y and remove libX.so
|
||||
for symlink in local_base_dir.rglob("*"):
|
||||
if symlink.is_symlink():
|
||||
real_name = self.get_reallink(symlink)
|
||||
if real_name in file_dict:
|
||||
link_file_name_old = os.path.basename(file_dict[real_name])
|
||||
link_file_name_new = os.path.basename(symlink)
|
||||
if len(link_file_name_new) > len(link_file_name_old):
|
||||
# replace libX.so/libX.dylib with libX.so.Y/libX.Y.dylib
|
||||
self.announce(f"Unlink symlink {file_dict[real_name]}, use {symlink} instead", level=3)
|
||||
os.unlink(file_dict[real_name])
|
||||
file_dict[real_name] = symlink
|
||||
else:
|
||||
self.announce(f"Unlink symlink {symlink}, use {file_dict[real_name]} instead", level=3)
|
||||
os.unlink(symlink)
|
||||
else:
|
||||
file_dict[real_name] = symlink
|
||||
self.resolve_symlinks(local_base_dir)
|
||||
|
||||
# step 2:
|
||||
# according to the corresponding relationship (file_dict),
|
||||
# remove the reserved soft link and rename the real file to the name of its soft link
|
||||
for real_name, symlink in file_dict.items():
|
||||
os.unlink(symlink)
|
||||
os.rename(real_name, symlink)
|
||||
self.announce(f"Resolved symlink {symlink} as {real_name}", level=3)
|
||||
# additional blacklist filter, just to fix cmake install issues
|
||||
blacklist_patterns = [ # static libraries and PBD files
|
||||
"^.*\\.a$", "^.*\\.lib$", "^.*\\.pdb$",
|
||||
# TBB debug libraries
|
||||
"^.*_debug\\.dll$", "^.*_debug\\.\\d*\\.dylib$", "^.*_debug\\.so\\.\\d*$",
|
||||
# hwloc static libs on Windows
|
||||
"^.*\\.la$"]
|
||||
|
||||
# copy so / dylib files to WHEEL_LIBS_INSTALL_DIR
|
||||
# copy so / dylib files to WHEEL_LIBS_INSTALL_DIR (clibs) inside python package
|
||||
for file_path in local_base_dir.rglob("*"):
|
||||
file_name = os.path.basename(file_path)
|
||||
if file_path.is_symlink():
|
||||
# sanity check for self.resolve_symlinks
|
||||
sys.exit(f"Wheel package content must not contain symlinks {file_path}")
|
||||
blacklisted = False
|
||||
for pattern in blacklist_patterns:
|
||||
@@ -367,12 +389,11 @@ class PrepareLibs(build_clib):
|
||||
blacklisted = True
|
||||
break
|
||||
if file_path.is_file() and not blacklisted:
|
||||
dst_file = os.path.join(package_dir, os.path.relpath(file_path, local_base_dir))
|
||||
os.makedirs(os.path.dirname(dst_file), exist_ok=True)
|
||||
dst_file = os.path.join(package_clibs_dir, file_name)
|
||||
copyfile(file_path, dst_file)
|
||||
self.announce(f"Copy {file_path} to {dst_file}", level=3)
|
||||
|
||||
if Path(package_dir).exists():
|
||||
if Path(package_clibs_dir).exists():
|
||||
self.announce(f"Adding {WHEEL_LIBS_PACKAGE} package", level=3)
|
||||
packages.append(WHEEL_LIBS_PACKAGE)
|
||||
package_data.update({WHEEL_LIBS_PACKAGE: ["*"]})
|
||||
@@ -383,16 +404,17 @@ class CopyExt(build_ext):
|
||||
|
||||
def run(self):
|
||||
if len(self.extensions) == 1:
|
||||
# when python3 setup.py build_ext is called, while build_clib is not called before
|
||||
self.run_command("build_clib")
|
||||
self.extensions = []
|
||||
self.extensions = find_prebuilt_extensions(get_install_dirs_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}")
|
||||
raise DistutilsSetupError(f"build_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
|
||||
# setting relative RPATH to found dlls
|
||||
if sys.platform != "win32":
|
||||
rpath = os.path.relpath(get_package_dir(PY_INSTALL_CFG), os.path.dirname(src))
|
||||
rpath = os.path.join(LIBS_RPATH, rpath, WHEEL_LIBS_INSTALL_DIR)
|
||||
@@ -412,7 +434,7 @@ class CustomInstall(install):
|
||||
class CustomClean(clean):
|
||||
"""Clean up staging directories."""
|
||||
|
||||
def clean(self, install_cfg):
|
||||
def clean_install_prefix(self, install_cfg):
|
||||
for comp, comp_data in install_cfg.items():
|
||||
install_prefix = comp_data.get("prefix")
|
||||
self.announce(f"Cleaning {comp}: {install_prefix}", level=3)
|
||||
@@ -420,8 +442,8 @@ class CustomClean(clean):
|
||||
rmtree(install_prefix)
|
||||
|
||||
def run(self):
|
||||
self.clean(LIB_INSTALL_CFG)
|
||||
self.clean(PY_INSTALL_CFG)
|
||||
self.clean_install_prefix(LIB_INSTALL_CFG)
|
||||
self.clean_install_prefix(PY_INSTALL_CFG)
|
||||
clean.run(self)
|
||||
|
||||
|
||||
@@ -500,11 +522,12 @@ def find_prebuilt_extensions(search_dirs):
|
||||
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):
|
||||
for search_dir in search_dirs:
|
||||
for path in Path(search_dir).glob(ext_pattern):
|
||||
# ignores usual inference plugins and libraries (clibs)
|
||||
if path.match("openvino/libs/*") or path.match(f"openvino/libs/openvino-{OPENVINO_VERSION}/*"):
|
||||
continue
|
||||
relpath = path.relative_to(base_dir)
|
||||
relpath = path.relative_to(search_dir)
|
||||
if relpath.parent != ".":
|
||||
package_names = str(relpath.parent).split(os.path.sep)
|
||||
else:
|
||||
@@ -513,6 +536,7 @@ def find_prebuilt_extensions(search_dirs):
|
||||
name = ".".join(package_names)
|
||||
extensions.append(PrebuiltExtension(name, sources=[str(path)]))
|
||||
if not extensions:
|
||||
# dummy extension to avoid python independent wheel
|
||||
extensions.append(PrebuiltExtension("openvino", sources=[str("setup.py")]))
|
||||
return extensions
|
||||
|
||||
@@ -524,25 +548,21 @@ def get_description(desc_file_path):
|
||||
return description
|
||||
|
||||
|
||||
def get_dependencies(requirements_file_path):
|
||||
def get_install_requires(requirements_file_path):
|
||||
"""Read dependencies from requirements.txt."""
|
||||
with open(requirements_file_path, "r", encoding="utf-8") as fstream:
|
||||
dependencies = fstream.read()
|
||||
return dependencies
|
||||
install_requirements = fstream.read()
|
||||
return install_requirements
|
||||
|
||||
|
||||
def get_install_dirs_list(install_cfg):
|
||||
"""Collect all available directories with libs or python packages."""
|
||||
dirs = []
|
||||
"""Collect all available directories with clibs or python extensions."""
|
||||
install_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
|
||||
full_install_dir = os.path.join(comp_info.get("prefix"), comp_info.get("install_dir"))
|
||||
if full_install_dir not in install_dirs:
|
||||
install_dirs.append(full_install_dir)
|
||||
return install_dirs
|
||||
|
||||
|
||||
def get_package_dir(install_cfg):
|
||||
@@ -555,7 +575,7 @@ def get_package_dir(install_cfg):
|
||||
return py_package_path
|
||||
|
||||
|
||||
def concat_files(output_file, input_files):
|
||||
def concat_files(input_files, output_file):
|
||||
"""Concatenates multuple input files to a single output file."""
|
||||
with open(output_file, "w", encoding="utf-8") as outfile:
|
||||
for filename in input_files:
|
||||
@@ -565,45 +585,36 @@ def concat_files(output_file, input_files):
|
||||
return output_file
|
||||
|
||||
|
||||
platforms = ["linux", "win32", "darwin"]
|
||||
if not any(pl in sys.platform for pl in platforms):
|
||||
sys.exit(f"Unsupported platform: {sys.platform}, expected: linux, win32, darwin")
|
||||
|
||||
OPENVINO_VERSION = WHEEL_VERSION = os.getenv("WHEEL_VERSION", "0.0.0")
|
||||
# copy license file into the build directory
|
||||
package_license = os.getenv("WHEEL_LICENSE", SCRIPT_DIR.parents[3] / "LICENSE")
|
||||
if os.path.exists(package_license):
|
||||
copyfile(package_license, "LICENSE")
|
||||
|
||||
packages = find_namespace_packages(get_package_dir(PY_INSTALL_CFG))
|
||||
PACKAGE_DIR = get_package_dir(PY_INSTALL_CFG)
|
||||
packages = find_namespace_packages(PACKAGE_DIR)
|
||||
package_data: typing.Dict[str, list] = {}
|
||||
pkg_name = os.getenv("WHEEL_PACKAGE_NAME", "openvino")
|
||||
ext_modules = find_prebuilt_extensions(get_install_dirs_list(PY_INSTALL_CFG)) if pkg_name == "openvino" else []
|
||||
ext_modules = find_prebuilt_extensions(get_install_dirs_list(PY_INSTALL_CFG))
|
||||
|
||||
description_md = SCRIPT_DIR.parents[3] / "docs" / "install_guides" / "pypi-openvino-rt.md"
|
||||
md_files = [description_md, SCRIPT_DIR.parents[3] / "docs" / "install_guides" / "pre-release-note.md"]
|
||||
long_description_md = OPENVINO_SOURCE_DIR / "docs" / "install_guides" / "pypi-openvino-rt.md"
|
||||
md_files = [long_description_md, OPENVINO_SOURCE_DIR / "docs" / "install_guides" / "pre-release-note.md"]
|
||||
docs_url = "https://docs.openvino.ai/2023.0/index.html"
|
||||
|
||||
if (os.getenv("CI_BUILD_DEV_TAG")):
|
||||
output = Path.cwd() / "build" / "pypi-openvino-rt.md"
|
||||
output.parent.mkdir(exist_ok=True)
|
||||
description_md = concat_files(output, md_files)
|
||||
docs_url = "https://docs.openvino.ai/2023.0/index.html"
|
||||
if os.getenv("CI_BUILD_DEV_TAG"):
|
||||
long_description_md = WORKING_DIR / "build" / "pypi-openvino-rt.md"
|
||||
long_description_md.parent.mkdir(exist_ok=True)
|
||||
concat_files(md_files, long_description_md)
|
||||
docs_url = "https://docs.openvino.ai/nightly/index.html"
|
||||
OPENVINO_VERSION = WHEEL_VERSION[0:8]
|
||||
|
||||
setup(
|
||||
name="openvino",
|
||||
version=WHEEL_VERSION,
|
||||
build=os.getenv("WHEEL_BUILD", "000"),
|
||||
author_email=os.getenv("WHEEL_AUTHOR_EMAIL", "openvino_pushbot@intel.com"),
|
||||
name=pkg_name,
|
||||
license=os.getenv("WHEEL_LICENCE_TYPE", "OSI Approved :: Apache Software License"),
|
||||
author=os.getenv("WHEEL_AUTHOR", "Intel(R) Corporation"),
|
||||
description=os.getenv("WHEEL_DESC", "OpenVINO(TM) Runtime"),
|
||||
install_requires=get_dependencies(os.getenv("WHEEL_REQUIREMENTS", SCRIPT_DIR.parents[0] / "requirements.txt")),
|
||||
long_description=get_description(os.getenv("WHEEL_OVERVIEW", description_md)),
|
||||
author_email="openvino@intel.com",
|
||||
license="OSI Approved :: Apache Software License",
|
||||
author="Intel(R) Corporation",
|
||||
description="OpenVINO(TM) Runtime",
|
||||
install_requires=get_install_requires(SCRIPT_DIR.parents[0] / "requirements.txt"),
|
||||
long_description=get_description(long_description_md),
|
||||
long_description_content_type="text/markdown",
|
||||
download_url=os.getenv("WHEEL_DOWNLOAD_URL", "https://github.com/openvinotoolkit/openvino/tags"),
|
||||
url=os.getenv("WHEEL_URL", docs_url),
|
||||
download_url="https://github.com/openvinotoolkit/openvino/releases",
|
||||
url=docs_url,
|
||||
cmdclass={
|
||||
"build": CustomBuild,
|
||||
"install": CustomInstall,
|
||||
@@ -613,7 +624,7 @@ setup(
|
||||
},
|
||||
ext_modules=ext_modules,
|
||||
packages=packages,
|
||||
package_dir={"": get_package_dir(PY_INSTALL_CFG)},
|
||||
package_dir={"": PACKAGE_DIR},
|
||||
package_data=package_data,
|
||||
zip_safe=False,
|
||||
)
|
||||
Reference in new issue
Block a user