Skip to content

Commit eb9d7ec

Browse files
committed
ENH: Add error checking for required paths
Verify that the required paths exist, and provide diagnostic messages to assist with resolving missing paths. Disable invalid/unused doxygen_root variable as a hard coded invalid path. Changed the value to the string 'None' to retain the API.
1 parent 5be56ea commit eb9d7ec

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

Wrapping/Generators/Python/itkConfig.py.in

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,28 +93,42 @@ warnings.formatwarning = _itk_format_warning
9393
def _initialize():
9494
import os
9595

96-
def _normalized_path(relative_posix_path):
96+
_this_file_dir: str = os.path.dirname(__file__)
97+
98+
def _normalized_path(relative_posix_path: str, message) -> str:
99+
norm_path: str = "None"
97100
if relative_posix_path != "None":
98-
file_dir = os.path.split(__file__)[0]
99101
relative_path = relative_posix_path.replace("/", os.sep)
100-
return os.path.normpath(os.path.join(file_dir, relative_path))
101-
102-
# swig_lib: location of the swig-generated shared libraries
103-
_swig_lib = _normalized_path("@CONFIG_PYTHON_SWIGLIB_DIR@")
104-
105-
# swig_py: location of the xxxPython.py swig-generated python interfaces
106-
_swig_py = _normalized_path("@CONFIG_PYTHON_SWIGPY_DIR@")
107-
108-
# config_py: location of xxxConfig.py CMake-generated library descriptions
109-
_config_py = _normalized_path("@CONFIG_PYTHON_CONFIGPY_DIR@")
102+
norm_path = os.path.normpath(os.path.join(_this_file_dir, relative_path))
103+
if not os.path.exists(norm_path):
104+
print(f"WARNING: Internal configuration path is invalid: {norm_path}")
105+
print(f"WARNING: Invalid: {message}")
106+
return norm_path
107+
108+
_swig_lib: str = _normalized_path(
109+
"@CONFIG_PYTHON_SWIGLIB_DIR@",
110+
"swig_lib: location of the swig-generated shared libraries",
111+
)
112+
_swig_py: str = _normalized_path(
113+
"@CONFIG_PYTHON_SWIGPY_DIR@",
114+
"swig_py: location of the xxxPython.py swig-generated python interfaces",
115+
)
116+
_config_py: str = _normalized_path(
117+
"@CONFIG_PYTHON_CONFIGPY_DIR@",
118+
"config_py: location of xxxConfig.py CMake-generated library descriptions",
119+
)
120+
121+
_config_py_root: str = os.path.dirname(_config_py)
110122

111123
# put the itkConfig.py path in the path list
112-
_path = [os.path.join(_config_py, "..")]
124+
_path = [_config_py_root]
113125
# also populate path with the WRAPITK_PYTHON_PATH var
114126
if "WRAPITK_PYTHON_PATH" in os.environ:
115127
_path.extend(os.environ["WRAPITK_PYTHON_PATH"].split(":"))
116128

117-
_doxygen_root = _normalized_path("../Doc")
129+
# NOT IMPLEMENTED:
130+
# _doxygen_root = _normalized_path("../Doc", "doxygen_root: location of the doxygen xml files.")
131+
_doxygen_root: str = "None"
118132

119133
return _swig_lib, _swig_py, _config_py, _doxygen_root, _path
120134

Wrapping/Generators/Python/itkTemplate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class itkTemplate(object):
149149
__templates__ = collections.OrderedDict()
150150
__class_to_template__ = {}
151151
__named_templates__ = {}
152-
__doxygen_root__ = itkConfig.doxygen_root
152+
# NOT IMPLEMENTED: __doxygen_root__ = itkConfig.doxygen_root
153153

154154
def __new__(cls, name):
155155
# Singleton pattern: we only make a single instance of any Template of

0 commit comments

Comments
 (0)