Skip to content

Commit 5a943bb

Browse files
committed
STYLE: Encapsulate initialization for keeping namespace clean.
1 parent b87caa1 commit 5a943bb

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

Wrapping/Generators/Python/itkConfig.py.in

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ Currently-supported options are:
3434
LazyLoading: Only load an itk library when needed. Before the library is
3535
loaded, the namespace will be inhabited with dummy objects."""
3636

37-
import warnings
38-
import os
3937

4038
# User options
4139
SILENT: int = 0
@@ -59,36 +57,45 @@ def _itk_format_warning(msg, *_, **__):
5957
return str(msg) + "\n"
6058

6159

60+
import warnings
61+
6262
# Redefine the format of the warnings
6363
warnings.formatwarning = _itk_format_warning
6464

6565

66-
def _normalized_path(relative_posix_path):
67-
if relative_posix_path != "None":
68-
file_dir = os.path.split(__file__)[0]
69-
relative_path = relative_posix_path.replace("/", os.sep)
70-
return os.path.normpath(os.path.join(file_dir, relative_path))
66+
def _initialize():
67+
import os
68+
69+
def _normalized_path(relative_posix_path):
70+
if relative_posix_path != "None":
71+
file_dir = os.path.split(__file__)[0]
72+
relative_path = relative_posix_path.replace("/", os.sep)
73+
return os.path.normpath(os.path.join(file_dir, relative_path))
74+
75+
# swig_lib: location of the swig-generated shared libraries
76+
_swig_lib = _normalized_path("@CONFIG_PYTHON_SWIGLIB_DIR@")
7177

78+
# swig_py: location of the xxxPython.py swig-generated python interfaces
79+
_swig_py = _normalized_path("@CONFIG_PYTHON_SWIGPY_DIR@")
7280

73-
# swig_lib: location of the swig-generated shared libraries
74-
swig_lib = _normalized_path("@CONFIG_PYTHON_SWIGLIB_DIR@")
81+
# config_py: location of xxxConfig.py CMake-generated library descriptions
82+
_config_py = _normalized_path("@CONFIG_PYTHON_CONFIGPY_DIR@")
7583

76-
# swig_py: location of the xxxPython.py swig-generated python interfaces
77-
swig_py = _normalized_path("@CONFIG_PYTHON_SWIGPY_DIR@")
84+
# put the itkConfig.py path in the path list
85+
_path = [os.path.join(_config_py, "..")]
86+
# also populate path with the WRAPITK_PYTHON_PATH var
87+
if "WRAPITK_PYTHON_PATH" in os.environ:
88+
_path.extend(os.environ["WRAPITK_PYTHON_PATH"].split(":"))
7889

79-
# config_py: location of xxxConfig.py CMake-generated library descriptions
80-
config_py = _normalized_path("@CONFIG_PYTHON_CONFIGPY_DIR@")
90+
_doxygen_root = _normalized_path("../Doc")
8191

82-
# put the itkConfig.py path in the path list
83-
path = [os.path.join(config_py, "..")]
84-
# also populate path with the WRAPITK_PYTHON_PATH var
85-
if "WRAPITK_PYTHON_PATH" in os.environ:
86-
path.extend(os.environ["WRAPITK_PYTHON_PATH"].split(":"))
92+
return _swig_lib, _swig_py, _config_py, _doxygen_root, _path
8793

88-
doxygen_root = _normalized_path("../Doc")
8994

9095
ITK_GLOBAL_VERSION_STRING: str = "@ITK_VERSION_MAJOR@.@ITK_VERSION_MINOR@.@ITK_VERSION_PATCH@"
9196

97+
(swig_lib, swig_py, config_py, doxygen_root, path) = _initialize()
98+
del _initialize
9299
del _normalized_path
93100
del os
94101
del warnings

0 commit comments

Comments
 (0)