Include additional files in itk external module python wheels

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

For Python applications, you can use PythonWheelRuntimeLibraries:

and scripts in setup.py

They then go to your bin package directory. I donā€™t know how to put them where itkExtras.py goesā€¦

1 Like

Thanks! That might be perfect for my use cases.

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

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

from FOOExtras.py import *

Any suggestion is welcomeā€¦

@matt.mccormick might have some suggestions?

Perhaps ITK_WRAP_PYTHON_LIBRARY_IMPORTS is useful here?

2 Likes

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, see

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!

1 Like

@simon.rit beautiful, well done! :clap: :100: