Skip to content

Commit

Permalink
BUG: snake case functions are erased
Browse files Browse the repository at this point in the history
When re-running cmake, the dependancies required
to append the `snake_case_functions` to the
`ITK*Config.py` files was incorrect.

Resolves #515
  • Loading branch information
hjmjohnson committed Oct 14, 2020
1 parent 3e79774 commit 8a0a940
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 19 deletions.
10 changes: 8 additions & 2 deletions Wrapping/Generators/Python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -362,16 +362,22 @@ macro(itk_end_wrap_module_python)
if(NOT "${WRAPPER_LIBRARY_NAME}" STREQUAL "ITKPyBase")
set(ITK_WRAP_PYTHON_CONFIGURATION_DEPENDS "'ITKPyBase', ${ITK_WRAP_PYTHON_CONFIGURATION_DEPENDS}")
set(ITK_WRAP_PYTHON_LIBRARY_IMPORTS "import itk.ITKPyBasePython\n${ITK_WRAP_PYTHON_LIBRARY_IMPORTS}")
set(ITK_WRAP_PYTHON_SNAKE_CASE "${ITK_WRAP_PYTHON_BINARY_DIR}/Configuration/${WRAPPER_LIBRARY_NAME}_snake_case.py")
else()
unset(ITK_WRAP_PYTHON_SNAKE_CASE)
endif()
set(ITK_WRAP_PYTHON_LIBRARY_CONFIG_FILE "${ITK_WRAP_PYTHON_BINARY_DIR}/Configuration/${WRAPPER_LIBRARY_NAME}Config.py")

# and create the file, with the var ITK_WRAP_PYTHON_CONFIGURATION_TEMPLATES and
# ITK_WRAP_PYTHON_CONFIGURATION_DEPENDS created earlier
configure_file("${ITK_WRAP_PYTHON_SOURCE_DIR}/ModuleConfig.py.in"
"${ITK_WRAP_PYTHON_BINARY_DIR}/Configuration/${WRAPPER_LIBRARY_NAME}Config.py"
"${ITK_WRAP_PYTHON_LIBRARY_CONFIG_FILE}"
@ONLY)

WRAP_ITK_PYTHON_BINDINGS_INSTALL(/itk/Configuration
"${WRAPPER_LIBRARY_NAME}"
"${ITK_WRAP_PYTHON_BINARY_DIR}/Configuration/${WRAPPER_LIBRARY_NAME}Config.py"
"${ITK_WRAP_PYTHON_LIBRARY_CONFIG_FILE}"
"${ITK_WRAP_PYTHON_SNAKE_CASE}"
)

set(ITK_WRAP_PYTHON_GLOBAL_TIMESTAMP_DECLS )
Expand Down
7 changes: 7 additions & 0 deletions Wrapping/Generators/Python/itkBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,11 @@ def cleanup(self):
path = os.path.join(d + os.sep + "Configuration", conf)
with open(path, "rb") as modulefile:
exec(modulefile.read(), data)
snake_data = {}
snake_conf = module + '_snake_case.py'
snake_path = os.path.join(d + os.sep + "Configuration", snake_conf)
if os.path.exists(snake_path):
with open(snake_path, "rb") as snake_modulefile:
exec(snake_modulefile.read(), snake_data)
data.update(snake_data)
module_data[module] = data
8 changes: 7 additions & 1 deletion Wrapping/Generators/SwigInterface/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ macro(itk_end_wrap_module_swig_interface)
set(deps_imports )

list(APPEND mdx_opts --mdx "${WRAPPER_MASTER_INDEX_OUTPUT_DIR}/${WRAPPER_LIBRARY_NAME}.mdx")

foreach(dep ${WRAPPER_LIBRARY_DEPENDS})
list(APPEND mdx_opts --mdx "${WRAP_ITK_TYPEDEFS_DIRECTORY}/${dep}.mdx")
list(APPEND deps_imports "%import ${dep}.i\n")
Expand All @@ -348,15 +349,20 @@ macro(itk_end_wrap_module_swig_interface)

list(LENGTH i_files number_interface_files)
if(number_interface_files GREATER 0)
# NOTE: snake_case_config_file is both an input and an output to this command.
# the ${IGENERATOR} script appends to this file.
set(snake_case_config_file
"${WRAPPER_LIBRARY_OUTPUT_DIR}/Generators/Python/Configuration/${WRAPPER_LIBRARY_NAME}_snake_case.py")
add_custom_command(
OUTPUT ${i_files} ${typedef_files} ${idx_files}
OUTPUT ${i_files} ${typedef_files} ${idx_files} ${snake_case_config_file}
COMMAND ${Python3_EXECUTABLE} ${IGENERATOR}
${mdx_opts}
${swig_libs}
-w1 -w3 -w51 -w52 -w53 -w54
-A protected -A private
-p ${PYGCCXML_DIR}
-g ${CASTXML_EXECUTABLE}
--snake-case-file "${snake_case_config_file}"
--interface-output-dir "${WRAPPER_MASTER_INDEX_OUTPUT_DIR}"
--library-output-dir "${WRAPPER_LIBRARY_OUTPUT_DIR}"
--submodule-order "${WRAPPER_SUBMODULE_ORDER}"
Expand Down
41 changes: 25 additions & 16 deletions Wrapping/Generators/SwigInterface/igenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,13 @@ def create_interfacefile(self, interfaceFile, idxFile, wrappersNamespace):
dest="submodule_order",
help="List of submodules that must be wrapped in the given order",
)
argParser.add_argument(
"-a",
"--snake-case-file",
action="store",
dest="snake_case_file",
help="The configuration file to be appended to if snake_case_functions are found",
)
options = argParser.parse_args()

sys.path.insert(1, options.pygccxml_path)
Expand Down Expand Up @@ -1234,20 +1241,22 @@ def generate_swig_input(moduleName):
for moduleName in moduleNames:
generate_swig_input(moduleName)

config_file = os.path.join(
options.library_output_dir,
"Generators",
"Python",
"Configuration",
os.path.basename(options.mdx[0])[:-4] + "Config.py",
)
with open(config_file, "a") as ff:
ff.write("snake_case_functions = (")
# Ensure that the functions are sorted alphabetically to ensure consistency
# in the generated file structure.
sorted_snake_case_process_object_functions = sorted(
snake_case_process_object_functions
snake_case_file = options.snake_case_file
main_config_file = snake_case_file.replace("_snake_case.py","Config.py")
if not os.path.exists(main_config_file):
print(
f"ERROR: required {main_config_file} file does not exist\n"
f"can not append to {snake_case_file}\n"
)
for function in sorted_snake_case_process_object_functions:
ff.write("'" + function + "', ")
ff.write(")\n")
sys.exit(-1)
else:
with open(snake_case_file, "a") as ff:
ff.write("snake_case_functions = (")
# Ensure that the functions are sorted alphabetically to ensure consistency
# in the generated file structure.
sorted_snake_case_process_object_functions = sorted(
snake_case_process_object_functions
)
for function in sorted_snake_case_process_object_functions:
ff.write("'" + function + "', ")
ff.write(")\n")

0 comments on commit 8a0a940

Please sign in to comment.