fa5500228e
1. Relying on `python3 -m pytest --help` to test for pytest can fail because the pytest packages's __main__ is still invoked; this can trigger import problems and falsely indicate that pytest is missing. A simpler test is to just confirm that pytest is importable. If so, the interpreter returns 0. Otherwise, an ImportError is thrown and the interpreter will return 1. 2. Many templates require a custom do_check just to set PYTHONPATH to either a build directory (especially for compiled extensions) or some subdirectory of the source tree. Setting PYTHONPATH automatically to the build directory should drastically reduce the need for custom do_check in py3 templates. (This only applies to python3-module.sh because pep517 builders will have unpredictable build directories.) Closes: #31354.
65 lines
2.1 KiB
Bash
65 lines
2.1 KiB
Bash
#
|
|
# This helper is for templates installing python3-only modules.
|
|
#
|
|
|
|
do_build() {
|
|
if [ -n "$CROSS_BUILD" ]; then
|
|
PYPREFIX="$XBPS_CROSS_BASE"
|
|
CFLAGS+=" -I${XBPS_CROSS_BASE}/${py3_inc} -I${XBPS_CROSS_BASE}/usr/include"
|
|
LDFLAGS+=" -L${XBPS_CROSS_BASE}/${py3_lib} -L${XBPS_CROSS_BASE}/usr/lib"
|
|
CC="${XBPS_CROSS_TRIPLET}-gcc -pthread $CFLAGS $LDFLAGS"
|
|
LDSHARED="${CC} -shared $LDFLAGS"
|
|
for f in ${XBPS_CROSS_BASE}/${py3_lib}/_sysconfigdata_*; do
|
|
f=${f##*/}
|
|
_PYTHON_SYSCONFIGDATA_NAME=${f%.py}
|
|
done
|
|
env CC="$CC" LDSHARED="$LDSHARED" \
|
|
PYPREFIX="$PYPREFIX" CFLAGS="$CFLAGS" \
|
|
PYTHONPATH=${XBPS_CROSS_BASE}/${py3_lib} \
|
|
_PYTHON_SYSCONFIGDATA_NAME="$_PYTHON_SYSCONFIGDATA_NAME" \
|
|
LDFLAGS="$LDFLAGS" python3 setup.py build ${make_build_args}
|
|
else
|
|
python3 setup.py build ${make_build_args}
|
|
fi
|
|
}
|
|
|
|
do_check() {
|
|
if python3 -c 'import pytest' >/dev/null 2>&1; then
|
|
PYTHONPATH="$(cd build/lib* && pwd)" \
|
|
python3 -m pytest ${make_check_args} ${make_check_target}
|
|
else
|
|
# Fall back to deprecated setup.py test orchestration without pytest
|
|
if [ -z "$make_check_target" ]; then
|
|
if ! python3 setup.py --help test >/dev/null 2>&1; then
|
|
msg_warn "No command 'test' defined by setup.py.\n"
|
|
return 0
|
|
fi
|
|
fi
|
|
|
|
: ${make_check_target:=test}
|
|
python3 setup.py ${make_check_target} ${make_check_args}
|
|
fi
|
|
}
|
|
|
|
do_install() {
|
|
if [ -n "$CROSS_BUILD" ]; then
|
|
PYPREFIX="$XBPS_CROSS_BASE"
|
|
CFLAGS+=" -I${XBPS_CROSS_BASE}/${py3_inc} -I${XBPS_CROSS_BASE}/usr/include"
|
|
LDFLAGS+=" -L${XBPS_CROSS_BASE}/${py3_lib} -L${XBPS_CROSS_BASE}/usr/lib"
|
|
CC="${XBPS_CROSS_TRIPLET}-gcc -pthread $CFLAGS $LDFLAGS"
|
|
LDSHARED="${CC} -shared $LDFLAGS"
|
|
for f in ${XBPS_CROSS_BASE}/${py3_lib}/_sysconfigdata_*; do
|
|
f=${f##*/}
|
|
_PYTHON_SYSCONFIGDATA_NAME=${f%.py}
|
|
done
|
|
env CC="$CC" LDSHARED="$LDSHARED" \
|
|
PYPREFIX="$PYPREFIX" CFLAGS="$CFLAGS" \
|
|
PYTHONPATH=${XBPS_CROSS_BASE}/${py3_lib} \
|
|
_PYTHON_SYSCONFIGDATA_NAME="$_PYTHON_SYSCONFIGDATA_NAME" \
|
|
LDFLAGS="$LDFLAGS" python3 setup.py \
|
|
install --prefix=/usr --root=${DESTDIR} ${make_install_args}
|
|
else
|
|
python3 setup.py install --prefix=/usr --root=${DESTDIR} ${make_install_args}
|
|
fi
|
|
}
|