Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Wrapping/Generators/Python/Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ itk_python_add_test(NAME PythonComplex COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/compl
itk_python_add_test(NAME PythonHelperFunctions COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/helpers.py)
itk_python_add_test(NAME PythonLazyModule COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/lazy.py)
itk_python_add_test(NAME PythonNoLazyModule COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/nolazy.py)
itk_python_add_test(NAME PythonNoDefaultFactories COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/nodefaultfactories.py)
itk_python_add_test(NAME PythonDICOMSeries COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/dicomSeries.py
DATA{${ITK_DATA_ROOT}/Input/DicomSeries/Image0075.dcm}
DATA{${ITK_DATA_ROOT}/Input/DicomSeries/Image0076.dcm}
Expand Down
25 changes: 25 additions & 0 deletions Wrapping/Generators/Python/Tests/nodefaultfactories.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# ==========================================================================
#
# 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.
#
# ==========================================================================*/
import itkConfig

# Override environmental variable default to ignore factories at load time
itkConfig.DefaultFactoryLoading = False
import itk

# Verify the object factory singleton is empty
assert len(itk.ObjectFactoryBase.GetRegisteredFactories()) == 0
4 changes: 3 additions & 1 deletion Wrapping/Generators/Python/itk/support/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import pkg_resources

import itkConfig
from itkConfig import DefaultFactoryLoading as _DefaultFactoryLoading
from itk.support.template_class import itkTemplate


Expand Down Expand Up @@ -236,7 +237,8 @@ def itk_load_swig_module(name: str, namespace=None):
# for some base class(es) defined in the current module.
# For instance, ITKImageIOBase will load any modules defining
# ImageIO objects for reading different image file types.
load_module_needed_factories(name)
if _DefaultFactoryLoading:
load_module_needed_factories(name)

for snakeCaseFunction in l_data.get_snake_case_functions():
namespace[snakeCaseFunction] = getattr(l_module, snakeCaseFunction)
Expand Down
4 changes: 3 additions & 1 deletion Wrapping/Generators/Python/itk/support/lazy.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# ==========================================================================*/
import types
from itk.support import base
from itkConfig import DefaultFactoryLoading as _DefaultFactoryLoading

# Needed to avoid problem with aliasing of itk.set (itkTemplate)
# inside the itk namespace. We need to explictly specify the
Expand Down Expand Up @@ -139,7 +140,8 @@ def __getattribute__(self, attr):
for k, v in namespace.items():
setattr(self, k, v)
value = namespace[attr]
base.load_module_needed_factories(module)
if _DefaultFactoryLoading:
base.load_module_needed_factories(module)
else: # one of the other threads that had been blocking
# waiting for first thread to complete. Now the
# attribute is REQUIRED to be available
Expand Down
1 change: 1 addition & 0 deletions Wrapping/Generators/Python/itkConfig.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def _get_environment_boolean(environment_var: str, default_string: str) -> bool:
return bool(_strtobool(default_string))


DefaultFactoryLoading: bool = _get_environment_boolean("ITK_PYTHON_DEFAULTFACTORYLOADING", "True")
LazyLoading: bool = _get_environment_boolean("ITK_PYTHON_LAZYLOADING", "True")
NotInPlace: bool = _get_environment_boolean("ITK_PYTHON_NOTINPLACE", "False")
del _get_environment_boolean
Expand Down