test_python_install.sh 2.93 KB
Newer Older
1
2
3
4
5
6
7
8
9
# Some debug echoes
echo "Python on path: `which python`"
echo "Python cmd: $PYTHON_EXE"
echo "pip on path: $(which pip)"
echo "pip cmd: $PIP_CMD"
echo "virtualenv on path: $(which virtualenv)"
echo "virtualenv cmd: $VIRTUALENV_CMD"

# Check that a pip install puts scripts on path
10
11
# (Need setuptools >= 25.0.1 for delocate install).
pip install "setuptools>=25"
12
install_delocate
13
14
15
delocate-listdeps --version || ingest "Delocate not installed right"

# Python version from Python to compare against required
Kyle Stewart's avatar
Kyle Stewart committed
16
17
18
19
20
21
22
23
24
if [[ $($PYTHON_EXE --version 2>&1 | awk '{print $2}') =~ ([0-9.]*).?([0-9.]*) ]]
then
    # CPython version, 2.7.x on both CPython 2.7 and PyPy 5.4
    cpython_version=${BASH_REMATCH[1]}
    # CPython/PyPy version
    implementer_version=${BASH_REMATCH[2]:-$cpython_version}
fi
python_mm="${cpython_version:0:1}.${cpython_version:2:1}"

25
# extract implementation prefix and version
26
if [[ "$PYTHON_VERSION" =~ (pypy-)?([0-9\.]+) ]]; then
27
28
    _impl=${BASH_REMATCH[1]:-"cp"}
    requested_impl=${_impl:0:2}
29
30
    requested_version=${BASH_REMATCH[2]}
else
31
    ingest "Error parsing PYTHON_VERSION=$PYTHON_VERSION"
Kyle Stewart's avatar
Kyle Stewart committed
32
fi
33

Kyle Stewart's avatar
Kyle Stewart committed
34
35
# simple regex match, a 2.7 pattern will match 2.7.11, but not 2
if ! [[ "$implementer_version" =~ $requested_version ]]; then
36
    ingest "Wrong python version: ${implementer_version}!=${requested_version}"
37
38
39
40
fi

if [ -n "$VENV" ]; then  # in virtualenv
    # Correct pip and Python versions should be on PATH
Kyle Stewart's avatar
Kyle Stewart committed
41
    if [ "$($PYTHON_EXE --version 2>&1)" != "$(python --version 2>&1)" ]; then
42
43
44
45
46
47
48
49
50
        ingest "Python versions do not match"
    fi
    if [ "$($PIP_CMD --version)" != "$(pip --version)" ]; then
        ingest "Pip versions do not match"
    fi
    # Versions in environment variables have full path
    if [ "$PYTHON_EXE" != "$PWD/venv/bin/python" ]; then
        ingest "Wrong virtualenv python '$PYTHON_EXE'"
    fi
51
    if [ "$PIP_CMD" != "${PWD}/venv/bin/pip${expected_pip_args}" ]; then
52
53
54
55
56
57
58
        ingest "Wrong virtualenv pip '$PIP_CMD'"
    fi
else # not virtualenv
    macpie_bin="$MACPYTHON_PY_PREFIX/$python_mm/bin"
    if [ "$PYTHON_EXE" != "$macpie_bin/python$python_mm" ]; then
        ingest "Wrong macpython python cmd '$PYTHON_EXE'"
    fi
59
    if [ "$PIP_CMD" != "sudo $macpie_bin/pip${python_mm}${expected_pip_args}" ]; then
60
61
62
        ingest "Wrong macpython pip '$PIP_CMD'"
    fi
fi
63

64
# for CPython, check macOS version and arch are as expected
65
66
67
68
69
70
71
72
73
74
75
76
77
distutils_plat=$($PYTHON_EXE -c "import distutils.util; print(distutils.util.get_platform())")
echo "Python cmd archs: $(lipo -info $(which $PYTHON_EXE))"
if [[ $requested_impl = 'cp' ]]; then
    echo "Cpython, checking platform..."
    expected_tag="macosx-${MB_PYTHON_OSX_VER}-$(mac_cpython_arch_for_osx_ver)"
    if ! [[ $distutils_plat == $expected_tag ]]; then
        ingest "Wrong Python platform tag: ${distutils_plat}!=${expected_tag}"
    fi
elif [[ $requested_impl = 'py' ]]; then
    echo "Pypy, skipping platform check..."
else
    ingest "Invalid impl: '${requested_impl}', expecting 'cp' or 'py'"
fi