Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pybind11-stubgen to v2.4.2 #89

Open
wants to merge 6 commits into
base: branch-25.02
Choose a base branch
from
18 changes: 14 additions & 4 deletions cmake/morpheus_utils/python/python_module_tools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<TARGET_OBJECTS:${TARGET_NAME}>
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}
Expand Down