Blame macros.pyproject

95ba837
# This is a directory where wheels are stored and installed from, relative to PWD
29157c1
%_pyproject_wheeldir %{_builddir}%{?buildsubdir:/%{buildsubdir}}/pyproject-wheeldir
95ba837
95ba837
# This is a directory used as TMPDIR, where pip copies sources to and builds from, relative to PWD
95ba837
# For proper debugsource packages, we create TMPDIR within PWD
95ba837
# See https://github.com/pypa/pip/issues/7555#issuecomment-595180864
95ba837
#
95ba837
# This will be used in debugsource package paths (applies to extension modules only)
95ba837
# NB: pytest collects tests from here if not hidden
95ba837
#     https://docs.pytest.org/en/latest/reference.html#confval-norecursedirs
29157c1
%_pyproject_builddir %{_builddir}%{?buildsubdir:/%{buildsubdir}}/.pyproject-builddir
49a323e
2800b49
%pyproject_files %{_builddir}/pyproject-files
cb4e43c
%pyproject_ghost_distinfo %{_builddir}/pyproject-ghost-distinfo
894e212
%pyproject_record %{_builddir}/pyproject-record
2800b49
5470f56
# Avoid leaking %%{_pyproject_builddir} to pytest collection
5470f56
# https://bugzilla.redhat.com/show_bug.cgi?id=1935212
5470f56
# The value is read and used by the %%pytest and %%tox macros:
5470f56
%_set_pytest_addopts %global __pytest_addopts --ignore=%{_pyproject_builddir}
5470f56
162b0ca
%pyproject_wheel() %{expand:\\\
5470f56
%_set_pytest_addopts
29157c1
mkdir -p "%{_pyproject_builddir}"
29157c1
CFLAGS="${CFLAGS:-${RPM_OPT_FLAGS}}" LDFLAGS="${LDFLAGS:-${RPM_LD_FLAGS}}" TMPDIR="%{_pyproject_builddir}" \\\
95ba837
%{__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 .
162b0ca
}
162b0ca
162b0ca
162b0ca
%pyproject_install() %{expand:\\\
19f84b1
specifier=$(ls %{_pyproject_wheeldir}/*.whl | xargs basename --multiple | sed -E 's/([^-]+)-([^-]+)-.+\\\.whl/\\\1==\\\2/')
29157c1
TMPDIR="%{_pyproject_builddir}" %{__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
fdf5116
if [ -d %{buildroot}%{_bindir} ]; then
a506123
  %py3_shebang_fix %{buildroot}%{_bindir}/*
8cce1fa
  rm -rfv %{buildroot}%{_bindir}/__pycache__
162b0ca
fi
cb4e43c
rm -f %{pyproject_ghost_distinfo}
8d5b3ac
site_dirs=()
8d5b3ac
# Process %%{python3_sitelib} if exists
fdf5116
if [ -d %{buildroot}%{python3_sitelib} ]; then
8d5b3ac
  site_dirs+=( "%{python3_sitelib}" )
253976c
fi
8d5b3ac
# Process %%{python3_sitearch} if exists and does not equal to %%{python3_sitelib}
cb4e43c
if [ %{buildroot}%{python3_sitearch} != %{buildroot}%{python3_sitelib} ] && [ -d %{buildroot}%{python3_sitearch} ]; then
8d5b3ac
  site_dirs+=( "%{python3_sitearch}" )
8d5b3ac
fi
8d5b3ac
# Process all *.dist-info dirs in sitelib/sitearch
8d5b3ac
for site_dir in ${site_dirs[@]}; do
8d5b3ac
  for distinfo in %{buildroot}$site_dir/*.dist-info; do
cb4e43c
    echo "%ghost ${distinfo#%{buildroot}}" >> %{pyproject_ghost_distinfo}
cb4e43c
    sed -i 's/pip/rpm/' ${distinfo}/INSTALLER
8d5b3ac
    PYTHONPATH=%{_rpmconfigdir}/redhat \\
8d5b3ac
      %{__python3} -B %{_rpmconfigdir}/redhat/pyproject_preprocess_record.py \\
8d5b3ac
      --buildroot %{buildroot} --record ${distinfo}/RECORD --output %{pyproject_record}
c5d2f62
    rm -fv ${distinfo}/RECORD
c5d2f62
    rm -fv ${distinfo}/REQUESTED
cb4e43c
  done
8d5b3ac
done
cb4e43c
lines=$(wc -l %{pyproject_ghost_distinfo} | cut -f1 -d" ")
cb4e43c
if [ $lines -ne 1 ]; then
3309d2d
  echo -e "\\n\\nWARNING: %%%%pyproject_extras_subpkg won't work without explicit -i or -F, found $lines dist-info directories.\\n\\n" >&2
cb4e43c
  rm %{pyproject_ghost_distinfo}  # any attempt to use this will fail
fdf5116
fi
fdf5116
}
fdf5116
2800b49
7e5adc9
# 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
7e5adc9
%pyproject_extras_subpkg(n:i:f:F) %{expand:%{?python_extras_subpkg:%{python_extras_subpkg%{?!-i:%{?!-f:%{?!-F: -f %{pyproject_ghost_distinfo}}}} %**}}}
cb4e43c
cb4e43c
2800b49
%pyproject_save_files() %{expand:\\\
2800b49
%{__python3} %{_rpmconfigdir}/redhat/pyproject_save_files.py \\
2800b49
  --output "%{pyproject_files}" \\
2800b49
  --buildroot "%{buildroot}" \\
2800b49
  --sitelib "%{python3_sitelib}" \\
2800b49
  --sitearch "%{python3_sitearch}" \\
2800b49
  --python-version "%{python3_version}" \\
894e212
  --pyproject-record "%{pyproject_record}" \\
2800b49
  %{*}
2800b49
}
2800b49
2800b49
ec07317
%default_toxenv py%{python3_version_nodots}
ec07317
%toxenv %{default_toxenv}
0124d2a
2800b49
d6ad9a7
%pyproject_buildrequires(rxtNe:) %{expand:\\\
d6ad9a7
%{-N:
d6ad9a7
%{-r:%{error:The -N and -r options are mutually exclusive}}
d6ad9a7
%{-x:%{error:The -N and -x options are mutually exclusive}}
d6ad9a7
%{-e:%{error:The -N and -e options are mutually exclusive}}
d6ad9a7
%{-t:%{error:The -N and -t options are mutually exclusive}}
d6ad9a7
}
38ef5fb
%{-e:%{expand:%global toxenv %(%{__python3} -s %{_rpmconfigdir}/redhat/pyproject_construct_toxenv.py %{?**})}}
5561755
echo 'python%{python3_pkgversion}-devel'
5561755
echo 'python%{python3_pkgversion}dist(pip) >= 19'
5561755
echo 'python%{python3_pkgversion}dist(packaging)'
d6ad9a7
%{!-N:if [ -f pyproject.toml ]; then
06b21e1
  echo 'python%{python3_pkgversion}dist(toml)'
5b1caad
elif [ -f setup.py ]; then
ff39661
  # Note: If the default requirements change, also change them in the script!
ff39661
  echo 'python%{python3_pkgversion}dist(setuptools) >= 40.8'
ff39661
  echo 'python%{python3_pkgversion}dist(wheel)'
5b1caad
else
5b1caad
  echo 'ERROR: Neither pyproject.toml nor setup.py found, consider using %%%%pyproject_buildrequires -N <requirements-file> if this is not a Python package.' >&2
5b1caad
  exit 1
d6ad9a7
fi}
bc156c4
# setuptools assumes no pre-existing dist-info
1026263
rm -rfv *.dist-info/ >&2
fdf5116
if [ -f %{__python3} ]; then
196bc90
  RPM_TOXENV="%{toxenv}" HOSTNAME="rpmbuild" %{__python3} -s %{_rpmconfigdir}/redhat/pyproject_buildrequires.py %{?!_python_no_extras_requires:--generate-extras} --python3_pkgversion %{python3_pkgversion} %{?**}
162b0ca
fi
162b0ca
}
ec07317
2800b49
ec07317
%tox(e:) %{expand:\\\
ec07317
TOX_TESTENV_PASSENV="${TOX_TESTENV_PASSENV:-*}" \\
32790ff
PYTHONDONTWRITEBYTECODE=1 \\
ec07317
PATH="%{buildroot}%{_bindir}:$PATH" \\
ec07317
PYTHONPATH="${PYTHONPATH:-%{buildroot}%{python3_sitearch}:%{buildroot}%{python3_sitelib}}" \\
5470f56
%{?__pytest_addopts:PYTEST_ADDOPTS="${PYTEST_ADDOPTS:-} %{__pytest_addopts}"} \\
37216e7
HOSTNAME="rpmbuild" \\
cb8e334
%{__python3} -m tox --current-env -q --recreate -e "%{-e:%{-e*}}%{!-e:%{toxenv}}" %{?*}
ec07317
}