|
| 1 | +# SPDX-License-Identifier: MIT |
| 2 | + |
| 3 | +# This is a directory where wheels are stored and installed from, relative to PWD |
| 4 | +%_pyproject_wheeldir pyproject-wheeldir |
| 5 | + |
| 6 | +# This is a directory used as TMPDIR, where pip copies sources to and builds from, relative to PWD |
| 7 | +# For proper debugsource packages, we create TMPDIR within PWD |
| 8 | +# See https://github.com/pypa/pip/issues/7555#issuecomment-595180864 |
| 9 | +# |
| 10 | +# This will be used in debugsource package paths (applies to extension modules only) |
| 11 | +# NB: pytest collects tests from here if not hidden |
| 12 | +# https://docs.pytest.org/en/latest/reference.html#confval-norecursedirs |
| 13 | +%_pyproject_builddir .pyproject-builddir |
| 14 | + |
| 15 | +%pyproject_files %{_builddir}/pyproject-files |
| 16 | +%pyproject_ghost_distinfo %{_builddir}/pyproject-ghost-distinfo |
| 17 | +%pyproject_record %{_builddir}/pyproject-record |
| 18 | + |
| 19 | +%pyproject_wheel() %{expand:\\\ |
| 20 | +export TMPDIR="${PWD}/%{_pyproject_builddir}" |
| 21 | +mkdir -p "${TMPDIR}" |
| 22 | +CFLAGS="${CFLAGS:-${RPM_OPT_FLAGS}}" LDFLAGS="${LDFLAGS:-${RPM_LD_FLAGS}}" \\\ |
| 23 | +%{__python3} -m pip wheel --wheel-dir %{_pyproject_wheeldir} --no-deps --use-pep517 --no-build-isolation --disable-pip-version-check --no-clean --progress-bar off --verbose . |
| 24 | +} |
| 25 | + |
| 26 | + |
| 27 | +%pyproject_install() %{expand:\\\ |
| 28 | +specifier=$(ls %{_pyproject_wheeldir}/*.whl | xargs basename --multiple | sed -E 's/([^-]+)-([^-]+)-.+\\\.whl/\\\1==\\\2/') |
| 29 | +export TMPDIR="${PWD}/%{_pyproject_builddir}" |
| 30 | +%{__python3} -m pip install --root %{buildroot} --no-deps --disable-pip-version-check --progress-bar off --verbose --ignore-installed --no-warn-script-location --no-index --no-cache-dir --find-links %{_pyproject_wheeldir} $specifier |
| 31 | +if [ -d %{buildroot}%{_bindir} ]; then |
| 32 | + %py3_shebang_fix %{buildroot}%{_bindir}/* |
| 33 | + rm -rfv %{buildroot}%{_bindir}/__pycache__ |
| 34 | +fi |
| 35 | +rm -f %{pyproject_ghost_distinfo} |
| 36 | +site_dirs=() |
| 37 | +# Process %%{python3_sitelib} if exists |
| 38 | +if [ -d %{buildroot}%{python3_sitelib} ]; then |
| 39 | + site_dirs+=( "%{python3_sitelib}" ) |
| 40 | +fi |
| 41 | +# Process %%{python3_sitearch} if exists and does not equal to %%{python3_sitelib} |
| 42 | +if [ %{buildroot}%{python3_sitearch} != %{buildroot}%{python3_sitelib} ] && [ -d %{buildroot}%{python3_sitearch} ]; then |
| 43 | + site_dirs+=( "%{python3_sitearch}" ) |
| 44 | +fi |
| 45 | +# Process all *.dist-info dirs in sitelib/sitearch |
| 46 | +for site_dir in ${site_dirs[@]}; do |
| 47 | + for distinfo in %{buildroot}$site_dir/*.dist-info; do |
| 48 | + echo "%ghost ${distinfo#%{buildroot}}" >> %{pyproject_ghost_distinfo} |
| 49 | + sed -i 's/pip/rpm/' ${distinfo}/INSTALLER |
| 50 | + PYTHONPATH=%{_rpmconfigdir}/redhat \\ |
| 51 | + %{__python3} -B %{_rpmconfigdir}/redhat/pyproject_preprocess_record.py \\ |
| 52 | + --buildroot %{buildroot} --record ${distinfo}/RECORD --output %{pyproject_record} |
| 53 | + rm -fv ${distinfo}/RECORD |
| 54 | + rm -fv ${distinfo}/REQUESTED |
| 55 | + done |
| 56 | +done |
| 57 | +lines=$(wc -l %{pyproject_ghost_distinfo} | cut -f1 -d" ") |
| 58 | +if [ $lines -ne 1 ]; then |
| 59 | + echo -e "\\n\\nWARNING: %%%%pyproject_extras_subpkg won't work without explicit -i or -F, found $lines dist-info directories.\\n\\n" >/dev/stderr |
| 60 | + rm %{pyproject_ghost_distinfo} # any attempt to use this will fail |
| 61 | +fi |
| 62 | +} |
| 63 | + |
| 64 | + |
| 65 | +# Note: the three times nested questionmarked -i -f -F pattern means: If none of those options was used -- in that case, we inject our own -f |
| 66 | +%pyproject_extras_subpkg(n:i:f:F) %{expand:%{?python_extras_subpkg:%{python_extras_subpkg%{?!-i:%{?!-f:%{?!-F: -f %{pyproject_ghost_distinfo}}}} %**}}} |
| 67 | + |
| 68 | + |
| 69 | +%pyproject_save_files() %{expand:\\\ |
| 70 | +%{__python3} %{_rpmconfigdir}/redhat/pyproject_save_files.py \\ |
| 71 | + --output "%{pyproject_files}" \\ |
| 72 | + --buildroot "%{buildroot}" \\ |
| 73 | + --sitelib "%{python3_sitelib}" \\ |
| 74 | + --sitearch "%{python3_sitearch}" \\ |
| 75 | + --python-version "%{python3_version}" \\ |
| 76 | + --pyproject-record "%{pyproject_record}" \\ |
| 77 | + %{*} |
| 78 | +} |
| 79 | + |
| 80 | + |
| 81 | +%default_toxenv py%{python3_version_nodots} |
| 82 | +%toxenv %{default_toxenv} |
| 83 | + |
| 84 | + |
| 85 | +%pyproject_buildrequires(rxte:) %{expand:\\\ |
| 86 | +%{-e:%{expand:%global toxenv %(%{__python3} -s %{_rpmconfigdir}/redhat/pyproject_construct_toxenv.py %{?**})}} |
| 87 | +echo 'python%{python3_pkgversion}-devel' |
| 88 | +echo 'python%{python3_pkgversion}dist(pip) >= 19' |
| 89 | +echo 'python%{python3_pkgversion}dist(packaging)' |
| 90 | +if [ -f pyproject.toml ]; then |
| 91 | + echo 'python%{python3_pkgversion}dist(toml)' |
| 92 | +else |
| 93 | + # Note: If the default requirements change, also change them in the script! |
| 94 | + echo 'python%{python3_pkgversion}dist(setuptools) >= 40.8' |
| 95 | + echo 'python%{python3_pkgversion}dist(wheel)' |
| 96 | +fi |
| 97 | +# Check if we can generate dependencies on Python extras |
| 98 | +if [ "%{py_dist_name []}" == "[]" ]; then |
| 99 | + extras_flag=%{?!_python_no_extras_requires:--generate-extras} |
| 100 | +else |
| 101 | + extras_flag= |
| 102 | +fi |
| 103 | +# setuptools assumes no pre-existing dist-info |
| 104 | +rm -rfv *.dist-info/ >&2 |
| 105 | +if [ -f %{__python3} ]; then |
| 106 | + RPM_TOXENV="%{toxenv}" HOSTNAME="rpmbuild" %{__python3} -s %{_rpmconfigdir}/redhat/pyproject_buildrequires.py $extras_flag --python3_pkgversion %{python3_pkgversion} %{?**} |
| 107 | +fi |
| 108 | +} |
| 109 | + |
| 110 | + |
| 111 | +%tox(e:) %{expand:\\\ |
| 112 | +TOX_TESTENV_PASSENV="${TOX_TESTENV_PASSENV:-*}" \\ |
| 113 | +PYTHONDONTWRITEBYTECODE=1 \\ |
| 114 | +PATH="%{buildroot}%{_bindir}:$PATH" \\ |
| 115 | +PYTHONPATH="${PYTHONPATH:-%{buildroot}%{python3_sitearch}:%{buildroot}%{python3_sitelib}}" \\ |
| 116 | +HOSTNAME="rpmbuild" \\ |
| 117 | +%{__python3} -m tox --current-env -q --recreate -e "%{-e:%{-e*}}%{!-e:%{toxenv}}" %{?*} |
| 118 | +} |
0 commit comments