diff --git a/cmake/morpheus_utils/python/python_module_tools.cmake b/cmake/morpheus_utils/python/python_module_tools.cmake index ac1735b..cd570cc 100644 --- a/cmake/morpheus_utils/python/python_module_tools.cmake +++ b/cmake/morpheus_utils/python/python_module_tools.cmake @@ -613,22 +613,32 @@ macro(__create_python_library MODULE_NAME) # succeed add_dependencies(${PYTHON_ACTIVE_PACKAGE_NAME}-modules ${TARGET_NAME}) - if(_ARGS_BUILD_STUBS) + if(_ARGS_BUILD_STUBS AND NOT _ARGS_IS_CYTHON) # Get the relative path from the project source to the module root cmake_path(RELATIVE_PATH _ARGS_MODULE_ROOT BASE_DIRECTORY ${PROJECT_SOURCE_DIR} OUTPUT_VARIABLE module_root_relative) cmake_path(APPEND PROJECT_BINARY_DIR ${module_root_relative} OUTPUT_VARIABLE module_root_binary_dir) - cmake_path(APPEND module_root_binary_dir ${SOURCE_RELATIVE_PATH} ${MODULE_NAME} "__init__.pyi" OUTPUT_VARIABLE module_binary_stub_file) + cmake_path(APPEND module_root_binary_dir ${SOURCE_RELATIVE_PATH} "stubs" OUTPUT_VARIABLE module_binary_stub_temp_dir) + cmake_path(APPEND module_binary_stub_temp_dir ${SOURCE_RELATIVE_PATH} "${MODULE_NAME}.pyi" OUTPUT_VARIABLE module_binary_stub_temp_file) + cmake_path(APPEND module_root_binary_dir ${SOURCE_RELATIVE_PATH} "${MODULE_NAME}" "__init__.pyi" OUTPUT_VARIABLE module_binary_stub_file) # Before installing, create the custom command to generate the stubs add_custom_command( - OUTPUT ${module_binary_stub_file} - COMMAND ${Python3_EXECUTABLE} -m pybind11_stubgen ${TARGET_NAME} --no-setup-py --log-level WARN -o ./ --root-module-suffix \"\" + OUTPUT ${module_binary_stub_temp_file} + COMMAND + ${Python3_EXECUTABLE} -m pybind11_stubgen --print-safe-value-reprs='.*' --ignore-invalid-identifiers '.*' ${TARGET_NAME} -o ${module_binary_stub_temp_dir} DEPENDS ${PYTHON_ACTIVE_PACKAGE_NAME}-modules $ COMMENT "Building stub for python module ${TARGET_NAME}..." WORKING_DIRECTORY ${module_root_binary_dir} ) + add_custom_command( + OUTPUT ${module_binary_stub_file} + COMMAND ${CMAKE_COMMAND} -E copy ${module_binary_stub_temp_file} ${module_binary_stub_file} + DEPENDS ${module_binary_stub_temp_file} + COMMENT "Moving target ${module_binary_stub_temp_file} to ${module_binary_stub_file}" + ) + # Add a custom target to ensure the stub generation runs add_custom_target(${TARGET_NAME}-stubs ALL DEPENDS ${module_binary_stub_file}