Skip to content
Merged
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
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 3.16.3 FATAL_ERROR)
cmake_minimum_required(VERSION 3.26.6 FATAL_ERROR)
# NOTE: 3.26.6 is the first cmake vesion to support Development.SABIModule

project(ITKPythonPackage CXX)

Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# ITK Python Package

This project provides a `setup.py` script to build ITK Python binary
packages and infrastructure to build ITK external module Python
packages.
This project configures pyproject.toml files and manages environmental
variables needed to build ITK Python binary wheels on MacOS, Linux, and Windows platforms.
Scripts are available for both [ITK infrastructure](https://github.com/insightSoftwareConsortium/ITK) and
ITK external module Python packages.

The Insight Toolkit (ITK) is an open-source, cross-platform system that provides developers
with an extensive suite of software tools for image analysis.
Expand All @@ -16,14 +17,14 @@ or at the [ITK GitHub homepage](https://github.com/insightSoftwareConsortium/ITK
- [Frequently Asked Questions](#frequently-asked-questions)
- [Additional Information](#additional-information)

## Using ITK Python Packages
## Using ITK Python Packages (pre-built, or locally built)

ITKPythonPackage scripts can be used to produce [Python](https://www.python.org/) packages
for ITK and ITK external modules. The resulting packages can be
hosted on the [Python Package Index (PyPI)](https://pypi.org/)
for easy distribution.

### Installation
### Installation of pre-built packages

To install baseline ITK Python packages:

Expand Down
6 changes: 3 additions & 3 deletions docs/Build_ITK_Module_Python_packages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Congratulations! Your packages can be installed with the commands::
python -m pip install itk-<your-short-module-name>

where `itk-<your-short-module-name>` is the short name for your module that is
specified in your setup.py file.
specified in the configured `pyproject.toml` file.

Automate PyPI Package Uploads
-----------------------------
Expand All @@ -118,7 +118,7 @@ and for the scope use::
itk-<your-short-module-name>

where `<your-short-module-name>` is the short name for your module that is
specified in your setup.py file. That scope will be available if you have
specified in your configured `pyproject.toml` file. That scope will be available if you have
already uploaded a first set of wheels via twine as described above; and that
is the recommended approach. Otherwise, if you are creating the project at
this time, choose an unlimited scope, but be careful with the created token.
Expand All @@ -137,7 +137,7 @@ individual package as a best practice.
:alt: GitHub PyPI token secret

To push packages to PyPI, first, make sure to update the `version` for your
package in the *setup.py* file. The initial version might be `0.1.0` or
package in the *pyproject.toml* file. The initial version might be `0.1.0` or
`1.0.0`. Subsequent versions should follow
`semantic versioning <https://semver.org/>`_.

Expand Down
73 changes: 37 additions & 36 deletions docs/Build_ITK_Python_packages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ automated. The following sections outline how to use the associated scripts.
Linux
-----

On any linux distribution with docker and bash installed, running the script dockcross-manylinux-build-wheels.sh will create 64-bit wheels for both python 2.x and python 3.x in the dist directory.
On any linux distribution with docker and bash installed, running the script dockcross-manylinux-build-wheels.sh will create 64-bit wheels for python 3.9+ in the dist directory.

For example::

Expand Down Expand Up @@ -94,38 +94,39 @@ files are created and deleted quickly, which can result in Access Denied
errors. Windows 10 ships with an antivirus application, Windows Defender, that
is enabled by default.

sdist
-----

To create source distributions, sdist's, that will be used by pip to compile a wheel for installation if a binary wheel is not available for the current Python version or platform::

$ python setup.py sdist --formats=gztar,zip
[...]

$ ls -1 dist/
itk-4.11.0.dev20170216.tar.gz
itk-4.11.0.dev20170216.zip

Manual builds
=============

Building ITK Python wheels
--------------------------

Build the ITK Python wheel with the following command::

python3 -m venv build-itk
./build-itk/bin/pip install --upgrade pip
./build-itk/bin/pip install -r requirements-dev.txt numpy
./build-itk/bin/python setup.py bdist_wheel

Build a wheel for a custom version of ITK
-----------------------------------------

To build a wheel for a custom version of ITK, point to your ITK git repository
with the `ITK_SOURCE_DIR` CMake variable::

./build-itk/bin/python setup.py bdist_wheel -- \
-DITK_SOURCE_DIR:PATH=/path/to/ITKPythonPackage-core-build/ITK

Other CMake variables can also be passed with `-D` after the double dash.
.. The below instructions are outdated and need to be re-written
.. sdist
.. -----
..
.. To create source distributions, sdist's, that will be used by pip to compile a wheel for installation if a binary wheel is not available for the current Python version or platform::
..
.. $ python setup.py sdist --formats=gztar,zip
.. [...]
..
.. $ ls -1 dist/
.. itk-4.11.0.dev20170216.tar.gz
.. itk-4.11.0.dev20170216.zip
..
.. Manual builds
.. =============
..
.. Building ITK Python wheels
.. --------------------------
..
.. Build the ITK Python wheel with the following command::
..
.. python3 -m venv build-itk
.. ./build-itk/bin/pip install --upgrade pip
.. ./build-itk/bin/pip install -r requirements-dev.txt numpy
.. ./build-itk/bin/python setup.py bdist_wheel
..
.. Build a wheel for a custom version of ITK
.. -----------------------------------------
..
.. To build a wheel for a custom version of ITK, point to your ITK git repository
.. with the `ITK_SOURCE_DIR` CMake variable::
..
.. ./build-itk/bin/python setup.py bdist_wheel -- \
.. -DITK_SOURCE_DIR:PATH=/path/to/ITKPythonPackage-core-build/ITK
..
.. Other CMake variables can also be passed with `-D` after the double dash.
2 changes: 1 addition & 1 deletion docs/code/CompareITKTypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

import itk

itk.F == itk.ctype('float') # True
itk.F == itk.ctype("float") # True
8 changes: 4 additions & 4 deletions docs/code/CreateBaseline.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import itk
import sys

image = itk.Image[itk.UC,2].New()
image.SetRegions([10,10])
image.SetOrigin([0,0])
image.SetSpacing([0.5,0.5])
image = itk.Image[itk.UC, 2].New()
image.SetRegions([10, 10])
image.SetOrigin([0, 0])
image.SetSpacing([0.5, 0.5])
image.Allocate()
image.FillBuffer(1)
itk.imwrite(image, sys.argv[1])
2 changes: 1 addition & 1 deletion docs/code/ExplicitInstantiation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

# An apriori ImageType
PixelType = itk.F
ImageType = itk.Image[PixelType,2]
ImageType = itk.Image[PixelType, 2]
image = itk.imread(input_filename, PixelType)

# An image type dynamically determined from the type on disk
Expand Down
4 changes: 2 additions & 2 deletions docs/code/InstantiateITKObjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import itk

# Instantiate SmartPointer objects
InputType = itk.Image[itk.F,3]
OutputType = itk.Image[itk.F,3]
InputType = itk.Image[itk.F, 3]
OutputType = itk.Image[itk.F, 3]
median = itk.MedianImageFilter[InputType, OutputType].New()

# Instantiate non-SmartPointer objects
Expand Down
12 changes: 6 additions & 6 deletions docs/code/MixingITKAndNumPy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import sys
from pathlib import Path

data_dir = Path(__file__).parent.resolve() / '..' / 'data'
data_dir = Path(__file__).parent.resolve() / ".." / "data"

input_image_filename = sys.argv[1]
temp_dir = Path(input_image_filename).parent
output_image_filename = sys.argv[2]
input_mesh_filename = data_dir / 'cow.vtk'
output_mesh_filename = temp_dir / 'cow.vtk'
input_transform_filename = data_dir / 'rigid.tfm'
output_transform_filename = temp_dir / 'rigid.tfm'
input_mesh_filename = data_dir / "cow.vtk"
output_mesh_filename = temp_dir / "cow.vtk"
input_transform_filename = data_dir / "rigid.tfm"
output_transform_filename = temp_dir / "rigid.tfm"

import itk
import numpy as np
Expand Down Expand Up @@ -116,7 +116,7 @@


# VNL matrix from np.ndarray
arr = np.zeros([3,3], np.uint8)
arr = np.zeros([3, 3], np.uint8)
matrix = itk.vnl_matrix_from_array(arr)

# Array from VNL matrix
Expand Down
3 changes: 3 additions & 0 deletions docs/code/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@
import tempfile
import shutil


def add_test(cmd):
cmd.insert(0, sys.executable)
subprocess.check_call(cmd)


def cleanup(files):
for f in files:
if os.path.isdir(f):
shutil.rmtree(f)
else:
os.remove(f)


# Create temporary folder to save output images
temp_folder = tempfile.mkdtemp()
# Change current working directory to find scripts
Expand Down
60 changes: 34 additions & 26 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os

# -*- coding: utf-8 -*-
#
# ITKPythonPackage documentation build configuration file, created by
Expand Down Expand Up @@ -34,30 +35,30 @@
extensions = []

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
source_suffix = ".rst"

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General information about the project.
project = u'ITKPythonPackage'
copyright = u'2017, Jean-Christophe Fillion-Robin and Matt McCormick'
author = u'Jean-Christophe Fillion-Robin and Matt McCormick'
project = "ITKPythonPackage"
copyright = "2017, Jean-Christophe Fillion-Robin and Matt McCormick"
author = "Jean-Christophe Fillion-Robin and Matt McCormick"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = u''
version = ""
# The full version, including alpha/beta/rc tags.
release = u''
release = ""

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand All @@ -69,10 +70,10 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False
Expand All @@ -83,7 +84,7 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'default'
html_theme = "default"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand All @@ -94,13 +95,13 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]


# -- Options for HTMLHelp output ------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'ITKPythonPackagedoc'
htmlhelp_basename = "ITKPythonPackagedoc"


# -- Options for LaTeX output ---------------------------------------------
Expand All @@ -109,15 +110,12 @@
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
Expand All @@ -127,8 +125,13 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'ITKPythonPackage.tex', u'ITKPythonPackage Documentation',
u'Jean-Christophe Fillion-Robin and Matt McCormick', 'manual'),
(
master_doc,
"ITKPythonPackage.tex",
"ITKPythonPackage Documentation",
"Jean-Christophe Fillion-Robin and Matt McCormick",
"manual",
),
]


Expand All @@ -137,8 +140,7 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'itkpythonpackage', u'ITKPythonPackage Documentation',
[author], 1)
(master_doc, "itkpythonpackage", "ITKPythonPackage Documentation", [author], 1)
]


Expand All @@ -148,19 +150,25 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'ITKPythonPackage', u'ITKPythonPackage Documentation',
author, 'ITKPythonPackage', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"ITKPythonPackage",
"ITKPythonPackage Documentation",
author,
"ITKPythonPackage",
"One line description of project.",
"Miscellaneous",
),
]


# -- Read The Docs -----------------------------------------------------

# on_rtd is whether we are on readthedocs.io
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
on_rtd = os.environ.get("READTHEDOCS", None) == "True"

if not on_rtd: # only import and set the theme if we're building docs locally
import sphinx_rtd_theme
html_theme = 'sphinx_rtd_theme'
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]

html_theme = "sphinx_rtd_theme"
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
Loading