Skip to content

Commit

Permalink
Generating stubs through cmake does not work as expected with ninja w…
Browse files Browse the repository at this point in the history
…ith a in build startegy and isnt working in install because the install order is random
  • Loading branch information
bakpaul committed Sep 19, 2024
1 parent 7a26c5e commit 55c8c76
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
18 changes: 17 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,23 @@ jobs:
echo ${CCACHE_BASEDIR}
ccache -s
fi
- name: Generate stubfiles
shell: bash
run: |
#Install stubgen
${{ steps.sofa.outputs.python_exe }} -m pip install mypy
if [[ "$RUNNER_OS" == "Windows" ]]; then
cmd //c "${{ steps.sofa.outputs.vs_vsdevcmd }} \
&& cd /d ${{ env.WORKSPACE_INSTALL_PATH }}/lib/python3/site-packages/ \
&& bash ${{ env.WORKSPACE_SRC_PATH }}/scripts/generate_stubs.sh ${{ env.WORKSPACE_INSTALL_PATH }}/lib/python3/site-packages/
else
cd ${{ env.WORKSPACE_INSTALL_PATH }}/lib/python3/site-packages/
/bin/bash ${{ env.WORKSPACE_SRC_PATH }}/scripts/generate_stubs.sh ${{ env.WORKSPACE_INSTALL_PATH }}/lib/python3/site-packages/
fi
- name: Set env vars for artifacts
shell: bash
run: |
Expand Down
14 changes: 0 additions & 14 deletions bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,6 @@ sofa_create_component_in_package_with_targets(
TARGETS ${PROJECT_NAME}
)

option(SP3_GENERATE_STUBS "Generate stub files at install step required for auto-completion" OFF)
if(SP3_GENERATE_STUBS)
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
set(bash_name bash)
else ()
set(bash_name /bin/bash)
endif ()
add_custom_target(GenerateStubs ALL ${bash_name} ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/generate_stubs.sh ${CMAKE_BUILD_DIR}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/lib/${SP3_PYTHON_PACKAGES_DIRECTORY}/
COMMENT "Generating stub files"
)
add_dependencies(GenerateStubs ${PROJECT_NAME})
endif()

#if (SP3_COMPILED_AS_SOFA_SUBPROJECT)
# ## Python configuration file (build tree), the lib in the source dir (easier while developping .py files)
# file(WRITE "${CMAKE_BINARY_DIR}/etc/sofa/python.d/plugin.SofaPython3.bindings" "${CMAKE_BINARY_DIR}/${SP3_PYTHON_PACKAGES_DIRECTORY}\n")
Expand Down
14 changes: 14 additions & 0 deletions scripts/generate_stubs.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
#!/bin/bash

usage() {
echo "Usage: generate_stubs.sh <sofa-python3-site-packages-dir> "
echo "This script automatically generates stub files for SofaPython3 modules"
}

if [ "$#" -eq 1 ]; then
WORK_DIR=$1
else
usage; exit 1
fi

cd $WORK_DIR


for module_name in *; do
echo "Generating stubgen for $module_name"
stubgen -p $module_name --include-docstrings --inspect-mode
Expand Down

0 comments on commit 55c8c76

Please sign in to comment.