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

WIP: Macos python build script #127

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -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
"""

Expand Down Expand Up @@ -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)
133 changes: 133 additions & 0 deletions scripts/macos_build_wheels.py
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 1 addition & 1 deletion scripts/windows_build_module_wheels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion scripts/windows_build_wheels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down