Blame marshalparser/test_marshalparser_compatibility.sh

86842ac
#!/bin/sh -eux
86842ac
86842ac
# Marshalparser helps us to uniform byte-compiled Python files
86842ac
# so it has to be able to also parse pyc files from
86842ac
# the main python packages.
86842ac
# Moreover, it has its own database of magic numbers so this test
86842ac
# checks that the parser is compatible with the latest python before
86842ac
# we ship it.
86842ac
86842ac
# Test the latest version by default because that's the place
86842ac
# where magic number incompatibility might happen with
86842ac
# the largest probability
86842ac
VERSION=${VERSION:-3.9}
86842ac
86842ac
# How many randomly-selected pyc files to check?
86842ac
SAMPLE=${SAMPLE:-50}
86842ac
59f2079
# This allows us to test marshalparser optionally: on Fedora 33+ only
59f2079
INSTALL_OR_SKIP=${INSTALL_OR_SKIP:-false}
59f2079
if [ "$INSTALL_OR_SKIP" == "true" ] && [ ! -f "/usr/bin/marshalparser" ]; then
59f2079
  dnf -y install marshalparser || :
59f2079
  if [ ! -f "/usr/bin/marshalparser" ]; then
59f2079
    echo "marshalparser not installable, skipping this test"
59f2079
    exit 0
59f2079
  fi
59f2079
fi
59f2079
86842ac
path="/usr/lib*/python$VERSION/"
86842ac
86842ac
for file in `find $path -name "*.pyc" | shuf | head -n $SAMPLE`; do
86842ac
  marshalparser $file || exit 1
86842ac
done