# ITK External Module GitHub builds for 4.X and 5.X

**URL:** https://discourse.itk.org/t/itk-external-module-github-builds-for-4-x-and-5-x/900
**Category:** Engineering
**Tags:** python, github, external-module
**Created:** [May 6, 2018, 2:59am UTC](https://discourse.itk.org/t/itk-external-module-github-builds-for-4-x-and-5-x/900 "2018-05-06T02:59:36Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [May 6, 2018, 2:59am UTC](https://discourse.itk.org/t/itk-external-module-github-builds-for-4-x-and-5-x/900/1 "2018-05-06T02:59:36Z")

</div>

As described in the [ITKModuleTemplate README](https://github.com/InsightSoftwareConsortium/ITKModuleTemplate), it is possible to build and develop ITK modules on GitHub. The _ITKModuleTemplate_ creates a configuration with continuous integration testing to build and test the module on Linux and build Python packages for Linux, macOS, and Windows.

The builds, by default, use the latest released version of ITK, including the ITK 5.0 alpha tags. With the transition to C++11, the Python packages are not expected to be compatible between ITK 4 and ITK 5.

It is possible to develop and test the module against both 4.13 and 5.X. Here are the steps:

- Create a branch, e.g. `release` or `ITKv4`. Push this branch to GitHub and develop for 4.13 on this branch, while 5.X development can occur on `master`.
- In the `build-and-test` section of `.circleci/config.yml`, build with the `insighttoolkit/module-ci:v4.13` instead of the `insighttoolkit/module-ci:latest` image.
- In the `package` section of `.circleci/config.yml`, set `export ITK_PACKAGE_VERSION=v4.13.0` before calling `dockcross-manylinux-download-cache-and-build-module-wheels.sh`
- In `.travis.yml` add `- export ITK_PACKAGE_VERSION=v4.13.0` before calling `macpython-download-cache-and-build-module-wheels.sh`
- In `appveyor.yml`, set the build command to `$env:ITK_PACKAGE_VERSION='v4.13.0'; .\windows-download-cache-and-build-module-wheels.ps1`
- In `setup.py` set `install_requires` to `itk<5`
- On the 5.X development branch, set the `version=` value in `setup.py` to a [pre-release version](https://www.python.org/dev/peps/pep-0440/#pre-releases), i.e. `X.YaN`, `X.YbN`, or `X.YrcN` where `X.Y` are higher numbers than the versions on the 4.X branch. This will ensure that a user can install the 4.X-based package with `pip install itk-mymodule` or the 5.X-based package with `pip install --pre itk-mymodule`.

[This patch](https://github.com/InsightSoftwareConsortium/ITKTextureFeatures/commit/1c4f89280b3f8f78cb641e1b0894dc1251eda34f) provides as an example.

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [July 9, 2018, 9:15pm UTC](https://discourse.itk.org/t/itk-external-module-github-builds-for-4-x-and-5-x/900/2 "2018-07-09T21:15:35Z")

</div>

A caveat [discovered](http://review.source.kitware.com/#/c/23547/) by @blowekamp for [Remote Modules](https://itk.org/ITKSoftwareGuide/html/Book1/ITKSoftwareGuide-Book1ch9.html#x55-1640009.7):

To update an ITKv4 remote module that has move ITKv4 to a named branch, e.g. `ITKv4` separate from `master`, call

```bash
git checkout master
git merge ITKv4 --strategy ours

```

To help the Git fetching system retrieve the desired history.

---

<div class="post-metadata">

### Author: ![phcerdan](https://discourse.itk.org/user_avatar/discourse.itk.org/phcerdan/32/286_2.png) [@phcerdan](https://discourse.itk.org/u/phcerdan)
#### Post date: [July 10, 2018, 3:19pm UTC](https://discourse.itk.org/t/itk-external-module-github-builds-for-4-x-and-5-x/900/3 "2018-07-10T15:19:47Z")

</div>

Reporting my experience using this in: [https://github.com/InsightSoftwareConsortium/ITKBoneMorphometry/tree/ITKv4](https://github.com/InsightSoftwareConsortium/ITKBoneMorphometry/tree/ITKv4)

So I am creating a ITKv4 branch for a module.  
If I create a new branch `ITKv4` from master, and use:

```bash
git checkout master
git merge ITKv4 --strategy ours

```

I got:

```bash
Already up to date.

```

Which makes sense.

So, I create a diverging commit in `ITKv4`:

```bash
git commit -m 'COMP: Change CI to use ITKv4'

```

You can push the branch in the module repo:

```auto
git push --set-upstream origin ITKv4 

```

And now the result of:

```bash
git checkout master
git merge ITKv4 --strategy ours

```

Creates a new commit in the master branch: `Merge branch ITKv4`

The log shows:

 ![image](https://discourse.itk.org/uploads/default/original/1X/4bc72239a6ec996fb73c326890b3cdd2077dca6f.png)

`git diff HEAD~1` is empty, so master has not been changed with the changes in ITKv4.

And the last step is to push master branch: `git checkout master ; git push`

Let me know if this workflow can be improved. Thanks!

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [July 13, 2018, 3:03pm UTC](https://discourse.itk.org/t/itk-external-module-github-builds-for-4-x-and-5-x/900/4 "2018-07-13T15:03:51Z")

</div>

Correct @phcerdan – thanks for sharing the additional information!

---

<div class="post-metadata">

### Author: ![phcerdan](https://discourse.itk.org/user_avatar/discourse.itk.org/phcerdan/32/286_2.png) [@phcerdan](https://discourse.itk.org/u/phcerdan)
#### Post date: [July 16, 2018, 6:09pm UTC](https://discourse.itk.org/t/itk-external-module-github-builds-for-4-x-and-5-x/900/5 "2018-07-16T18:09:45Z")

</div>

Another point to add to the steps in the first post is to keep minimun required version of cmake compatible with ITKv4:

- ITKv5 upgraded the minimum required version of `CMake` to `3.10.2`, but the ITKv4 branch in the module should avoid this upgrade and keep aligned with ITKv4. The top-level `CMakeLists.txt` in the ITKv4 branch should have:  
`cmake_minimum_required(VERSION 2.8.12)`  
This also avoids errors with the continuous integration scripts for ITKv4, that would fail if the required `CMake` version is very modern.
