-
Notifications
You must be signed in to change notification settings - Fork 358
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
Auto-Generated Stubs for Python Bindings #2028
base: main
Are you sure you want to change the base?
Changes from all commits
6da6881
4357533
bba0997
fc5071a
112587d
f4a16a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,56 @@ if(MATERIALX_PYTHON_OCIO_DIR) | |
install(DIRECTORY "${MATERIALX_PYTHON_OCIO_DIR}/" DESTINATION "${MATERIALX_PYTHON_FOLDER_NAME}/config/" MESSAGE_NEVER) | ||
endif() | ||
|
||
if (MATERIALX_PYTHON_STUBS) | ||
# attempts to find mypy stubgen executable | ||
find_program(_MYPY_STUBGEN_EXECUTABLE "stubgen") | ||
message("Found stubgen executable: _MYPY_STUBGEN_EXECUTABLE=${MATERIALX_PYTHON_STUBS}") | ||
|
||
# check if stubgen can be accessed | ||
execute_process( | ||
COMMAND ${_MYPY_STUBGEN_EXECUTABLE} --help | ||
OUTPUT_VARIABLE _MYPY_STUBGEN_HELP_OUTPUT | ||
ERROR_VARIABLE _MYPY_STUBGEN_HELP_OUTPUT | ||
RESULT_VARIABLE _MYPY_STUBGEN_HELP_EXITCODE | ||
COMMAND_ECHO STDOUT | ||
) | ||
|
||
# build stubs if stubgen could be found properly | ||
if (_MYPY_STUBGEN_HELP_EXITCODE EQUAL "0") | ||
message("mypy stubgen found successfully, setting up Python Stubs build process...") | ||
install(CODE " | ||
message(\"Building Python Stubs...\") | ||
message(\"MATERIALX_PYTHON_FOLDER_NAME=${MATERIALX_PYTHON_FOLDER_NAME}\") | ||
message(\"CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}\") | ||
if(EXISTS ${_MYPY_STUBGEN_EXECUTABLE}) | ||
execute_process( | ||
COMMAND ${_MYPY_STUBGEN_EXECUTABLE} -p MaterialX --inspect-mode -o ${CMAKE_INSTALL_PREFIX}/python -v --ignore-errors | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if |
||
WORKING_DIRECTORY \"${CMAKE_INSTALL_PREFIX}/python\" | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
COMMAND_ECHO STDOUT | ||
COMMAND_ERROR_IS_FATAL ANY | ||
) | ||
message(\"Finished Building Python.\") | ||
else() | ||
message( | ||
FATAL_ERROR | ||
\"MATERIALX_PYTHON_STUBS=${MATERIALX_PYTHON_STUBS} but mypy stubgen doesn't exist!\" | ||
) | ||
endif() | ||
" | ||
) | ||
else () | ||
# prints errors if mypy couldn't be found | ||
# TODO: should this be a fatal error or? | ||
message( | ||
FATAL_ERROR | ||
"MATERIALX_PYTHON_STUBS=${MATERIALX_PYTHON_STUBS} but" | ||
" mypy stubgen not found: status=${_MYPY_STUBGEN_HELP_EXITCODE}:" | ||
" ${_MYPY_STUBGEN_HELP_OUTPUT}" | ||
) | ||
endif () | ||
endif() | ||
|
||
if(MATERIALX_INSTALL_PYTHON AND PYTHON_EXECUTABLE AND NOT SKBUILD) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you need to move this before stubgen, so it get's run after install. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. However to include the stubs in the package itself, You need to repackage. I think the least number of steps is
I think this should cover locally packaged plus packages generated via SKBUILD. ( I think think the wheels logic is run afterwards as an additional workflow in github actions ). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which part do you mean exactly? Or the whole code block? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for lack of clarity:
|
||
set(SETUP_PY "${CMAKE_INSTALL_PREFIX}/python/setup.py") | ||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in" "${SETUP_PY}") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is set then you need to ensure that MATERIALX_INSTALL_PYTHON is set as well
since your running stubgen off the installed package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use https://cmake.org/cmake/help/latest/module/CMakeDependentOption.html for that purpose.