# Include additional files in itk external module python wheels

**URL:** https://discourse.itk.org/t/include-additional-files-in-itk-external-module-python-wheels/5794
**Category:** Engineering
**Created:** [March 11, 2023, 4:16pm UTC](https://discourse.itk.org/t/include-additional-files-in-itk-external-module-python-wheels/5794 "2023-03-11T16:16:21Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Stephen\_Aylward](https://discourse.itk.org/user_avatar/discourse.itk.org/stephen_aylward/32/654_2.png) [@Stephen\_Aylward](https://discourse.itk.org/u/Stephen_Aylward)
#### Post date: [March 11, 2023, 4:16pm UTC](https://discourse.itk.org/t/include-additional-files-in-itk-external-module-python-wheels/5794/1 "2023-03-11T16:16:21Z")

</div>

The new scripts for building external modules are amazing!

What is the magic to include additional files in a python wheel for an external module using the new scripts?

For example, if I have a project directory

itkFOO

- CMakeLists.txt
- setup.py
- .github/workflows/build-test-package.yml
- src
  - CMakeLists.txt
  - foo.cxx

- include
  - foo.h

- wrapping
  - CMakeLists.txt
  - foo.wrap

- extras
  - FOOExtras.py

How can I include FOOExtras.py in the wheel?

Could perhaps copy to ITK-build/Wrapping/Generators/Python/itk, but I’m guessing that there is a much cleaner way.

Thanks,  
Stephen

---

<div class="post-metadata">

### Author: ![simon.rit](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/f08c70/32.png) [@simon.rit](https://discourse.itk.org/u/simon.rit)
#### Post date: [March 13, 2023, 6:19am UTC](https://discourse.itk.org/t/include-additional-files-in-itk-external-module-python-wheels/5794/2 "2023-03-13T06:19:02Z")

</div>

For Python applications, you can use `PythonWheelRuntimeLibraries`:

> <https://github.com/RTKConsortium/RTK/blob/master/CMakeLists.txt#L271-L276>

and `scripts` in `setup.py`

> <https://github.com/RTKConsortium/RTK/blob/master/setup.py#L50-L55>

They then go to your `bin` package directory. I don’t know how to put them where `itkExtras.py` goes…

---

<div class="post-metadata">

### Author: ![Stephen\_Aylward](https://discourse.itk.org/user_avatar/discourse.itk.org/stephen_aylward/32/654_2.png) [@Stephen\_Aylward](https://discourse.itk.org/u/Stephen_Aylward)
#### Post date: [March 13, 2023, 2:25pm UTC](https://discourse.itk.org/t/include-additional-files-in-itk-external-module-python-wheels/5794/3 "2023-03-13T14:25:09Z")

</div>

Thanks! That might be perfect for my use cases.

---

<div class="post-metadata">

### Author: ![simon.rit](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/f08c70/32.png) [@simon.rit](https://discourse.itk.org/u/simon.rit)
#### Post date: [March 14, 2023, 3:03pm UTC](https://discourse.itk.org/t/include-additional-files-in-itk-external-module-python-wheels/5794/4 "2023-03-14T15:03:34Z")

</div>

Since I do not want to include applications only, I also found a way to add python files using `WRAP_ITK_PYTHON_BINDINGS_INSTALL`:

> <https://github.com/RTKConsortium/RTK/pull/537/files#diff-1e7de1ae2d059d21e1dd75d5812d5a34b0222cef273b7c3a2af62eb747f9d20aR278-R282>

It seems to work so far. What I now miss is a way to add an initialization line in the module init, e.g.

```plaintext
from FOOExtras.py import *

```

Any suggestion is welcome…

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [March 14, 2023, 4:36pm UTC](https://discourse.itk.org/t/include-additional-files-in-itk-external-module-python-wheels/5794/5 "2023-03-14T16:36:34Z")

</div>

@matt.mccormick might have some suggestions?

---

<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: [March 14, 2023, 5:35pm UTC](https://discourse.itk.org/t/include-additional-files-in-itk-external-module-python-wheels/5794/6 "2023-03-14T17:35:49Z")

</div>

Perhaps [`ITK_WRAP_PYTHON_LIBRARY_IMPORTS`](https://github.com/InsightSoftwareConsortium/ITK/blob/6b0d4b83376da7adda33f4d9ff5e422817ec3ad2/Wrapping/Generators/Python/main_module_ext.i.in#L9) is useful here?

---

<div class="post-metadata">

### Author: ![simon.rit](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/f08c70/32.png) [@simon.rit](https://discourse.itk.org/u/simon.rit)
#### Post date: [March 30, 2023, 5:47am UTC](https://discourse.itk.org/t/include-additional-files-in-itk-external-module-python-wheels/5794/7 "2023-03-30T05:47:24Z")

</div>

A follow-up on your suggestion. In wrapping/CMakeLists.txt, I have modified `ITK_WRAP_PYTHON_LIBRARY_IMPORTS`. It works if RTK is loaded (no LazyLoading or something loaded the module beforehand). If the first RTK attribute is in one of the imports and lazy loading is on, ITK does not know the symbol. I have found a work around with [` __init_module__.py`](https://github.com/InsightSoftwareConsortium/ITK/blob/master/Wrapping/Generators/Python/itk/ __init__.py#L145), see

> <https://github.com/RTKConsortium/RTK/pull/537/files#diff-bad50410226ffa07e9aaacdc70887972fd36f235972c3110156999ee83962159>

What do you think of this “solution” to add the new attributes to the lazy list? It seems a bit too low level but I haven’t found a better solution… Suggestions are welcome!

---

<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: [March 30, 2023, 7:45pm UTC](https://discourse.itk.org/t/include-additional-files-in-itk-external-module-python-wheels/5794/8 "2023-03-30T19:45:07Z")

</div>

@simon.rit beautiful, well done! 👏 💯
