From 4f2b2ad179a6044e47fec7eeee0739ff7e3cfda6 Mon Sep 17 00:00:00 2001 From: Thomas Ferreira de Lima Date: Mon, 29 May 2023 12:51:50 -0400 Subject: [PATCH] autogenerate updated stubs when wheels in github --- .github/workflows/build.yml | 53 ++++++++++++++++++++++++++++++------ scripts/make_stubs.sh | 54 ++++++++++++++++++++++--------------- 2 files changed, 78 insertions(+), 29 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c79fc93b8..409268ea6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -71,15 +71,12 @@ jobs: with: path: ./wheelhouse/*.whl -# The following was taken from https://cibuildwheel.readthedocs.io/en/stable/deliver-to-pypi/ + # The following was taken from https://cibuildwheel.readthedocs.io/en/stable/deliver-to-pypi/ make_sdist: name: Make SDist runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 # Optional, use if you use setuptools_scm - submodules: true # Optional, use if you have submodules + - uses: actions/checkout@v3 - name: Build SDist run: pipx run build --sdist @@ -88,8 +85,48 @@ jobs: with: path: dist/*.tar.gz - upload_to_test_pypy: + test_pyi: needs: [build, make_sdist] + name: Test if pyi stubs are up-to-date + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + # https://github.com/EndBug/add-and-commit#working-with-prs + if: ${{ github.event_name == 'pull_request' }} + with: + ref: ${{ github.event.pull_request.head.ref }} + - uses: actions/checkout@v3 + if: ${{ github.event_name != 'pull_request' }} + - uses: actions/download-artifact@v3 + with: + name: artifact + path: dist + - name: Install klayout from wheels + run: pip install --no-index --find-links dist/ klayout + - name: Build stubs + run: ./scripts/make_stubs.sh + - name: Verify Changed files + uses: tj-actions/verify-changed-files@v14 + id: verify-changed-files + with: + files: | + src/**/*.pyi + - name: Show changed pyi stubs + if: steps.verify-changed-files.outputs.files_changed == 'true' + run: | + echo "Changed files: ${{ steps.verify-changed-files.outputs.changed_files }}" + - uses: EndBug/add-and-commit@v9 + if: steps.verify-changed-files.outputs.files_changed == 'true' + with: + add: 'src' + default_author: github_actions + message: 'Auto-updated pyi stubs' + - name: Failing because pyi stubs are outdated + if: steps.verify-changed-files.outputs.files_changed == 'true' + run: exit 1 + + upload_to_test_pypy: + needs: [test_pyi] runs-on: ubuntu-latest steps: - uses: actions/download-artifact@v3 @@ -102,10 +139,10 @@ jobs: with: user: __token__ password: ${{ secrets.test_pypi_password }} - repository_url: https://test.pypi.org/legacy/ + repository-url: https://test.pypi.org/legacy/ upload_to_pypi: - needs: [build, make_sdist] + needs: [test_pyi] runs-on: ubuntu-latest if: github.event_name == 'release' && github.event.action == 'published' steps: diff --git a/scripts/make_stubs.sh b/scripts/make_stubs.sh index 1df806a28..b5fc4a9f9 100755 --- a/scripts/make_stubs.sh +++ b/scripts/make_stubs.sh @@ -1,29 +1,40 @@ #!/bin/bash -e -# Generates LVS and DRC documentation +# Generates pyi stubs # # Run this script from a valid build below the repository root, e.g. -# /build-debug. It needs to have a "pymod" installation in +# /build-debug. It needs to have a "pymod" installation in # current directory. inst=$(realpath $(dirname $0)) -scripts=${inst}/drc_lvs_doc -ld=$(realpath .) -pymod="$ld/pymod" +## Detect if klayout pymod libraries are installed +python= +for try_python in python python3; do + if $try_python -c "import klayout.tl" >/dev/null 2>&1; then + python=$try_python + fi +done -export LD_LIBRARY_PATH=$ld -export PYTHONPATH=$pymod +if [ "$python" = "" ]; then + echo "*** Searching for pymod..." -pymod_src=$ld/../src/pymod -if ! [ -e $pymod_src ]; then - echo "*** ERROR: missing pymod sources ($pymod_src) - did you run the script from the build folder below the source tree?" - exit 1 -fi + ld=$(realpath .) + pymod="$ld/pymod" -if ! [ -e $pymod ]; then - echo "*** ERROR: missing pymod folder ($pymod) - did you run the script from the build folder?" - exit 1 + export LD_LIBRARY_PATH=$ld + export PYTHONPATH=$pymod + + pymod_src=$ld/../src/pymod + if ! [ -e $pymod_src ]; then + echo "*** ERROR: missing pymod sources ($pymod_src) - did you run the script from the build folder below the source tree?" + exit 1 + fi + + if ! [ -e $pymod ]; then + echo "*** ERROR: missing pymod folder ($pymod) - did you run the script from the build folder?" + exit 1 + fi fi python= @@ -38,20 +49,21 @@ if [ "$python" = "" ]; then exit 1 fi +pyi_srcdir="$inst/../src/pymod/distutils_src/klayout" + echo "Generating stubs for tl .." -$python $inst/stubgen.py tl >$pymod_src/distutils_src/klayout/tlcore.pyi +$python $inst/stubgen.py tl >$pyi_srcdir/tlcore.pyi echo "Generating stubs for db .." -$python $inst/stubgen.py db tl >$pymod_src/distutils_src/klayout/dbcore.pyi +$python $inst/stubgen.py db tl >$pyi_srcdir/dbcore.pyi echo "Generating stubs for rdb .." -$python $inst/stubgen.py rdb tl,db >$pymod_src/distutils_src/klayout/rdbcore.pyi +$python $inst/stubgen.py rdb tl,db >$pyi_srcdir/rdbcore.pyi echo "Generating stubs for lay .." -$python $inst/stubgen.py lay tl,db,rdb >$pymod_src/distutils_src/klayout/laycore.pyi +$python $inst/stubgen.py lay tl,db,rdb >$pyi_srcdir/laycore.pyi echo "Generating stubs for lib .." -$python $inst/stubgen.py lib tl,db >$pymod_src/distutils_src/klayout/libcore.pyi +$python $inst/stubgen.py lib tl,db >$pyi_srcdir/libcore.pyi echo "Done." -