Skip to content

Build local development python wheels #147

@hjmjohnson

Description

@hjmjohnson

The documentation for the ITKPythonPackage is very confusing.

I want to set up a local development environment where I can make changes to ITK and test how those changes affect python functionality quickly (i.e. without installing docker which I don't have access rights to do).

Reading the existing documentation, and the various scripts used to make wheels does not provide sufficient informatoin about how this system is supposed to work to successfully accomplish the above goal.

NOTE: I do not want to build the nightly ITK as a superbuild of ITKPythonPackaging. I want to package my ITK development tree that is already built with python wrapping.

The following script describes what I am trying to do:

#!/bin/bash
# This script setups up an itk python development environment
# suitable for testing rapid code changes.
#
# This script will be used to provide better documentation
# for how to use the ITKPythonPackage resources.
#
#  COMMON COMMANDLINE USAGE:  MY_DEV_BASE_DIR=/localscratch/Users/${LOGNAME}/ITK_PYTHON_BUILD ./make_custom_ITK_python_environment.sh 

# ---------------------------------------------------------------------------
# Use default values if not set outside this script
MY_DEV_BASE_DIR=${MY_DEV_BASE_DIR:-${HOME}}
MY_DEV_ITK_SOURCE_DIR=${MY_DEV_ITK_SOURCE_DIR:-${MY_DEV_BASE_DIR}/ITK}
MY_DEV_ITK_BINARY_DIR=${MY_DEV_ITK_BINARY_DIR:-${MY_DEV_BASE_DIR}/ITK-python-build}
MY_DEV_ITK_INSTALL_DIR=${MY_DEV_ITK_INSTALL_DIR:-${MY_DEV_BASE_DIR}/ITK-python-install}  #TODO: Why does this need to be set?
MY_DEV_ITK_PYTHON_PACKAGING_DIR=${MY_DEV_ITK_PYTHON_PACKAGING_DIR:-${MY_DEV_BASE_DIR}/ITKPythonPackage}
VIRTUAL_DEV_DIR=${VIRTUAL_DEV_DIR:-${MY_DEV_BASE_DIR}/itk_dev}

# ---------------------------------------------------------------------------
# Get wheel building scripts
if [ ! -d "${MY_DEV_ITK_PYTHON_PACKAGING_DIR}" ];then
  git clone https://github.com/InsightSoftwareConsortium/ITKPythonPackage.git ${MY_DEV_ITK_PYTHON_PACKAGING_DIR}
fi

# Get ITK source code
if [ ! -d "${MY_DEV_ITK_SOURCE_DIR}" ]; then
  git clone  https://github.com/InsightSoftwareConsortium/ITK.git ${MY_DEV_ITK_SOURCE_DIR}
fi

# ---------------------------------------------------------------------------
# Set up a virtual environment with python binary suitable for building ITK
if [ ! -f ${VIRTUAL_DEV_DIR}/bin/activate ]; then
  python3 -m venv ${VIRTUAL_DEV_DIR}
  source ${VIRTUAL_DEV_DIR}/bin/activate
  pip install pip -U
  pip install -r ${MY_DEV_ITK_PYTHON_PACKAGING_DIR}/requirements-dev.txt
else
  source ${VIRTUAL_DEV_DIR}/bin/activate
fi


if [[ ! -f ${MY_DEV_ITK_BINARY_DIR}/CMakeCache.txt ]] ;then
# ---------------------------------------------------------------------------
# Configure ITK development tree
mkdir -p ${MY_DEV_ITK_BINARY_DIR}
cmake -G Ninja \
  -S ${MY_DEV_ITK_SOURCE_DIR} \
  -B ${MY_DEV_ITK_BINARY_DIR} \
  -DCMAKE_BUILD_TYPE:STRING=Release \
  -DCMAKE_CXX_FLAGS:STRING="" \
  -DCMAKE_INSTALL_PREFIX:PATH="${MY_DEV_ITK_INSTALL_DIR}" \
  -DBUILD_SHARED_LIBS:BOOL=ON \
  -DBUILD_TESTING:BOOL=OFF \
  -DITK_WRAP_PYTHON:BOOL=ON \

# ---------------------------------------------------------------------------
# Build ITK development tree
cmake --build ${MY_DEV_ITK_BINARY_DIR} --target all  

fi

# ---------------------------------------------------------------------------
# Make ITK development wheels
pushd ${MY_DEV_ITK_PYTHON_PACKAGING_DIR}
python ${MY_DEV_ITK_PYTHON_PACKAGING_DIR}/setup.py bdist_wheel -- \
  -DITK_BINARY_DIR:PATH=${MY_DEV_ITK_BINARY_DIR} \
  -DITK_SOURCE_DIR:PATH=${MY_DEV_ITK_SOURCE_DIR} \
  -DCMAKE_INSTALL_PREFIX:PATH="${MY_DEV_ITK_INSTALL_DIR}" \
  -DITKPythonPackage_WHEEL_NAME:STRING="itk"

popd 

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions