Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wheel changes #126

Merged
merged 2 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ CMakeUserPresets.json
*.?env*
*.pyc
__pycache__
*.lock
# Tests-specific
*.coverage
*htmlcov
Expand Down
153 changes: 150 additions & 3 deletions src/bindings/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ macro(ov_define_setup_py_dependencies)
list(APPEND ov_setup_py_deps
${openvino_py_files}
${compat_ngraph_py_files}
"${CMAKE_CURRENT_SOURCE_DIR}/wheel/setup.py"
"${CMAKE_CURRENT_SOURCE_DIR}/setup.py"
"${OpenVINOPython_SOURCE_DIR}/requirements.txt"
"${OpenVINOPython_SOURCE_DIR}/wheel/readme.txt"
"${OpenVINO_SOURCE_DIR}/LICENSE"
Expand All @@ -337,7 +337,152 @@ ov_define_setup_py_packaging_vars()
ov_define_setup_py_dependencies()

if(ENABLE_WHEEL)
add_subdirectory(wheel)
# Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#

#
# Define proper package name
#

execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import wheel.vendored.packaging.tags as tags ; print(f'{tags.interpreter_name()}{tags.interpreter_version()}')"
OUTPUT_VARIABLE PYTHON_TAG OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import wheel.bdist_wheel ; print(f'{wheel.bdist_wheel.get_abi_tag()}')"
OUTPUT_VARIABLE ABI_TAG OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import wheel.vendored.packaging.tags as tags ; print(f'{next(tags.platform_tags())}')"
OUTPUT_VARIABLE PLATFORM_TAG OUTPUT_STRIP_TRAILING_WHITESPACE)

# defines wheel architecture part of `PLATFORM_TAG`
macro(_ov_platform_arch)
if(AARCH64)
if(APPLE)
set(_arch "arm64")
else()
set(_arch "aarch64")
endif()
elseif(UNIVERSAL2)
set(_arch "universal2")
elseif(ARM)
set(_arch "armvl7")
elseif(X86_64)
set(_arch "x86_64")
elseif(X86)
set(_arch "i686")
elseif(RISCV64)
set(_arch "riscv64")
else()
message(FATAL_ERROR "Unknown architecture: ${CMAKE_SYSTEM_PROCESSOR}")
endif()
endmacro()

# For macOS and Linux `PLATFORM_TAG` is not always correctly detected
# So, we need to add our-own post-processing
if(APPLE)
_ov_platform_arch()

if(CMAKE_OSX_DEPLOYMENT_TARGET)
set(_macos_target_version "${CMAKE_OSX_DEPLOYMENT_TARGET}")
if(_macos_target_version MATCHES "^1[0-9]$")
set(_macos_target_version "${CMAKE_OSX_DEPLOYMENT_TARGET}.0")
endif()
string(REPLACE "." "_" _macos_target_version "${_macos_target_version}")
else()
string(REGEX MATCH "1[0-9]_[0-9]+" _macos_target_version ${PLATFORM_TAG})
endif()

# common platform tag looks like macosx_<macos major>_<macos minor>_<arch>
if(_arch AND _macos_target_version)
set(PLATFORM_TAG "macosx_${_macos_target_version}_${_arch}")
endif()
elseif(LINUX)
_ov_platform_arch()

string(REPLACE "." "_" _ov_glibc_version "${OV_GLIBC_VERSION}")
set(manylinux "manylinux_${_ov_glibc_version}")

# convert to well-known formats according to PEP 600
if(manylinux STREQUAL "manylinux_2_5")
set(manylinux "manylinux1")
elseif(manylinux STREQUAL "manylinux_2_12")
set(manylinux "manylinux2010")
elseif(manylinux STREQUAL "manylinux_2_17")
set(manylinux "manylinux2014")
endif()

set(PLATFORM_TAG "${manylinux}_${_arch}")
endif()

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")
set(openvino_wheel_path "${openvino_wheels_output_dir}/${openvino_wheel_name}")

#
# create target for openvino.wheel
#

execute_process(COMMAND ${PYTHON_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)
message("!!!!!!!!!!!!!!!!!!!HELLO: HERE000!!!!!!!!!!!!!!!!!!!!!!!!")
set(wheel_build_command
${PYTHON_EXECUTABLE} -m pip wheel
--no-deps
--wheel-dir ${openvino_wheels_output_dir}
--verbose
--config-settings --build-number=${WHEEL_BUILD}
--config-settings --plat-name=${PLATFORM_TAG}
"${CMAKE_CURRENT_SOURCE_DIR}")
else()
set(wheel_build_command
${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/setup.py"
--quiet
--no-user-cfg
--no-build-isolation
bdist_wheel
--dist-dir ${openvino_wheels_output_dir}
--build-number=${WHEEL_BUILD}
--plat-name=${PLATFORM_TAG})
endif()

add_custom_command(OUTPUT ${openvino_wheel_path}
COMMAND ${setup_py_env}
${wheel_build_command}
COMMAND ${CMAKE_COMMAND} -E remove_directory "${CMAKE_CURRENT_SOURCE_DIR}/wheel/build_${pyversion}"
DEPENDS ${ov_setup_py_deps}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMENT "Building Python wheel ${openvino_wheel_name}"
VERBATIM)

# TODO: Reenable when everything works
# set(fdupes_report ${CMAKE_CURRENT_BINARY_DIR}/fdupes_report.txt)
# add_custom_command(OUTPUT "${fdupes_report}"
# COMMAND ${CMAKE_COMMAND}
# -D PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}
# -D WORKING_DIRECTORY=${CMAKE_CURRENT_BINARY_DIR}
# -D WHEEL_VERSION=${WHEEL_VERSION}
# -D PACKAGE_FILE=${openvino_wheel_path}
# -D REPORT_FILE=${fdupes_report}
# -D CMAKE_SHARED_LIBRARY_SUFFIX=${CMAKE_SHARED_LIBRARY_SUFFIX}
# -P "${CMAKE_CURRENT_SOURCE_DIR}/fdupes_check.cmake"
# DEPENDS "${openvino_wheel_path}"
# WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
# COMMENT "Run 'fdupes' checks for wheel ${openvino_wheel_name}"
# VERBATIM)

# add_custom_target(ie_wheel ALL DEPENDS ${openvino_wheel_path} ${fdupes_report})

# install

ov_cpack_add_component(${OV_CPACK_COMP_PYTHON_WHEELS} HIDDEN)

install(FILES ${openvino_wheel_path}
DESTINATION ${OV_CPACK_WHEELSDIR}
COMPONENT ${OV_CPACK_COMP_PYTHON_WHEELS}
${OV_CPACK_COMP_PYTHON_WHEELS_EXCLUDE_ALL})
endif()

#
Expand All @@ -360,14 +505,16 @@ if(ENABLE_PYTHON_PACKAGING)
set(meta_info_subdir "openvino-${OpenVINO_VERSION}-py${python_xy}.egg-info")
set(meta_info_file "${install_lib}/${meta_info_subdir}/PKG-INFO")

message("!!!!WHATEVER!!!!")

add_custom_command(OUTPUT ${meta_info_file}
COMMAND ${CMAKE_COMMAND} -E remove_directory
"${python_package_prefix}"
COMMAND ${setup_py_env}
# variables to reflect options (extensions only or full wheel package)
PYTHON_EXTENSIONS_ONLY=ON
SKIP_RPATH=ON
"${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/wheel/setup.py"
"${PYTHON_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/wheel/setup.py"
--no-user-cfg
--quiet
build
Expand Down
103 changes: 103 additions & 0 deletions src/bindings/python/pdm-custom-plugins/pdm_custom_install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import platform

from pdm.project.config import ConfigItem

# from pdm.cli.commands.base import BaseCommand
from pdm.cli.commands.install import Command as BaseCommand
from pdm.core import Core


CONFIG = {
"python.version": ConfigItem(
"Use this to override 'python-requires' of the project",
default="",
),
}


class CustomInstallCommand(BaseCommand):
"""
This class is used to run the ``pdm install`` command in a custom mode.

:param --python: This parameter can have three possible values:

1. If set to 'env', the command will use the python version of the currently active environment.
2. If set to a specific version (e.g. '>=3.10'), the command will use that version.
3. If not provided, the command will read from the `python.version` config.

If the `python.version` config is unset, the command will use the project's `requires-python` value.
This command always prioritizes `--python` flag over the `python.version`.

.. code::

# To use active environment version:
$ pdm custom-install --python env
# To use range from 3.10.0 to 3.11.*:
$ pdm custom-install --python ">3.9, <=3.11
# Works with interface of `pdm install`:
$ pdm custom-install --python env --no-lock --no-self --dry-run

:param --requirements: This parameter applies `--no-lock --no-self`.

"""

description = BaseCommand.__doc__
name = "custom-install" # TODO: consider changing to "install" to override original one

def add_arguments(self, parser):
parser.add_argument(
"--python", help="Python version to replace project's `requires-python`."
)
parser.add_argument(
"--requirements",
action="store_true",
dest="only_requirements",
help="Install requirements only. Applies `--no-lock` and `--no-self` automatically",
)

# Append `pdm install` attributes itself.
super().add_arguments(parser)

def handle(self, project, options):
# Pass project to the function to reuse options available for Project class.
# For style refer to: https://github.com/pdm-project/pdm/blob/main/src/pdm/termui.py
def note(project, style: str, message: str) -> None:
if not project.is_global:
project.core.ui.echo(message, style=style, err=True)

if options.only_requirements:
note(project, "warning", f"Installing only requirements of the project.")
project.enable_write_lockfile = False
options.no_self = True

# Get version from either options or config. Prioritize `--python` flag.
python_version = options.python or project.config.get("python.version", "")
# Check if existing and apply to current install session.
if python_version:
if python_version == "env":
project.pyproject.metadata[
"requires-python"
] = f"=={platform.python_version()}"
else:
project.pyproject.metadata["requires-python"] = python_version
note(project, "warning", f"Python version has been overriden by the user.")

note(
project,
"info",
f"Custom installation with Python version set to: {project.pyproject.metadata.get('requires-python', '')}",
)

# Probably not needed?
# if options.groups:
# if ":all" in options.groups:
# options.groups += list(project.iter_groups())

# Run `pdm install` itself.
super().handle(project, options)


def register(core: Core) -> None:
core.register_command(CustomInstallCommand)
for k, v in CONFIG.items():
core.add_config(k, v)
2 changes: 1 addition & 1 deletion src/bindings/python/pdm-custom-plugins/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ pip-lock = "pdm_pip_lock:register"

[build-system]
requires = ["pdm-backend"]
build-backend = "pdm.backend"
build-backend = "pdm.backend"
15 changes: 8 additions & 7 deletions src/bindings/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,18 @@ build = [
"wheel >= 0.38.1",
]

# [build-system]
# requires = ["setuptools", "wheel"]
# build-backend = "setuptools.build_meta"

[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
###
# Tools configs
###
[tool.pdm]
plugins = [
"-e file:///${PROJECT_ROOT}/pdm-custom-plugins/"
]

# [project.scripts]
# ov-runtime-tests = "pytest ./tests/test_runtime/" # try to add -s -v into cli!
[tool.pdm.scripts]
ov-runtime-tests = "pytest ./tests/test_runtime/" # try to add -s -v into cli!

[tool.black]
line-length = 160
Expand Down
8 changes: 8 additions & 0 deletions src/bindings/python/setup.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
[metadata]
license_files =
/wheel/readme.txt
../../../licensing/runtime-third-party-programs.txt
../../../licensing/tbb_third-party-programs.txt
../../../licensing/onednn_third-party-programs.txt
../../../LICENSE

[tox:tox]
envlist = py3

Expand Down
Loading
Loading