Files
openvino/ngraph/python/build_wheel.py.in

74 lines
3.0 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
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']
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))
subprocess.check_call(['virtualenv', venv_dir])
venv_activator = os.path.abspath(os.path.join(venv_dir, "Scripts", "activate.bat"))
print("Activating the virtualenv...")
os.startfile(venv_activator)
print("Installing build dependencies...")
pip_install_cmd = ['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(['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(['python', os.path.join(PYTHON_API_SOURCE_DIR, 'setup.py'), 'sdist'])
print("Deactivating the temporary build virtualenv")
venv_deactivator = os.path.abspath(os.path.join(venv_dir, "Scripts", "deactivate.bat"))
os.startfile(venv_deactivator)
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)