Debian Codegraph @

python/generate_stubs.sh

raw
1 #!/bin/bash
2
3 set -e
4 PYTHON_EXEC=$1
5 OUTPUT=$2
6 PACKAGE_NAME="_core"
7 echo "Building stubs with $PYTHON_EXEC to $OUTPUT"
8 $PYTHON_EXEC -m pybind11_stubgen $PACKAGE_NAME -o $OUTPUT \
9 --numpy-array-use-type-var \
10 --enum-class-locations=.+:$PACKAGE_NAME \
11 --ignore-invalid-expressions "ceres::*" \
12 --print-invalid-expressions-as-is \
13 --print-safe-value-reprs "[a-zA-Z]+Options\(\)"
14 FILES=$(find $OUTPUT/$PACKAGE_NAME/ -name '*.pyi' -type f)
15
16 perl -i -pe's/\b_core\b/pycolmap/g' $FILES
17 perl -i -pe's/: ceres::([a-zA-Z]|::)+//g' $FILES
18 perl -i -pe's/ -> ceres::([a-zA-Z]|::)+:$/:/g' $FILES
19
20 # pybind issue, will not be fixed: https://github.com/pybind/pybind11/pull/2277
21 perl -i -pe's/(?<=\b__(eq|ne)__\(self, )arg0: [a-zA-Z0-9_]+\)/other: object)/g' $FILES
22
23 # mypy bug: https://github.com/python/mypy/issues/4266
24 perl -i -pe's/(__hash__:? .*= None)$/\1 # type: ignore/g' $FILES
25
26 # pybind issue: dictionary keys should not be cast to the more generic types.
27 perl -i -pe's/Mapping\[typing.Supports(Int|Float)/Mapping\[\L\1/g' $FILES
28
29 COLMAP_DIR=$(dirname $( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ))
30 ruff format --config ${COLMAP_DIR}/ruff.toml ${FILES}