From 71661720b013e7426cd164ca65915df406450b36 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Thu, 25 Apr 2019 11:23:43 -0400 Subject: [PATCH 1/2] scripts: Start build_common.py --- ...wheel_builder_utils.py => build_common.py} | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) rename scripts/internal/{wheel_builder_utils.py => build_common.py} (70%) diff --git a/scripts/internal/wheel_builder_utils.py b/scripts/internal/build_common.py similarity index 70% rename from scripts/internal/wheel_builder_utils.py rename to scripts/internal/build_common.py index bbfac984..d11a3292 100644 --- a/scripts/internal/wheel_builder_utils.py +++ b/scripts/internal/build_common.py @@ -1,7 +1,7 @@ +""" +Code shared by platform-specific build scripts -"""This module provides convenient function facilitating scripting. - -These functions have been copied from scikit-build project. +Some of these functions have been copied from scikit-build project. See https://github.com/scikit-build/scikit-build """ @@ -93,3 +93,19 @@ def __enter__(self): def __exit__(self, typ, val, traceback): os.chdir(self.old_cwd) + +def main(wheel_names=None): + parser = argparse.ArgumentParser(description='Driver script to build ITK Python wheels.') + parser.add_argument('--single-wheel', action='store_true', help='Build a single wheel as opposed to one wheel per ITK module group.') + parser.add_argument('--py-envs', nargs='+', default=DEFAULT_PY_ENVS, + help='Target Python environment versions, e.g. "37-x64".') + parser.add_argument('--no-cleanup', dest='cleanup', action='store_false', help='Do not clean up temporary build files.') + parser.add_argument('cmake_options', nargs='*', help='Extra options to pass to CMake, e.g. -DBUILD_SHARED_LIBS:BOOL=OFF') + args = parser.parse_args() + + build_wheels(single_wheel=args.single_wheel, cleanup=args.cleanup, + py_envs=args.py_envs, wheel_names=wheel_names, + cmake_options=args.cmake_options) + fixup_wheels() + for py_env in args.py_envs: + test_wheels(py_env) From 62f7225cabbdf93f6d819e9cca2fb1baa159c1ad Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Fri, 3 May 2019 15:27:04 -0400 Subject: [PATCH 2/2] WIP: Factor out macos Python script --- scripts/macos_build_wheels.py | 133 +++++++++++++++++++++++++ scripts/windows_build_module_wheels.py | 2 +- scripts/windows_build_wheels.py | 2 +- 3 files changed, 135 insertions(+), 2 deletions(-) create mode 100755 scripts/macos_build_wheels.py diff --git a/scripts/macos_build_wheels.py b/scripts/macos_build_wheels.py new file mode 100755 index 00000000..4b5293ac --- /dev/null +++ b/scripts/macos_build_wheels.py @@ -0,0 +1,133 @@ +#!/usr/bin/env python + +import os +import argparse + +SCRIPT_DIR = os.path.dirname(__file__) +ROOT_DIR = os.path.abspath(os.path.join(SCRIPT_DIR, "..")) +STANDALONE_DIR = os.path.join(ROOT_DIR, "standalone-build") + +print("SCRIPT_DIR: %s" % SCRIPT_DIR) +print("ROOT_DIR: %s" % ROOT_DIR) +print("STANDALONE_DIR: %s" % STANDALONE_DIR) + +sys.path.insert(0, os.path.join(SCRIPT_DIR, "internal")) +from wheel_builder_utils import push_dir, push_env +from windows_build_common import DEFAULT_PY_ENVS, venv_paths + +# import glob +# import os +# import shutil +# from subprocess import check_call +# import sys + +# SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__)) +# ROOT_DIR = os.path.abspath(os.path.join(SCRIPT_DIR, "..")) +# STANDALONE_DIR = os.path.join(ROOT_DIR, "standalone-build") +# PROJECT_NAME = "VTK" + +# sys.path.insert(0, os.path.join(SCRIPT_DIR, "internal")) +# from wheel_builder_utils import push_dir, push_env +# from macos_build_common import DEFAULT_PY_ENVS, venv_paths + + +# def pip_install(python_dir, package, upgrade=True): + # pip = os.path.join(python_dir, "bin", "pip") + # print("Installing %s using %s" % (package, pip)) + # args = [pip, "install"] + # if upgrade: + # args.append("--upgrade") + # args.append(package) + # check_call(args) + + +# def prepare_build_env(python_version): + # python_dir = "/Library/Frameworks/Python.framework/Versions/%s" % python_version + # if not os.path.exists(python_dir): + # raise FileNotFoundError( + # "Aborting. python_dir [%s] does not exist." % python_dir) + + # venv = os.path.join(python_dir, "bin", "pyvenv") + # venv_dir = os.path.join(ROOT_DIR, "venv-%s" % python_version) + # print("Creating python virtual environment: %s" % venv_dir) + # if not os.path.exists(venv_dir): + # check_call([venv, venv_dir]) + # pip_install(venv_dir, "scikit-build") + + +# def build_wheel(python_version, cleanup=False): + + # py_exe, \ + # py_inc_dir, \ + # py_lib, \ + # pip, \ + # ninja_executable, \ + # path = venv_paths(python_version) + + # with push_env(PATH="%s%s%s" % (path, os.pathsep, os.environ["PATH"])): + + # # Install dependencies + # check_call([pip, "install", "--upgrade", + # "-r", os.path.join(ROOT_DIR, "requirements-dev.txt")]) + + # build_type = 'Release' + # build_path = "%s/%s-osx_%s" % (ROOT_DIR, PROJECT_NAME, python_version) + # osx_target="10.9" + + # # Clean up previous invocations + # if cleanup and os.path.exists(build_path): + # shutil.rmtree(build_path) + + # print("#") + # print("# Build single %s wheel" % PROJECT_NAME) + # print("#") + + # # Generate wheel + # check_call([ + # py_exe, + # "setup.py", "bdist_wheel", + # "--build-type", build_type, + # "-G", "Ninja", + # "--plat-name", "macosx-%s-x86_64" % osx_target, + # "--", + # "-DPYTHON_EXECUTABLE:FILEPATH=%s" % py_exe, + # "-DPYTHON_INCLUDE_DIR:PATH=%s" % py_inc_dir, + # "-DPYTHON_LIBRARY:FILEPATH=%s" % py_lib + # ]) + + # # Cleanup + # check_call([py_exe, "setup.py", "clean"]) + + +# def build_wheels(py_envs=DEFAULT_PY_ENVS, cleanup=False): + + # for py_env in py_envs: + # prepare_build_env(py_env) + + # with push_dir(directory=STANDALONE_DIR, make_directory=True): + + # tools_venv = os.path.join(ROOT_DIR, "venv-%s" % DEFAULT_PY_ENVS[0]) + # pip_install(tools_venv, "ninja") + # ninja_executable = os.path.join(tools_venv, "bin", "ninja") + + # # Build standalone project and populate archive cache + # check_call([ + # "cmake", + # "-DVTKPythonPackage_BUILD_PYTHON:BOOL=OFF", + # "-G", "Ninja", + # "-DCMAKE_MAKE_PROGRAM:FILEPATH=%s" % ninja_executable, + # ROOT_DIR + # ]) + + # # Compile wheels re-using standalone project and archive cache + # for py_env in py_envs: + # build_wheel(py_env, cleanup=cleanup) + + +# def main(py_envs=DEFAULT_PY_ENVS, cleanup=True): + + # build_wheels(py_envs=py_envs, cleanup=cleanup) + + +# if __name__ == '__main__': + # main() diff --git a/scripts/windows_build_module_wheels.py b/scripts/windows_build_module_wheels.py index b7396105..e387aea0 100644 --- a/scripts/windows_build_module_wheels.py +++ b/scripts/windows_build_module_wheels.py @@ -11,7 +11,7 @@ sys.path.insert(0, os.path.join(SCRIPT_DIR, "internal")) -from wheel_builder_utils import push_dir, push_env +from build_common import push_dir, push_env from windows_build_common import DEFAULT_PY_ENVS, venv_paths def build_wheels(py_envs=DEFAULT_PY_ENVS): diff --git a/scripts/windows_build_wheels.py b/scripts/windows_build_wheels.py index a5403b1f..939f6661 100644 --- a/scripts/windows_build_wheels.py +++ b/scripts/windows_build_wheels.py @@ -21,7 +21,7 @@ print("STANDALONE_DIR: %s" % STANDALONE_DIR) sys.path.insert(0, os.path.join(SCRIPT_DIR, "internal")) -from wheel_builder_utils import push_dir, push_env +from build_common import push_dir, push_env from windows_build_common import DEFAULT_PY_ENVS, venv_paths