python/smoke/venv.sh
Miro Hrončok ca464dcb60 Fix Cython installation for fresh CPythons
We try to fetch a wheel only and if that fails, we disable compilation.
Useful for fresh CPythons such as 3.8 now, where wheels are not yet ready,
but Cython defaults to compiling (because it detects CPython).

Note that --install-option="--no-cython-compile" makes pip use source package,
hence we don't want to use it right away. We still prefer wheel over
sdist.
2019-02-07 08:36:39 +01:00

96 lines
2 KiB
Bash
Executable file

#!/bin/sh -eux
# set python version
VERSION=${VERSION:-3.7}
PYTHON=${PYTHON:-python$VERSION}
METHOD=${METHOD:-venv}
TOX=${TOX:-true}
# clean from possible older runs
rm -rf venv .tox __pycache__ .pytest* test_*.py *.pyx *.c *.so || :
# check the we can create the venv
if [ "$METHOD" == "venv" ]; then
$PYTHON -m venv venv
elif [ "$METHOD" == "virtualenv" ]; then
virtualenv --python=$PYTHON venv
else
echo 'Unsupported $METHOD' $METHOD >&2
exit 1
fi
# and activate it
# unset variables on 3.5, it's known
set +u
source venv/bin/activate
set -u
# run python in it
python -c 'import sys; print(sys.version)' | head -n1 | grep $VERSION
# install packages with pip
if [ "$VERSION" == "2.6" ]; then
pip install pytest
pip install Cython --install-option="--no-cython-compile"
else
python -m pip install pytest
if [ "$PYTHON" != "jython" ]; then
# We try to fetch a wheel only and if that fails, we disable compilation
# Useful for fresh CPythons, where wheels are not yet ready, but Cython defaults to compiling
python -m pip install Cython --only-binary :all: || python -m pip install Cython --install-option="--no-cython-compile"
fi
fi
# run tests
cat > test_foo.py << EOF
def test_foo():
assert True
EOF
python -m pytest -v test_foo.py
# check that we can do extension modules
if [ "$PYTHON" != "jython" ]; then
cat > module.pyx << EOF
cdef int add(int a, int b):
return a + b
def two():
cdef int a = 1
cdef int b = 1
return add(a, b)
EOF
cat > setup.py << EOF
from setuptools import setup
from Cython.Build import cythonize
setup(ext_modules = cythonize('module.pyx'))
EOF
python setup.py build_ext --inplace
python -c 'import module; print(module.two())' | grep '^2$'
fi
# deactivate has unset variable, it's known
set +u
deactivate
set -u
# use it with tox
[[ "$TOX" != "true" ]] && exit 0
cat > tox.ini << EOF
[tox]
skipsdist = True
[testenv]
deps = pytest
commands = python -m pytest -v test_foo.py
EOF
if [[ $PYTHON == python* ]]; then
tox -e py${VERSION/./}
else
tox -e $PYTHON
fi