Files
openvino/ngraph/python/build_wheel.py.in
2020-10-18 17:12:25 +02:00

82 lines
3.1 KiB
Python

# ******************************************************************************
# Copyright 2017-2020 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ******************************************************************************
import os
import subprocess
import sys
import venv
print("Building ngraph wheel for Python {}".format(sys.version_info.major))
PYBIND_HEADERS_PATH = "@CMAKE_CURRENT_BINARY_DIR@/pybind11"
NGRAPH_CPP_BUILD_PATH = "@CMAKE_INSTALL_PREFIX@/@NGRAPH_COMPONENT_PREFIX@"
NGRAPH_ONNX_IMPORT_ENABLE = "@NGRAPH_ONNX_IMPORT_ENABLE@"
NGRAPH_VERSION = "@NGRAPH_WHEEL_VERSION@"
PYTHON_API_SOURCE_DIR = "@CMAKE_CURRENT_SOURCE_DIR@"
BUILD_DIR = "@CMAKE_CURRENT_BINARY_DIR@"
BUILD_DEPS = ["setuptools", "wheel", "pip"]
try:
venv_dir = os.path.join(os.path.curdir, "whl_build_venv")
print("Creating a virtualenv to build the wheel in: ", os.path.abspath(venv_dir))
venv.create(venv_dir, with_pip=True)
venv_python = (
os.path.abspath(os.path.join(venv_dir, "Scripts", "python"))
if os.name == "nt"
else os.path.abspath(os.path.join(venv_dir, "bin", "python"))
)
print("Installing build dependencies...")
pip_install_cmd = [venv_python, "-m", "pip", "install", "-U"]
pip_install_cmd.extend(BUILD_DEPS)
subprocess.check_call(pip_install_cmd)
build_env_variables = {
"PYBIND_HEADERS_PATH": PYBIND_HEADERS_PATH,
"NGRAPH_CPP_BUILD_PATH": NGRAPH_CPP_BUILD_PATH,
"NGRAPH_ONNX_IMPORT_ENABLE": NGRAPH_ONNX_IMPORT_ENABLE,
"NGRAPH_VERSION": NGRAPH_VERSION,
}
env = os.environ
env.update(build_env_variables)
print("Running setup.py bdist_wheel")
build_log = subprocess.Popen(
[venv_python, os.path.join(PYTHON_API_SOURCE_DIR, "setup.py"), "bdist_wheel"],
stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env, universal_newlines=True,
)
for line in build_log.stdout:
sys.stdout.write(line)
print("Running setup.py sdist")
subprocess.check_call([venv_python, os.path.join(PYTHON_API_SOURCE_DIR, "setup.py"), "sdist"])
output_dir = os.path.join(PYTHON_API_SOURCE_DIR, "dist")
print("\n>>> NOTE: nGraph Python packages created in ", output_dir)
print("\n".join(os.listdir(output_dir)))
except subprocess.CalledProcessError as err:
print("Could not complete the wheel building process")
print("Command that failed: ", err.cmd)
if err.stdout is not None:
print("Command std output: ", err.stdout.decode("utf-8"))
if err.stderr is not None:
print("Command err output: ", err.stderr.decode("utf-8"))
sys.exit(1)