OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[PY] Using pyproject.toml for python api management (#30048)
Mikhail Ryzhov19427e87a073
diff --git a/.github/workflows/py_checks.yml b/.github/workflows/py_checks.ymlindex f9df95a067c..0e61977f42a 100644--- a/.github/workflows/py_checks.yml+++ b/.github/workflows/py_checks.yml@@ -106,8 +106,7 @@ jobs:# Run pyright to assert no regressions in type hinting- name: Run pyright on Python API- run: python -m pyright ./src/openvino -p ./pyproject.toml- working-directory: src/bindings/python+ run: python -m pyright --verbose# layer_tests Flake code-style- name: Run flake8 on python tests in openvino/tests/layer_testsdiff --git a/pyproject.toml b/pyproject.tomlnew file mode 100644index 00000000000..d7b89561a41--- /dev/null+++ b/pyproject.toml@@ -0,0 +1,70 @@+[project]+name = "openvino"+dynamic = ["version", "entry-points", "scripts"]+description = "OpenVINO(TM) Runtime"+readme = {file = "README.md", content-type="text/markdown"}+license = {text = "OSI Approved :: Apache Software License"}+authors = [+ { name = "OpenVINO Developers", email = "[email protected]" },+]+classifiers = [+ "Programming Language :: Python :: 3.9",+ "Programming Language :: Python :: 3.10",+ "Programming Language :: Python :: 3.11",+ "Programming Language :: Python :: 3.12",+ "Programming Language :: Python :: 3.13",+]+requires-python = ">=3.9"++dependencies = [+ "numpy>=1.16.6,<2.3.0",+ "openvino-telemetry>=2023.2.1",+ "packaging"+]++[build-system]+requires = [+ "setuptools>=70,<=80.3.1",+ "wheel<=0.45.1",+ "cmake<=3.31.6",+ "patchelf<=0.17.2.2; sys_platform == 'linux' and platform_machine == 'x86_64'"+]+build-backend = "setuptools.build_meta"++[tool.setuptools]+license-files = [+ "LICENSE",+ "licensing/runtime-third-party-programs.txt",+ "licensing/onetbb_third-party-programs.txt",+ "licensing/onednn_third-party-programs.txt",+]+[tool.setuptools.packages.find]+where = ["./src/bindings/python"]+include = ["pyopenvino"]++[tool.black]+line-length = 160+include = '\.pyi?$'++[tool.pyright]+include = ["src/bindings/python/src"]+exclude = ["src/bindings/python/src/pyopenvino"]+ignore = [+ "**/ops.py",+ "**/utils/data_helpers/data_dispatcher.py",+ "**/utils/types.py",+ "**/utils/decorators.py",+ "**/frontend/frontend.py",+ "**/_ov_api.py",+ "**/_op_base.py",+ "**/utils/node_factory.py",+ "**/frontend/tensorflow",+ "**/frontend/pytorch",+ "**/frontend/jax"+]+reportInvalidTypeForm = false+reportMissingModuleSource = false+reportFunctionMemberAccess = false+reportAttributeAccessIssue = false+reportMissingImports = false+reportIncompatibleMethodOverride = falsediff --git a/src/bindings/python/wheel/setup.py b/setup.pysimilarity index 94%rename from src/bindings/python/wheel/setup.pyrename to setup.pyindex 1b3bed6220b..cb2e0de0a10 100644--- a/src/bindings/python/wheel/setup.py+++ b/setup.py@@ -20,6 +20,7 @@ from setuptools.command.build_ext import build_extfrom setuptools.command.build_clib import build_clibfrom setuptools.command.install import installfrom setuptools.command.build import build+from setuptools.command.bdist_wheel import bdist_wheelfrom setuptools.errors import SetupErrorWHEEL_PACKAGE_DIR = "openvino"@@ -42,14 +43,14 @@ elif machine == "riscv64":ARCH = "riscv64"# The following variables can be defined in environment or .env file-SCRIPT_DIR = Path(__file__).resolve().parents[0]+SCRIPT_DIR = Path(__file__).resolve().parentWORKING_DIR = Path.cwd()-BUILD_BASE = f"{WORKING_DIR}/build_{PYTHON_VERSION}"-OPENVINO_SOURCE_DIR = SCRIPT_DIR.parents[3]-OPENVINO_BINARY_DIR = os.getenv("OPENVINO_BINARY_DIR")+BUILD_BASE = f"build_{PYTHON_VERSION}"+OPENVINO_SOURCE_DIR = os.getenv("OPENVINO_SOURCE_DIR", SCRIPT_DIR)+OPENVINO_BINARY_DIR = os.getenv("OPENVINO_BINARY_DIR", f'{OPENVINO_SOURCE_DIR}/build_wheel')OPENVINO_PYTHON_BINARY_DIR = os.getenv("OPENVINO_PYTHON_BINARY_DIR", "python_build")CONFIG = os.getenv("BUILD_TYPE", "Release")-OV_RUNTIME_LIBS_DIR = os.getenv("OV_RUNTIME_LIBS_DIR", f"runtime/{LIBS_DIR}/{ARCH}/{CONFIG}")+OV_RUNTIME_LIBS_DIR = os.getenv("OV_RUNTIME_LIBS_DIR", f"runtime/{LIBS_DIR}/{ARCH}")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", "python")@@ -285,7 +286,7 @@ class CustomBuild(build):"""Runs cmake (configure, build and install) if artfiacts are not already built / installed."""plat_specifier = ".{0}-{1}.{2}".format(self.plat_name, *sys.version_info[:2])self.build_temp = os.path.join(self.build_base, "temp" + plat_specifier)- self.announce(f"Create build directory: {self.build_temp}", level=3)+ self.announce(f"Create build directory: {self.build_temp}", level=log.INFO)# build some components which have not been built yetfor comp, comp_data in install_cfg.items():cpack_comp_name = comp_data.get("name")@@ -293,18 +294,14 @@ class CustomBuild(build):binary_dir = comp_data.get("binary_dir", OPENVINO_BINARY_DIR)install_dir = comp_data.get("install_dir")prefix = comp_data.get("prefix")-+# perform installation steps if we are not given a full pathif not os.path.isabs(install_dir):# install_dir is just a sub-dir after install prefix, let's make a full path- comp_data["install_dir"] = os.path.join(prefix, install_dir)-- # even perform a build in case of binary directory does not exist- binary_dir = binary_dir if os.path.isabs(binary_dir) else os.path.join(self.build_temp, binary_dir)-if not os.path.exists(binary_dir):+ # even perform a build in case of binary directory does not existbinary_dir = os.path.join(self.build_temp, binary_dir)- self.announce(f"Configuring {comp} cmake project", level=3)+ self.announce(f"Configuring {comp} cmake project", level=log.INFO)self.spawn(["cmake",f"-DOpenVINODeveloperPackage_DIR={OPENVINO_BINARY_DIR}",f"-DPython3_EXECUTABLE={sys.executable}",@@ -316,12 +313,12 @@ class CustomBuild(build):"-S", source_dir,"-B", binary_dir])- self.announce(f"Building {comp} project", level=3)+ self.announce(f"Building {comp} project", level=log.INFO)self.spawn(["cmake", "--build", binary_dir,"--config", CONFIG,"--parallel", str(self.jobs)])- self.announce(f"Installing {comp}", level=3)+ self.announce(f"Installing {comp}", level=log.INFO)self.spawn(["cmake", "--install", binary_dir,"--prefix", prefix,"--config", CONFIG,@@ -351,7 +348,6 @@ class CustomBuild(build):(dst / path_rel.parent).mkdir(exist_ok=True, parents=True)copyfile(path, dst / path_rel)-class PrepareLibs(build_clib):"""Prepares prebuilt libraries.@@ -371,7 +367,7 @@ class PrepareLibs(build_clib):def post_install(self, install_cfg):"""Install prebuilt libraries to the temp directories, set rpath."""for comp, comp_data in install_cfg.items():- install_dir = comp_data.get("install_dir")+ install_dir = os.path.join(comp_data.get("prefix"), comp_data.get("install_dir"))# we need to resolve symlinks before setting rpath to avoid doing it multiple timesinstall_dir_path = Path(install_dir)@@ -425,11 +421,11 @@ class PrepareLibs(build_clib):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)+ self.announce(f"Unlink symlink {file_dict[real_name]}, use {symlink} instead", level=log.INFO)os.unlink(file_dict[real_name])file_dict[real_name] = symlinkelse:- self.announce(f"Unlink symlink {symlink}, use {file_dict[real_name]} instead", level=3)+ self.announce(f"Unlink symlink {symlink}, use {file_dict[real_name]} instead", level=log.INFO)os.unlink(symlink)else:file_dict[real_name] = symlink@@ -440,7 +436,7 @@ class PrepareLibs(build_clib):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)+ self.announce(f"Resolved symlink {symlink} as {real_name}", level=log.INFO)def copy_package_libs(self, src_dirs):"""Collect package data files (clibs and other plugin support files) from preinstalled dirs and put all runtime libraries to the subpackage."""@@ -465,10 +461,10 @@ class PrepareLibs(build_clib):if file_path.is_file() and not is_blacklisted(file_name, blacklist_patterns):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)+ self.announce(f"Copy {file_path} to {dst_file}", level=log.INFO)if Path(package_clibs_dir).exists():- self.announce(f"Adding {WHEEL_LIBS_PACKAGE} package", level=3)+ self.announce(f"Adding {WHEEL_LIBS_PACKAGE} package", level=log.INFO)packages.append(WHEEL_LIBS_PACKAGE)package_data.update({WHEEL_LIBS_PACKAGE: ["*"]})@@ -518,16 +514,16 @@ class PrepareLibs(build_clib):if file_path.is_file() and not is_blacklisted(file_name, blacklist_patterns):dst_file = os.path.join(package_clibs_dir, file_name)move(file_path, dst_file)- self.announce(f"Move {file_path} to {dst_file}", level=3)+ self.announce(f"Move {file_path} to {dst_file}", level=log.INFO)# collect all cmake files in one directoryfor file_path in Path(src).rglob("*.cmake"):file_name = os.path.basename(file_path)if file_path.is_file() and not is_blacklisted(file_name, blacklist_patterns):dst_file = os.path.join(package_cmake_dir, file_name)- self.announce(f"Move {file_path} to {dst_file}", level=3)+ self.announce(f"Move {file_path} to {dst_file}", level=log.INFO)move(file_path, dst_file)- self.announce("Patch cmake configurations", level=3)+ self.announce("Patch cmake configurations", level=log.INFO)replace_strings_in_file(dst_file,openvino_replacements if file_name.startswith("OpenVINO") else tbb_replacements)@@ -592,12 +588,34 @@ class CopyExt(build_ext):class CustomInstall(install):- """Enable build_clib during the installation."""-+ """Custom install command."""def run(self):+ """Enable build_clib during the installation."""self.run_command("build")- install.run(self)+ super().run()+++class CustomBdistWheel(bdist_wheel):+ """Custom bdist_wheel command."""+ def initialize_options(self):+ """Set default values for all the options that this command supports."""+ super().initialize_options()+ def finalize_options(self):+ """Set final values for all the options that this command supports."""+ super().finalize_options()++ platform_tag = os.getenv("PLATFORM_TAG")+ if platform_tag:+ self.plat_name = platform_tag+ self.plat_name_supplied = True++ build_number = os.getenv("WHEEL_BUILD")+ if build_number:+ self.build_number = build_number++ def run(self):+ super().run()class CustomClean(Command):"""Clean up staging directories."""@@ -613,7 +631,7 @@ class CustomClean(Command):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)+ self.announce(f"Cleaning {comp}: {install_prefix}", level=log.INFO)if os.path.exists(install_prefix):rmtree(install_prefix)@@ -723,13 +741,6 @@ def get_description(desc_file_path):return description-def get_install_requires(requirements_file_path):- """Read dependencies from requirements.txt."""- with open(requirements_file_path, "r", encoding="utf-8") as fstream:- install_requirements = fstream.read()- return install_requirements--def get_install_dirs_list(install_cfg):"""Collect all available directories with clibs or python extensions."""install_dirs = []@@ -784,8 +795,8 @@ package_data: typing.Dict[str, list] = {}ext_modules = find_prebuilt_extensions(get_install_dirs_list(PY_INSTALL_CFG))entry_points = find_entry_points(PY_INSTALL_CFG)-long_description_md = OPENVINO_SOURCE_DIR / "docs" / "dev" / "pypi_publish" / "pypi-openvino-rt.md"-md_files = [long_description_md, OPENVINO_SOURCE_DIR / "docs" / "dev" / "pypi_publish" / "pre-release-note.md"]+long_description_md = Path(OPENVINO_SOURCE_DIR) / "docs" / "dev" / "pypi_publish" / "pypi-openvino-rt.md"+md_files = [long_description_md, Path(OPENVINO_SOURCE_DIR) / "docs" / "dev" / "pypi_publish" / "pre-release-note.md"]docs_url = "https://docs.openvino.ai/2023.0/index.html"if os.getenv("CI_BUILD_DEV_TAG"):@@ -797,13 +808,7 @@ if os.getenv("CI_BUILD_DEV_TAG"):setup(name="openvino",- version=WHEEL_VERSION,- build=os.getenv("WHEEL_BUILD", "000"),- author_email="[email protected]",- 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"),+ version=f'{WHEEL_VERSION}',long_description=get_description(long_description_md),long_description_content_type="text/markdown",download_url="https://github.com/openvinotoolkit/openvino/releases",@@ -811,6 +816,7 @@ setup(entry_points=entry_points,cmdclass={"build": CustomBuild,+ "bdist_wheel": CustomBdistWheel,"install": CustomInstall,"build_clib": PrepareLibs,"build_ext": CopyExt,diff --git a/src/bindings/python/CMakeLists.txt b/src/bindings/python/CMakeLists.txtindex eacb2f8dadb..03ae9d18c69 100644--- a/src/bindings/python/CMakeLists.txt+++ b/src/bindings/python/CMakeLists.txt@@ -242,6 +242,7 @@ macro(ov_define_setup_py_packaging_vars)WHEEL_VERSION=${WHEEL_VERSION}WHEEL_BUILD=${WHEEL_BUILD}# build locations+ OPENVINO_SOURCE_DIR=${OpenVINO_SOURCE_DIR}OPENVINO_BINARY_DIR=${OpenVINO_BINARY_DIR}OPENVINO_PYTHON_BINARY_DIR=${OpenVINOPython_BINARY_DIR}# to create proper directories for BA, OVC tools@@ -276,7 +277,8 @@ macro(ov_define_setup_py_dependencies)list(APPEND ov_setup_py_deps${openvino_py_files}- "${CMAKE_CURRENT_SOURCE_DIR}/wheel/setup.py"+ "${OpenVINO_SOURCE_DIR}/pyproject.toml"+ "${OpenVINO_SOURCE_DIR}/setup.py""${OpenVINOPython_SOURCE_DIR}/requirements.txt""${OpenVINOPython_SOURCE_DIR}/wheel/readme.txt""${OpenVINO_SOURCE_DIR}/LICENSE"@@ -321,13 +323,12 @@ if(ENABLE_PYTHON_PACKAGING)set(openvino_meta_info_file "${ov_install_lib}/${openvino_meta_info_subdir}/PKG-INFO")add_custom_command(OUTPUT ${openvino_meta_info_file}- COMMAND ${CMAKE_COMMAND} -E remove_directory- "${ov_python_package_prefix}"+ COMMAND ${CMAKE_COMMAND} -E remove_directory "${ov_python_package_prefix}"COMMAND ${setup_py_env}# variables to reflect options (extensions only or full wheel package)PYTHON_EXTENSIONS_ONLY=ONSKIP_RPATH=ON- "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/wheel/setup.py"+ "${Python3_EXECUTABLE}" "${OpenVINO_SOURCE_DIR}/setup.py"--no-user-cfg--quietbuilddiff --git a/src/bindings/python/pyproject.toml b/src/bindings/python/pyproject.tomldeleted file mode 100644index b42c01e41e4..00000000000--- a/src/bindings/python/pyproject.toml+++ /dev/null@@ -1,24 +0,0 @@-[tool.black]-line-length = 160-include = '\.pyi?$'--[tool.pyright]-exclude = [- "src/openvino/utils/data_helpers/data_dispatcher.py",- "src/openvino/utils/types.py",- "src/openvino/**/ops.py",- "src/openvino/utils/decorators.py",- "src/openvino/frontend/frontend.py",- "src/openvino/_ov_api.py",- "src/openvino/_op_base.py",- "src/openvino/utils/node_factory.py",- "src/openvino/frontend/tensorflow",- "src/openvino/frontend/pytorch",- "src/openvino/frontend/jax",-]-reportInvalidTypeForm = false-reportMissingModuleSource = false-reportFunctionMemberAccess = false-reportAttributeAccessIssue = false-reportMissingImports = false-reportIncompatibleMethodOverride = falsediff --git a/src/bindings/python/wheel/CMakeLists.txt b/src/bindings/python/wheel/CMakeLists.txtindex ea3a63c232b..ada33e88113 100644--- a/src/bindings/python/wheel/CMakeLists.txt+++ b/src/bindings/python/wheel/CMakeLists.txt@@ -91,6 +91,7 @@ elseif(LINUX)set(PLATFORM_TAG "${platform}_${_arch}")endif()+list(APPEND setup_py_env PLATFORM_TAG=${PLATFORM_TAG})set(openvino_wheel_name "openvino-${WHEEL_VERSION}-${WHEEL_BUILD}-${PYTHON_TAG}-${ABI_TAG}-${PLATFORM_TAG}.whl")set(openvino_wheels_output_dir "${CMAKE_BINARY_DIR}/wheels")@@ -100,36 +101,18 @@ set(openvino_wheel_path "${openvino_wheels_output_dir}/${openvino_wheel_name}")# create target for openvino.wheel#-execute_process(COMMAND ${Python3_EXECUTABLE} -m pip --version- OUTPUT_VARIABLE pip_version OUTPUT_STRIP_TRAILING_WHITESPACE)--string(REGEX MATCH "pip[ ]+([\\.0-9]*)" pip_version "${pip_version}")-set(pip_version ${CMAKE_MATCH_1})--if(pip_version VERSION_GREATER_EQUAL 22.0)- set(wheel_build_command- ${Python3_EXECUTABLE} -m pip wheel- --no-deps- --wheel-dir ${openvino_wheels_output_dir}- --verbose- --build-option --build-number=${WHEEL_BUILD}- --build-option --plat-name=${PLATFORM_TAG}- "${CMAKE_CURRENT_SOURCE_DIR}")-else()- # for --config-setting explanation see https://github.com/pypa/setuptools/issues/2491- set(wheel_build_command- ${Python3_EXECUTABLE} -m build "${CMAKE_CURRENT_SOURCE_DIR}"- --outdir ${openvino_wheels_output_dir}- --config-setting=--build-option=--build-number=${WHEEL_BUILD}- --config-setting=--build-option=--plat-name=${PLATFORM_TAG}- --config-setting=--quiet- --wheel)-endif()+set(wheel_build_command+ ${Python3_EXECUTABLE} -m pip wheel+ --no-deps+ --ignore-requires-python+ --wheel-dir ${openvino_wheels_output_dir}+ --verbose+ ".")add_custom_command(OUTPUT ${openvino_wheel_path}COMMAND ${setup_py_env} ${wheel_build_command}DEPENDS ${ov_setup_py_deps}- WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"+ WORKING_DIRECTORY "${OpenVINO_SOURCE_DIR}"COMMENT "Building Python wheel ${openvino_wheel_name}"VERBATIM)set(ie_wheel_deps ${openvino_wheel_path})diff --git a/src/bindings/python/wheel/setup.cfg b/src/bindings/python/wheel/setup.cfgdeleted file mode 100644index 9c04023139b..00000000000--- a/src/bindings/python/wheel/setup.cfg+++ /dev/null@@ -1,7 +0,0 @@-[metadata]-license_files =- readme.txt- ../../../../licensing/runtime-third-party-programs.txt- ../../../../licensing/onetbb_third-party-programs.txt- ../../../../licensing/onednn_third-party-programs.txt- ../../../../LICENSE