void-packages/common/build-style/python3-pep517.sh
Andrew J. Hesford fa5500228e build-style/python3-{module,pep517}.sh: improve pytest usage
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.
2021-06-08 13:53:15 -04:00

33 lines
1,023 B
Bash

#
# This style is for templates installing python3 modules adhering to PEP517
#
do_build() {
# No PEP517 build tool currently supports compiled extensions
# Thus, there is no need to accommodate cross compilation here
: ${make_build_target:=.}
mkdir -p build
TMPDIR=build python3 -m pip wheel --no-deps --use-pep517 --no-clean \
--no-build-isolation ${make_build_args} ${make_build_target}
}
do_check() {
if python3 -c 'import pytest' >/dev/null 2>&1; then
python3 -m pytest ${make_check_args} ${make_check_target}
else
msg_warn "Unable to determine tests for PEP517 Python templates"
return 0
fi
}
do_install() {
# As with do_build, no need to accommodate cross compilation here
: ${make_install_target:=${pkgname#python3-}-${version}-*-*-*.whl}
# If do_build was overridden, make sure the TMPDIR exists
mkdir -p build
TMPDIR=build python3 -m pip install --use-pep517 --prefix /usr \
--root ${DESTDIR} --no-deps --no-build-isolation \
--no-clean ${make_install_args} ${make_install_target}
}