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

Python packaging automation #468

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 43 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-22.04, macos-13, windows-2022]
os: [ubuntu-22.04]
sofa_branch: [master]
python_version: ['3.10']

Expand Down Expand Up @@ -72,7 +72,7 @@ jobs:
echo ${CCACHE_BASEDIR}
ccache -s
fi

- name: Set env vars for artifacts
shell: bash
run: |
Expand All @@ -85,20 +85,8 @@ jobs:
fi
ARTIFACT_NAME="${PROJECT_NAME}_${ARTIFACT_VERSION}_python-${{ matrix.python_version }}_for-SOFA-${{ steps.sofa.outputs.sofa_version }}_${{ runner.os }}"
echo "ARTIFACT_NAME=$ARTIFACT_NAME" | tee -a $GITHUB_ENV

- name: Create artifact
uses: actions/[email protected]
with:
name: ${{ env.ARTIFACT_NAME }}
path: ${{ env.WORKSPACE_INSTALL_PATH }}

- name: Install artifact
uses: actions/[email protected]
with:
name: ${{ env.ARTIFACT_NAME }}
path: ${{ env.WORKSPACE_ARTIFACT_PATH }}

- name: Set env vars for tests
- name: Set env vars for tests and stub generation
shell: bash
run: |
# Set env vars for tests
Expand All @@ -113,10 +101,8 @@ jobs:
echo "LD_LIBRARY_PATH=$WORKSPACE_ARTIFACT_PATH/lib:$SOFA_ROOT/lib:$LD_LIBRARY_PATH" | tee -a $GITHUB_ENV
fi
echo "PYTHONPATH=$WORKSPACE_ARTIFACT_PATH/lib/python3/site-packages" | tee -a $GITHUB_ENV
# Add execution right on the tests
chmod +x $WORKSPACE_ARTIFACT_PATH/bin/*.Tests${{ steps.sofa.outputs.exe }}

- name: Check environment for tests

- name: Check environments variable for Sofa & SofaPython3
shell: bash
run: |
echo '------ ls -la "$WORKSPACE_SRC_PATH" ------'
Expand All @@ -135,6 +121,42 @@ jobs:
echo '----------------------'
python -c "import sys; print('sys.version = ' + str(sys.version)); print('sys.path = ' + str(sys.path))"

- name: Build python binding and sofa stubs
shell: bash
run: |
#Install pybind11-stubgen
python -m pip install pybind11-stubgen

#Setup env
echo "PYTHONPATH=${{ env.WORKSPACE_INSTALL_PATH }}/lib/python3/site-packages" | tee -a $GITHUB_ENV

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 Sofa"
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 Sofa
fi

- name: Create artifact
uses: actions/[email protected]
with:
name: ${{ env.ARTIFACT_NAME }}
path: ${{ env.WORKSPACE_INSTALL_PATH }}

- name: Install artifact
uses: actions/[email protected]
with:
name: ${{ env.ARTIFACT_NAME }}
path: ${{ env.WORKSPACE_ARTIFACT_PATH }}

- name: Change permission on tests
shell: bash
run: |
# Add execution right on the tests
chmod +x $WORKSPACE_ARTIFACT_PATH/bin/*.Tests${{ steps.sofa.outputs.exe }}

- name: Run test Binding.Sofa.Tests
if: always()
shell: bash
Expand Down Expand Up @@ -163,6 +185,8 @@ jobs:
cd $WORKSPACE_ARTIFACT_PATH
./bin/Bindings.Modules.Tests${{ steps.sofa.outputs.exe }}



deploy:
name: Deploy artifacts
if: always() && startsWith(github.repository, 'sofa-framework') && (startsWith(github.ref, 'refs/heads/') || startsWith(github.ref, 'refs/tags/')) # we are not on a fork and on a branch or a tag (not a PR)
Expand Down
31 changes: 31 additions & 0 deletions scripts/generate_stubs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

usage() {
echo "Usage: generate_stubs.sh <destination> <module_name> "
echo "This script automatically generates stub files for SofaPython3 modules"
}

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

destination_dir=$1
if [ ! -d "$destination_dir/$module_name/" ]; then
echo "Destination directory does not contains a module with name $module_name"
exit 1
fi


for module_name in "${@:2}"
do
echo "Generating stubgen for $module_name in $destination_dir"
pybind11-stubgen $module_name -o out
if [ -d "./out/$module_name/" ]; then
rsync -a ./out/$module_name/ $destination_dir/$module_name/
fi
echo $"Resync terminated for copying '$module_name' in '$destination_dir/$module_name/'"
rm -rf ./out/$module_name
done
rm -rf "./out"
Loading