Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: Add Python example for module loading printouts
- Loading branch information
Showing
4 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
cmake_minimum_required(VERSION 3.16.3) | ||
|
||
project(PrintModuleLoadingPython) | ||
|
||
find_package(ITK REQUIRED) | ||
include(${ITK_USE_FILE}) | ||
|
||
install(FILES Code.py CMakeLists.txt | ||
DESTINATION share/ITKSphinxExamples/Code/Core/Common/PrintModuleLoadingPython/ | ||
COMPONENT Code | ||
) | ||
|
||
enable_testing() | ||
if(ITK_WRAP_PYTHON) | ||
add_test(NAME PrintModuleLoadingPythonTest | ||
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/Code.py) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env python | ||
|
||
# Copyright NumFOCUS | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0.txt | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
### Print ITK Module Loading | ||
|
||
# It can be useful to see how ITK modules are being loaded in order | ||
# to understand module dependencies. `itk.auto_progress` can be used | ||
# to increase verbosity of module loading and filter printouts. | ||
|
||
import itk | ||
|
||
# Enable module loading printouts | ||
itk.auto_progress(2) | ||
|
||
# Load a filter from a module with several dependencies | ||
_ = itk.ForwardFFTImageFilter.values()[0].New() | ||
|
||
# Disable printouts | ||
itk.auto_progress(0) | ||
|
||
# Do work |
34 changes: 34 additions & 0 deletions
34
src/Core/Common/PrintModuleLoadingPython/Documentation.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
:name: PrintModuleLoadingPython | ||
|
||
Print ITK Python Module Loading | ||
================================ | ||
|
||
Synopsis | ||
-------- | ||
|
||
Print how ITK Python module dependencies are lazily loaded. | ||
|
||
|
||
Results | ||
------- | ||
Output:: | ||
|
||
Loading ITKPyBase... done | ||
Loading ITKCommon... done | ||
Loading ITKStatistics... done | ||
Loading ITKImageFilterBase... done | ||
Loading ITKTransform... done | ||
Loading ITKImageFunction... done | ||
Loading ITKImageGrid... done | ||
Loading ITKFFT... done | ||
Loading ITKPyUtils... done | ||
|
||
Code | ||
---- | ||
|
||
Python | ||
...... | ||
|
||
.. literalinclude:: Code.py | ||
:language: python | ||
:lines: 1, 16- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters