Repository navigation
Hooks: Add hook for ITK. - #3998
fbudin69500 wants to merge 1 commit into
Conversation
7fff729 to
efd6209
Compare
bdfb8fd to
76884ce
Compare
This does not result in PyInstaller support. For PyInstaller support see: pyinstaller/pyinstaller#3998
76884ce to
cb1feea
Compare
|
Hello everyone. It looks like my PR is in pretty good shape. The tests that are failing do not seem related to my PR. Could someone give some feedback to know what needs to be improved before it can be merged? Thanks! |
htgoebel
left a comment
There was a problem hiding this comment.
Thanks for this pull-request. Please see my inline comments.
| @@ -0,0 +1,7 @@ | |||
| from PyInstaller.utils.hooks import collect_data_files | |||
There was a problem hiding this comment.
Please add the standard copyright header
|
|
||
| # If ITK is pip installed, gets all the files. | ||
| itk_datas = collect_data_files('itk', include_py_files=True) | ||
| datas = [x for x in itk_datas if '__pycache__' not in x[0]] |
There was a problem hiding this comment.
This looks very ugly. Please check PyInstaller.utils.hooks for a more appropriate collection function. What shall be collected here in the end?
Why is it required to unconditionally include all files in this name-space? Even if all these modules would be required unconditionally, this will add them as files and not as precompiled modules.
There was a problem hiding this comment.
Unfortunately, because ITK is primarily developed in C++, its interfaces and how to use it is not always very Pythonic. In this case, the import process is different from what is usually done in Python packages (lazy loading, monolithic package). Even though we, ITK developers, are trying to improve some of this, some decisions were made a long time ago and are not easy to address.
Because of the way ITK is wrapped (from C++) in Python, a set of non-conventional files are generated and required for ITK to work in Python. This includes:
- The dynamic libraries.
- Python modules that call functions in the dynamic libraries.
- Additional configuration files that describe the modules and how to load them.
Despite these limitations, including all the (required) files allows to use PyInstaller with ITK seamlessly, which is what some ITK users have asked us to help them with.
There was a problem hiding this comment.
Note that since ITK is divided into smaller subpackages to be able to be uploaded on PyPI, an advanced user that knows exactly what is required could install only the required ITK subpackages. However, due to the lazy-loading and monolithic packaging of ITK, there is no way to find what part of the package is required simply looking at the import statements.
|
|
||
| hiddenimports = ['new'] | ||
|
|
||
| # If ITK is pip installed, gets all the files. |
There was a problem hiding this comment.
"If pip installed" is misleading since file are collected no matter ho it was installed. Please update the comment.
There was a problem hiding this comment.
I moved the comment to the top of the file and rephrased it. I also added a similar phrasing in the commit message. This note is to let the user know that in order for this hook to work, they need to use ITK installed from pip. Many ITK developers directly use ITK from its build tree, and this hook will not work when using that ITK installation.
|
|
||
| # Windows 64 bits only | ||
| # -------------------- | ||
| itk==4.13.1.post1; sys_platform != 'win32' |
There was a problem hiding this comment.
I'm not sure whether we shall add this huge package to the testsuite. This will add about 114MB of download files. This is nine times the size of numpy.
There was a problem hiding this comment.
I removed this requirement. I left the test for users to be able to run it manually if they want to test ITK with PyInstaller. Since it is decorated with the standard PyInstaller test decorator, it will be skipped by default (since ITK will not be installed). In order for the test to run, the user will have to manually install this requirement.
|
I has a deeper look into the code:
|
The Insight Segmentation and Registration Toolkit (ITK) is is an open-source, cross-platform system that provides developers with an extensive suite of software tools for image analysis [1]. ITK is written in C++ and wrapped in Python. Its packages are available on PyPI for Linux, MacOS and Windows [2]. ITK's functionalities are completed with remote modules that are also wrapped in Python and available on PyPI. A sample of the ITK remote modules includes itk-vtkglue [3], itk-isotropicwavelets [4], and itk-ultrasound [5]. Note that ITK's hook will only work if ITK is installed with pip. It will not work when using ITK directly from its build tree. [1] https://itk.org [2] https://pypi.org/project/itk [3] https://pypi.org/project/itk-vtkglue [4] https://pypi.org/project/itk-isotropicwavelets [5] https://pypi.org/project/itk-ultrasound
cb1feea to
06ebe47
Compare
|
Thank you for your review. I have tried to address all your comments and concerns. As mentioned in one of the inline answer to a comment, ITK has a non-conventional way of being imported (lazy loading, monolithic package) which forces us for now to incorporate all the files from the package in the executable generated with PyInstaller. This is not optimal, but it does work. We, ITK developers, would love to improve this in the future, but this will require a lot of change in the current architecture and will take a long time. |
|
@fbudin69500 please re-target this PR at https://github.com/pyinstaller/pyinstaller-hooks-contrib, or include the hooks inside ITK itself. Please also note that there is added file filtering in the |
The Insight Segmentation and Registration Toolkit (ITK) is is an open-source,
cross-platform system that provides developers with an extensive suite of
software tools for image analysis [1]. ITK is written in C++ and wrapped in
Python. Its packages are available on PyPI for Linux, MacOS and Windows [2].
ITK's functionalities are completed with remote modules that are also
wrapped in Python and available on PyPI.
A sample of the ITK remote modules includes itk-vtkglue [3],
itk-isotropicwavelets [4], and itk-ultrasound [5].
[1] https://itk.org
[2] https://pypi.org/project/itk
[3] https://pypi.org/project/itk-vtkglue
[4] https://pypi.org/project/itk-isotropicwavelets
[5] https://pypi.org/project/itk-ultrasound