contrib/setup-pytype.sh
author Arseniy Alekseyev <aalekseyev@janestreet.com>
Thu, 04 Apr 2024 14:15:32 +0100
branchstable
changeset 51572 13c004b54cbe
parent 49652 03792c1ed341
permissions -rwxr-xr-x
wireprotoserver: ensure that output stream gets flushed on exception Previously flush was happening due to Python finalizer being run on `BufferedWriter`. With upgrade to Python 3.11 this started randomly failing. My guess is that the finalizer on the raw `FileIO` object may be running before the finalizer of `BufferedWriter` has a chance to run. At any rate, since we're not relying on finalizers in the happy case we should also not rely on them in case of exception.

#!/bin/bash

set -e
set -u

# Find the python3 setup that would run pytype
PYTYPE=`which pytype`
PYTHON3=`head -n1 ${PYTYPE} | sed -s 's/#!//'`

# Existing stubs that pytype processes live here
TYPESHED=$(${PYTHON3} -c "import pytype; print(pytype.__path__[0])")/typeshed/stubs
HG_STUBS=${TYPESHED}/mercurial

echo "Patching typeshed at $HG_STUBS"

rm -rf ${HG_STUBS}
mkdir -p ${HG_STUBS}

cat > ${HG_STUBS}/METADATA.toml <<EOF
version = "0.1"
EOF


mkdir -p ${HG_STUBS}/mercurial/cext ${HG_STUBS}/mercurial/thirdparty/attr

touch ${HG_STUBS}/mercurial/__init__.pyi
touch ${HG_STUBS}/mercurial/cext/__init__.pyi
touch ${HG_STUBS}/mercurial/thirdparty/__init__.pyi

ln -sf $(hg root)/mercurial/cext/*.{pyi,typed} \
       ${HG_STUBS}/mercurial/cext
ln -sf $(hg root)/mercurial/thirdparty/attr/*.{pyi,typed} \
       ${HG_STUBS}/mercurial/thirdparty/attr