Ability to configure setup.py via env variables (#18538)
This commit is contained in:
parent
7b5acbb29a
commit
96d16b141d
@ -37,7 +37,7 @@ macro(ov_common_libraries_cpack_set_dirs)
|
|||||||
ov_get_pyversion(pyversion)
|
ov_get_pyversion(pyversion)
|
||||||
if(pyversion)
|
if(pyversion)
|
||||||
# should not be used in production; only by setup.py install
|
# should not be used in production; only by setup.py install
|
||||||
set(OV_CPACK_PYTHONDIR ${CMAKE_INSTALL_LIBDIR}/${pyversion}/site-packages)
|
set(OV_CPACK_PYTHONDIR lib/${pyversion}/site-packages)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# non-native stuff
|
# non-native stuff
|
||||||
|
@ -242,6 +242,8 @@ macro(ov_define_setup_py_packaging_vars)
|
|||||||
# build locations
|
# build locations
|
||||||
OPENVINO_BINARY_DIR=${OpenVINO_BINARY_DIR}
|
OPENVINO_BINARY_DIR=${OpenVINO_BINARY_DIR}
|
||||||
OPENVINO_PYTHON_BINARY_DIR=${OpenVINOPython_BINARY_DIR}
|
OPENVINO_PYTHON_BINARY_DIR=${OpenVINOPython_BINARY_DIR}
|
||||||
|
# to create proper directories for BA, OVC tools
|
||||||
|
CPACK_GENERATOR=${CPACK_GENERATOR}
|
||||||
# variables to reflect cpack locations
|
# variables to reflect cpack locations
|
||||||
OV_RUNTIME_LIBS_DIR=${OV_WHEEL_RUNTIMEDIR}
|
OV_RUNTIME_LIBS_DIR=${OV_WHEEL_RUNTIMEDIR}
|
||||||
TBB_LIBS_DIR=${TBB_LIBS_DIR}
|
TBB_LIBS_DIR=${TBB_LIBS_DIR}
|
||||||
@ -316,14 +318,15 @@ if(ENABLE_PYTHON_PACKAGING)
|
|||||||
COMMAND ${CMAKE_COMMAND} -E remove_directory
|
COMMAND ${CMAKE_COMMAND} -E remove_directory
|
||||||
"${python_package_prefix}"
|
"${python_package_prefix}"
|
||||||
COMMAND ${setup_py_env}
|
COMMAND ${setup_py_env}
|
||||||
|
# variables to reflect options (extensions only or full wheel package)
|
||||||
|
PYTHON_EXTENSIONS_ONLY=ON
|
||||||
|
SKIP_RPATH=ON
|
||||||
"${PYTHON_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/wheel/setup.py"
|
"${PYTHON_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/wheel/setup.py"
|
||||||
--no-user-cfg
|
--no-user-cfg
|
||||||
--quiet
|
--quiet
|
||||||
build
|
build
|
||||||
--python-extensions-only
|
|
||||||
--executable "/usr/bin/python3"
|
--executable "/usr/bin/python3"
|
||||||
build_ext
|
build_ext
|
||||||
--skip-rpath
|
|
||||||
install
|
install
|
||||||
--no-compile
|
--no-compile
|
||||||
--prefix "${python_package_prefix}"
|
--prefix "${python_package_prefix}"
|
||||||
|
@ -52,6 +52,9 @@ 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}")
|
PUGIXML_LIBS_DIR = os.getenv("PUGIXML_LIBS_DIR", f"runtime/3rdparty/pugixml/{LIBS_DIR}")
|
||||||
PY_PACKAGES_DIR = os.getenv("PY_PACKAGES_DIR", "python")
|
PY_PACKAGES_DIR = os.getenv("PY_PACKAGES_DIR", "python")
|
||||||
LIBS_RPATH = "$ORIGIN" if sys.platform == "linux" else "@loader_path"
|
LIBS_RPATH = "$ORIGIN" if sys.platform == "linux" else "@loader_path"
|
||||||
|
PYTHON_EXTENSIONS_ONLY = True if os.getenv("PYTHON_EXTENSIONS_ONLY") is not None else False
|
||||||
|
SKIP_RPATH = True if os.getenv("SKIP_RPATH") is not None else False
|
||||||
|
CPACK_GENERATOR = os.getenv("CPACK_GENERATOR", "TGZ")
|
||||||
|
|
||||||
LIB_INSTALL_CFG = {
|
LIB_INSTALL_CFG = {
|
||||||
"ie_libs": {
|
"ie_libs": {
|
||||||
@ -218,9 +221,7 @@ class CustomBuild(build):
|
|||||||
user_options = build.user_options + [
|
user_options = build.user_options + [
|
||||||
("jobs=", None, "Specifies the number of jobs to use with make."),
|
("jobs=", None, "Specifies the number of jobs to use with make."),
|
||||||
("cmake-args=", None, "Additional options to be passed to CMake."),
|
("cmake-args=", None, "Additional options to be passed to CMake."),
|
||||||
("python-extensions-only", None, "Install Python extensions without C++ libraries."),
|
|
||||||
]
|
]
|
||||||
boolean_options = build.boolean_options + ["python-extensions-only"]
|
|
||||||
|
|
||||||
def initialize_options(self):
|
def initialize_options(self):
|
||||||
"""Set default values for all the options that this command supports."""
|
"""Set default values for all the options that this command supports."""
|
||||||
@ -228,7 +229,6 @@ class CustomBuild(build):
|
|||||||
self.build_base = BUILD_BASE
|
self.build_base = BUILD_BASE
|
||||||
self.jobs = None
|
self.jobs = None
|
||||||
self.cmake_args = None
|
self.cmake_args = None
|
||||||
self.python_extensions_only = False
|
|
||||||
|
|
||||||
def finalize_options(self):
|
def finalize_options(self):
|
||||||
"""Set final values for all the options that this command supports."""
|
"""Set final values for all the options that this command supports."""
|
||||||
@ -267,6 +267,7 @@ class CustomBuild(build):
|
|||||||
self.announce(f"Configuring {comp} cmake project", level=3)
|
self.announce(f"Configuring {comp} cmake project", level=3)
|
||||||
self.spawn(["cmake", f"-DOpenVINODeveloperPackage_DIR={OPENVINO_BINARY_DIR}",
|
self.spawn(["cmake", f"-DOpenVINODeveloperPackage_DIR={OPENVINO_BINARY_DIR}",
|
||||||
f"-DPYTHON_EXECUTABLE={sys.executable}",
|
f"-DPYTHON_EXECUTABLE={sys.executable}",
|
||||||
|
f"-DCPACK_GENERATOR={CPACK_GENERATOR}",
|
||||||
"-DCMAKE_BUILD_TYPE=Release",
|
"-DCMAKE_BUILD_TYPE=Release",
|
||||||
"-DENABLE_WHEEL=OFF",
|
"-DENABLE_WHEEL=OFF",
|
||||||
self.cmake_args,
|
self.cmake_args,
|
||||||
@ -287,14 +288,14 @@ class CustomBuild(build):
|
|||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
# build and install clib into temporary directories
|
# build and install clib into temporary directories
|
||||||
if not self.python_extensions_only:
|
if not PYTHON_EXTENSIONS_ONLY:
|
||||||
self.cmake_build_and_install(LIB_INSTALL_CFG)
|
self.cmake_build_and_install(LIB_INSTALL_CFG)
|
||||||
|
|
||||||
# install python code into a temporary directory (site-packages)
|
# install python code into a temporary directory (site-packages)
|
||||||
self.cmake_build_and_install(PY_INSTALL_CFG)
|
self.cmake_build_and_install(PY_INSTALL_CFG)
|
||||||
|
|
||||||
# install clibs into a temporary directory (site-packages)
|
# install clibs into a temporary directory (site-packages)
|
||||||
if not self.python_extensions_only:
|
if not PYTHON_EXTENSIONS_ONLY:
|
||||||
self.run_command("build_clib")
|
self.run_command("build_clib")
|
||||||
|
|
||||||
# Copy extra package_data content filtered by 'find_packages'
|
# Copy extra package_data content filtered by 'find_packages'
|
||||||
@ -433,17 +434,6 @@ class PrepareLibs(build_clib):
|
|||||||
|
|
||||||
class CopyExt(build_ext):
|
class CopyExt(build_ext):
|
||||||
"""Copy extension files to the build directory."""
|
"""Copy extension files to the build directory."""
|
||||||
|
|
||||||
user_options = [
|
|
||||||
("skip-rpath", None, "Skips RPATH for Python extensions."),
|
|
||||||
]
|
|
||||||
boolean_options = ["skip_rpath"]
|
|
||||||
|
|
||||||
def initialize_options(self):
|
|
||||||
"""Set default values for all the options that this command supports."""
|
|
||||||
super().initialize_options()
|
|
||||||
self.skip_rpath = False
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
if len(self.extensions) == 1:
|
if len(self.extensions) == 1:
|
||||||
self.extensions = find_prebuilt_extensions(get_install_dirs_list(PY_INSTALL_CFG))
|
self.extensions = find_prebuilt_extensions(get_install_dirs_list(PY_INSTALL_CFG))
|
||||||
@ -455,7 +445,7 @@ class CopyExt(build_ext):
|
|||||||
dst = self.get_ext_fullpath(extension.name)
|
dst = self.get_ext_fullpath(extension.name)
|
||||||
os.makedirs(os.path.dirname(dst), exist_ok=True)
|
os.makedirs(os.path.dirname(dst), exist_ok=True)
|
||||||
# setting relative RPATH to found dlls
|
# setting relative RPATH to found dlls
|
||||||
if sys.platform != "win32" and not self.skip_rpath:
|
if sys.platform != "win32" and not SKIP_RPATH:
|
||||||
rpath = os.path.relpath(get_package_dir(PY_INSTALL_CFG), os.path.dirname(src))
|
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)
|
rpath = os.path.join(LIBS_RPATH, rpath, WHEEL_LIBS_INSTALL_DIR)
|
||||||
set_rpath(rpath, os.path.realpath(src))
|
set_rpath(rpath, os.path.realpath(src))
|
||||||
|
Loading…
Reference in New Issue
Block a user