From dc51e0897925ee1ba58670c5e91ba83bef6c45b6 Mon Sep 17 00:00:00 2001 From: Sergei Izmailov Date: Thu, 31 Aug 2023 18:09:53 +0900 Subject: [PATCH] chore: Split testing script, generate `.patch` --- .github/workflows/ci.yml | 20 ++++-- .gitignore | 1 + tests/check-demo-stubs-generation.sh | 70 +++++++++++++++++++ .../{run-tests.sh => install-demo-module.sh} | 39 +---------- 4 files changed, 88 insertions(+), 42 deletions(-) create mode 100755 tests/check-demo-stubs-generation.sh rename tests/{run-tests.sh => install-demo-module.sh} (68%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eaec86c..ab0a580 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -69,9 +69,19 @@ jobs: - name: Install pybind11-stubgen run: pip install . - - name: Run tests + - name: Install demo module shell: bash - run: > - ./tests/run-tests.sh \ - --pybind11-branch "${{ matrix.pybind11-branch }}" \ - --stubs-sub-dir "stubs/python-${{ matrix.python }}/pybind11-${{ matrix.pybind11-branch }}" \ + run: ./tests/install-demo-module.sh --pybind11-branch "${{ matrix.pybind11-branch }}" + + - name: Check stubs generation + shell: bash + run: ./tests/check-demo-stubs-generation.sh --stubs-sub-dir "stubs/python-${{ matrix.python }}/pybind11-${{ matrix.pybind11-branch }}" + + - name: Archive patch + uses: actions/upload-artifact@v3 + if: failure() + with: + name: "python-${{ matrix.python }}-pybind-${{ matrix.pybind11-branch }}.patch" + path: "./tests/stubs/python-${{ matrix.python }}/pybind11-${{ matrix.pybind11-branch }}.patch" + retention-days: 30 + if-no-files-found: ignore diff --git a/.gitignore b/.gitignore index 59443dd..8a33787 100644 --- a/.gitignore +++ b/.gitignore @@ -209,3 +209,4 @@ cython_debug/ tmp +*.patch diff --git a/tests/check-demo-stubs-generation.sh b/tests/check-demo-stubs-generation.sh new file mode 100755 index 0000000..5c3f21f --- /dev/null +++ b/tests/check-demo-stubs-generation.sh @@ -0,0 +1,70 @@ +#!/bin/bash + +set -e + +function parse_args() { + + CLEAR='\033[0m' + RED='\033[0;31m' + + function usage() { + if [ -n "$1" ]; then + echo -e "${RED}👉 $1${CLEAR}\n"; + fi + echo "Usage: $0 --stubs-sub-dir STUBS_SUB_DIR" + echo " --stubs-sub-dir stubs output dir relative to this script directory" + exit 1 + } + + # parse params + while [[ "$#" > 0 ]]; do case $1 in + --stubs-sub-dir) STUBS_SUB_DIR="$2";shift;shift;; + *) usage "Unknown parameter passed: $1"; shift; shift;; + esac; done + + # verify params + if [ -z "$STUBS_SUB_DIR" ]; then usage "STUBS_SUB_DIR is not set"; fi; + + TESTS_ROOT="$(readlink -m "$(dirname "$0")")" + STUBS_DIR=$(readlink -m "${TESTS_ROOT}/${STUBS_SUB_DIR}") +} + +remove_stubs() { + rm -rf "${STUBS_DIR}/*" ; +} + +run_stubgen() { + pybind11-stubgen \ + demo \ + --output-dir=${STUBS_DIR} \ + --numpy-array-wrap-with-annotated-fixed-size \ + --ignore-invalid-expressions="\(anonymous namespace\)::(Enum|Unbound)" \ + --ignore-unresolved-names="typing\.Annotated" \ + --exit-code +} + +format_stubs() { + ( + cd "${STUBS_DIR}" ; + black . ; + isort --profile=black . ; + ) +} + +check_stubs() { + git add --all "${STUBS_DIR}" ; + ( + set -o pipefail ; + git diff --exit-code HEAD -- "${STUBS_DIR}" | tee "${STUBS_DIR}.patch" ; + ) +} + +main () { + parse_args "$@" + remove_stubs + run_stubgen + format_stubs + check_stubs +} + +main "$@" diff --git a/tests/run-tests.sh b/tests/install-demo-module.sh similarity index 68% rename from tests/run-tests.sh rename to tests/install-demo-module.sh index b9101e0..3b1f35d 100755 --- a/tests/run-tests.sh +++ b/tests/install-demo-module.sh @@ -11,30 +11,26 @@ function parse_args() { if [ -n "$1" ]; then echo -e "${RED}👉 $1${CLEAR}\n"; fi - echo "Usage: $0 --pybind11-branch PYBIND11_BRANCH --stubs-sub-dir STUBS_SUB_DIR" + echo "Usage: $0 --pybind11-branch PYBIND11_BRANCH" echo " --pybind11-branch name of pybind11 branch" - echo " --stubs-sub-dir stubs output dir relative to this script directory" exit 1 } # parse params while [[ "$#" > 0 ]]; do case $1 in --pybind11-branch) PYBIND11_BRANCH="$2"; shift;shift;; - --stubs-sub-dir) STUBS_SUB_DIR="$2";shift;shift;; *) usage "Unknown parameter passed: $1"; shift; shift;; esac; done # verify params if [ -z "$PYBIND11_BRANCH" ]; then usage "PYBIND11_BRANCH is not set"; fi; - if [ -z "$STUBS_SUB_DIR" ]; then usage "STUBS_SUB_DIR is not set"; fi; - TESTS_ROOT="$(dirname "$0")" + TESTS_ROOT="$(readlink -m "$(dirname "$0")")" PROJECT_ROOT="${TESTS_ROOT}/.." TEMP_DIR="${PROJECT_ROOT}/tmp/pybind11-${PYBIND11_BRANCH}" INSTALL_PREFIX="${TEMP_DIR}/install" BUILD_ROOT="${TEMP_DIR}/build" EXTERNAL_DIR="${TEMP_DIR}/external" - STUBS_DIR=$(readlink -m "${TESTS_ROOT}/${STUBS_SUB_DIR}") } @@ -89,33 +85,6 @@ install_pydemo() { ) } -remove_stubs() { - rm -rf "${STUBS_DIR}/*" ; -} - -run_stubgen() { - pybind11-stubgen \ - demo \ - --output-dir=${STUBS_DIR} \ - --numpy-array-wrap-with-annotated-fixed-size \ - --ignore-invalid-expressions="\(anonymous namespace\)::(Enum|Unbound)" \ - --ignore-unresolved-names="typing\.Annotated" \ - --exit-code -} - -format_stubs() { - ( - cd "${STUBS_DIR}" ; - black . ; - isort --profile=black . ; - ) -} - -check_stubs() { - git add --all "${STUBS_DIR}" ; - git diff --exit-code HEAD -- "${STUBS_DIR}" -} - main () { parse_args "$@" clone_eigen @@ -124,10 +93,6 @@ main () { install_eigen install_demo install_pydemo - remove_stubs - run_stubgen - format_stubs - check_stubs } main "$@"