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

chore: Imporve CI #125

Merged
merged 1 commit into from
Aug 31, 2023
Merged
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
20 changes: 15 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,4 @@ cython_debug/


tmp
*.patch
70 changes: 70 additions & 0 deletions tests/check-demo-stubs-generation.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"
39 changes: 2 additions & 37 deletions tests/run-tests.sh → tests/install-demo-module.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
}


Expand Down Expand Up @@ -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
Expand All @@ -124,10 +93,6 @@ main () {
install_eigen
install_demo
install_pydemo
remove_stubs
run_stubgen
format_stubs
check_stubs
}

main "$@"