|
 |
42e0692 |
#!/bin/sh -eux
|
|
 |
42e0692 |
|
|
 |
6a9ffe6 |
# set default version to %{python3_version} if available
|
|
 |
6a9ffe6 |
VERSION=${VERSION:-$(rpm --eval '%{?python3_version}')} || true
|
|
 |
6a9ffe6 |
# ...or 3.8 if that macro is not available or rpm fails for any reason
|
|
 |
6a9ffe6 |
VERSION=${VERSION:-3.8}
|
|
 |
6a9ffe6 |
|
|
 |
b3d405a |
PYTHON=${PYTHON:-python$VERSION}
|
|
 |
aa5f2fe |
METHOD=${METHOD:-venv}
|
|
 |
413ee19 |
TOX=${TOX:-true}
|
|
 |
c26b648 |
INSTALL_OR_SKIP=${INSTALL_OR_SKIP:-false}
|
|
 |
42e0692 |
|
|
 |
42e0692 |
# clean from possible older runs
|
|
 |
4503646 |
rm -rf venv .tox __pycache__ .pytest* test_*.py *.pyx *.c *.so ensurepiptestroot || :
|
|
 |
42e0692 |
|
|
 |
c26b648 |
if [ "$INSTALL_OR_SKIP" == "true" ] && [ ! -f "/usr/bin/$PYTHON" ]; then
|
|
 |
c26b648 |
dnf -y install "/usr/bin/$PYTHON" || :
|
|
 |
c26b648 |
if [ ! -f "/usr/bin/$PYTHON" ]; then
|
|
 |
c26b648 |
echo "/usr/bin/$PYTHON not installable, skipping this test"
|
|
 |
c26b648 |
exit 0
|
|
 |
c26b648 |
fi
|
|
 |
c26b648 |
fi
|
|
 |
c26b648 |
|
|
 |
42e0692 |
# check the we can create the venv
|
|
 |
aa5f2fe |
if [ "$METHOD" == "venv" ]; then
|
|
 |
aa5f2fe |
$PYTHON -m venv venv
|
|
 |
aa5f2fe |
elif [ "$METHOD" == "virtualenv" ]; then
|
|
 |
aa5f2fe |
virtualenv --python=$PYTHON venv
|
|
 |
d37bcbf |
elif [ "$METHOD" == "virtualenv-no-download" ]; then
|
|
 |
d37bcbf |
virtualenv --no-download --python=$PYTHON venv
|
|
 |
261dfe6 |
elif [ "$METHOD" == "virtualenv-seeder-pip" ]; then
|
|
 |
261dfe6 |
virtualenv --seeder pip --python=$PYTHON venv
|
|
 |
aa5f2fe |
else
|
|
 |
aa5f2fe |
echo 'Unsupported $METHOD' $METHOD >&2
|
|
 |
aa5f2fe |
exit 1
|
|
 |
aa5f2fe |
fi
|
|
 |
aa5f2fe |
|
|
 |
42e0692 |
|
|
 |
42e0692 |
# and activate it
|
|
 |
a6067a8 |
# unset variables on 3.5, it's known
|
|
 |
a6067a8 |
set +u
|
|
 |
42e0692 |
source venv/bin/activate
|
|
 |
a6067a8 |
set -u
|
|
 |
42e0692 |
|
|
 |
42e0692 |
# run python in it
|
|
 |
42e0692 |
python -c 'import sys; print(sys.version)' | head -n1 | grep $VERSION
|
|
 |
42e0692 |
|
|
 |
42e0692 |
# install packages with pip
|
|
 |
d7cf02c |
if [ "$VERSION" == "2.6" ]; then
|
|
 |
2540126 |
pip install pytest
|
|
 |
2540126 |
pip install Cython --install-option="--no-cython-compile"
|
|
 |
d7cf02c |
else
|
|
 |
c56363e |
python -m pip install pytest
|
|
 |
6cc91d5 |
if [ "$PYTHON" != "jython" ]; then
|
|
 |
ca464dc |
# We try to fetch a wheel only and if that fails, we disable compilation
|
|
 |
ca464dc |
# Useful for fresh CPythons, where wheels are not yet ready, but Cython defaults to compiling
|
|
 |
ca464dc |
python -m pip install Cython --only-binary :all: || python -m pip install Cython --install-option="--no-cython-compile"
|
|
 |
c56363e |
fi
|
|
 |
d7cf02c |
fi
|
|
 |
42e0692 |
|
|
 |
42e0692 |
# run tests
|
|
 |
42e0692 |
cat > test_foo.py << EOF
|
|
 |
42e0692 |
def test_foo():
|
|
 |
42e0692 |
assert True
|
|
 |
42e0692 |
EOF
|
|
 |
42e0692 |
|
|
 |
42e0692 |
python -m pytest -v test_foo.py
|
|
 |
42e0692 |
|
|
 |
42e0692 |
# check that we can do extension modules
|
|
 |
c56363e |
if [ "$PYTHON" != "jython" ]; then
|
|
 |
42e0692 |
cat > module.pyx << EOF
|
|
 |
42e0692 |
cdef int add(int a, int b):
|
|
 |
42e0692 |
return a + b
|
|
 |
42e0692 |
|
|
 |
42e0692 |
def two():
|
|
 |
42e0692 |
cdef int a = 1
|
|
 |
42e0692 |
cdef int b = 1
|
|
 |
42e0692 |
return add(a, b)
|
|
 |
42e0692 |
EOF
|
|
 |
42e0692 |
|
|
 |
42e0692 |
cat > setup.py << EOF
|
|
 |
42e0692 |
from setuptools import setup
|
|
 |
42e0692 |
from Cython.Build import cythonize
|
|
 |
42e0692 |
|
|
 |
42e0692 |
setup(ext_modules = cythonize('module.pyx'))
|
|
 |
42e0692 |
EOF
|
|
 |
42e0692 |
|
|
 |
42e0692 |
python setup.py build_ext --inplace
|
|
 |
42e0692 |
|
|
 |
42e0692 |
python -c 'import module; print(module.two())' | grep '^2$'
|
|
 |
c56363e |
fi
|
|
 |
42e0692 |
|
|
 |
42e0692 |
# deactivate has unset variable, it's known
|
|
 |
42e0692 |
set +u
|
|
 |
42e0692 |
deactivate
|
|
 |
42e0692 |
set -u
|
|
 |
42e0692 |
|
|
 |
4503646 |
# ensurepip test (when testing virtualenv, this was not covered)
|
|
 |
4503646 |
# with the main Python, this will say "Requirement already satisfied", but that's OK
|
|
 |
4503646 |
$PYTHON -m ensurepip --root ensurepiptestroot
|
|
 |
4503646 |
|
|
 |
42e0692 |
# use it with tox
|
|
 |
413ee19 |
[[ "$TOX" != "true" ]] && exit 0
|
|
 |
74239ca |
if [[ $PYTHON == python* ]]; then
|
|
 |
74239ca |
export TOXENV=py${VERSION/./}
|
|
 |
74239ca |
else
|
|
 |
74239ca |
export TOXENV=$PYTHON
|
|
 |
74239ca |
fi
|
|
 |
74239ca |
|
|
 |
74239ca |
cat > tox.ini << EOF
|
|
 |
74239ca |
[tox]
|
|
 |
74239ca |
skipsdist = True
|
|
 |
74239ca |
[testenv]
|
|
 |
74239ca |
commands = python -c 'import sys; print(sys.version)'
|
|
 |
74239ca |
EOF
|
|
 |
74239ca |
|
|
 |
74239ca |
# Tests that the Python version used in tox is really the Python version we want
|
|
 |
74239ca |
tox | tee toxlog
|
|
 |
74239ca |
grep "^$VERSION\.[0-9]" toxlog
|
|
 |
74239ca |
|
|
 |
42e0692 |
cat > tox.ini << EOF
|
|
 |
42e0692 |
[tox]
|
|
 |
42e0692 |
skipsdist = True
|
|
 |
42e0692 |
[testenv]
|
|
 |
42e0692 |
deps = pytest
|
|
 |
42e0692 |
commands = python -m pytest -v test_foo.py
|
|
 |
42e0692 |
EOF
|
|
 |
42e0692 |
|
|
 |
74239ca |
# A more complex example with pytest
|
|
 |
74239ca |
tox
|