#!/bin/sh
PYTHONS="python2.7 python3.3 python3.4 python3.5"

tempfoo=`basename $0`
TMP_DIR=`mktemp -d -t ${tempfoo}` || exit 2

cat >${TMP_DIR}/sitecustomize.py <<EOF
import sys, os
# remove our copy of sitecustomize from import path

print("sitecustomize imported")

if "${TMP_DIR}" in sys.path:
    print("removing from sys.path")
    sys.path.remove("${TMP_DIR}")

# now attempt to import any actual sitecustomize
# (which should fail with ImportError)
try:
    print("importing")
    import sitecustomize
    if sys.version_info[0] >= 3:
        from imp import reload
    print('reloading')
    reload(sitecustomize)
except ImportError:
    print('ImportError raised -> passed')

print("continuing on")
EOF

for PYTHON in ${PYTHONS}; do
    echo "---- testing ${PYTHON}"
    echo " "
    if ${PYTHON} -c 'import sitecustomize' 2>/dev/null ; then
        echo "ERROR - sitecustomize already exists for ${PYTHON}"
        exit 1
    fi
    PYTHONPATH=${TMP_DIR} ${PYTHON} -c 'pass'
    echo " "
done

rm -r ${TMP_DIR}
