Don't generate runtime dependency on setuptools for console_scripts entrypoints
- recent setuptools don't need it, they use importlib.metadata - for this to work, we need to detect setuptools version - the detection is not bulletproof, but it fallbacks to the old behavior
This commit is contained in:
parent
a295a58559
commit
8485b55bea
7 changed files with 225 additions and 35 deletions
71
tests/console_script.sh
Executable file
71
tests/console_script.sh
Executable file
|
|
@ -0,0 +1,71 @@
|
|||
#!/usr/bin/bash -eux
|
||||
RPMDIR=$(rpm --eval '%_topdir')/RPMS/noarch
|
||||
RPMPKG="${RPMDIR}/isort-5.7.0-0.noarch.rpm"
|
||||
|
||||
mkdir -p $(rpm --eval '%_topdir')/SOURCES/
|
||||
|
||||
spectool -g -R isort.spec
|
||||
|
||||
for py_version in 3.6 3.7 3.8 3.9 3.10; do
|
||||
rpmbuild -ba --define "python3_test_version ${py_version}" isort.spec
|
||||
|
||||
# sanity check for provides; if this is broken, so is the test
|
||||
rpm -qp --provides ${RPMPKG} | grep "python${py_version}dist(isort)"
|
||||
|
||||
# only the "main" Python version has setuptools installed,
|
||||
# everything else does not
|
||||
if [ "$py_version" = "$(rpm --eval '%python3_version')" ]; then
|
||||
# all main Python/setuptools versions in Fedora 33+ are recent enough
|
||||
# not to justify a generated dependency wrt the console_script
|
||||
rpm -qp --requires ${RPMPKG} | grep "python${py_version}dist(setuptools)" && exit 1 || true
|
||||
rpm -qp --requires ${RPMPKG} | grep "python${py_version}dist(importlib-metadata)" && exit 1 || true
|
||||
else
|
||||
# no setuptools installed, we assume an old version of setuptools was used to prepare the data
|
||||
# hence the package always requires setuptools
|
||||
rpm -qp --requires ${RPMPKG} | grep "python${py_version}dist(setuptools)"
|
||||
rpm -qp --requires ${RPMPKG} | grep "python${py_version}dist(importlib-metadata)" && exit 1 || true
|
||||
fi
|
||||
|
||||
# the rest is only possible on the CI or in mock/container, where we are root
|
||||
# never run this script as root on your host OS, it is destructive
|
||||
# also, it only works once (improvements welcome)
|
||||
test $EUID -ne 0 && continue
|
||||
export RPM_BUILD_ROOT=/
|
||||
|
||||
# install setuptools and build again
|
||||
python${py_version} -m ensurepip
|
||||
rpmbuild -ba --define "python3_test_version ${py_version}" isort.spec
|
||||
|
||||
# the ensurepip version of setuptools is recent enough on Fedora 33+
|
||||
# WARNING: Once we flip the rpmwheels bcond in python3.6, this assumption will break
|
||||
rpm -qp --requires ${RPMPKG} | grep "python${py_version}dist(setuptools)" && exit 1 || true
|
||||
# but older Pythons still need importlib_metadata
|
||||
if [[ "$py_version" = "3.6" || "$py_version" = "3.7" ]]; then
|
||||
rpm -qp --requires ${RPMPKG} | grep "python${py_version}dist(importlib-metadata)"
|
||||
else
|
||||
rpm -qp --requires ${RPMPKG} | grep "python${py_version}dist(importlib-metadata)" && exit 1 || true
|
||||
fi
|
||||
|
||||
# install setuptools 47.2 and build again
|
||||
python${py_version} -m pip uninstall --yes setuptools
|
||||
python${py_version} -m pip install 'setuptools>=47.2.0,<47.3.0'
|
||||
rpmbuild -ba --define "python3_test_version ${py_version}" isort.spec
|
||||
|
||||
# this version of setuptools never uses importlib_metadata
|
||||
rpm -qp --requires ${RPMPKG} | grep "python${py_version}dist(importlib-metadata)" && exit 1 || true
|
||||
# older Pythons use setuptools, newer Pythons use importlib.metadata
|
||||
if [[ "$py_version" = "3.6" || "$py_version" = "3.7" ]]; then
|
||||
rpm -qp --requires ${RPMPKG} | grep "python${py_version}dist(setuptools)"
|
||||
else
|
||||
rpm -qp --requires ${RPMPKG} | grep "python${py_version}dist(setuptools)" && exit 1 || true
|
||||
fi
|
||||
|
||||
# install an even older setuptools version and build again
|
||||
python${py_version} -m pip uninstall --yes setuptools
|
||||
python${py_version} -m pip install 'setuptools<47.2.0'
|
||||
rpmbuild -ba --define "python3_test_version ${py_version}" isort.spec
|
||||
|
||||
# old console_scripts entyrpoint used pkg_resources only
|
||||
rpm -qp --requires ${RPMPKG} | grep "python${py_version}dist(setuptools)"
|
||||
rpm -qp --requires ${RPMPKG} | grep "python${py_version}dist(importlib-metadata)" && exit 1 || true
|
||||
done
|
||||
Loading…
Add table
Add a link
Reference in a new issue