From cb4e43c670b9e8c065375b985a0ac15b6bfa6e78 Mon Sep 17 00:00:00 2001 From: Miro Hrončok Date: Jul 29 2020 15:40:37 +0000 Subject: Implement %pyproject_extras_subpkg --- diff --git a/macros.pyproject b/macros.pyproject index bab2c4c..1b0aa02 100644 --- a/macros.pyproject +++ b/macros.pyproject @@ -11,6 +11,7 @@ %_pyproject_builddir .pyproject-builddir %pyproject_files %{_builddir}/pyproject-files +%pyproject_ghost_distinfo %{_builddir}/pyproject-ghost-distinfo %pyproject_wheel() %{expand:\\\ export TMPDIR="${PWD}/%{_pyproject_builddir}" @@ -28,15 +29,30 @@ if [ -d %{buildroot}%{_bindir} ]; then pathfix.py -pni "%{__python3}" -k%{?py3_shbang_opts: -a%{py3_shbang_opts_nodash}} %{buildroot}%{_bindir}/* rm -rfv %{buildroot}%{_bindir}/__pycache__ fi +rm -f %{pyproject_ghost_distinfo} if [ -d %{buildroot}%{python3_sitelib} ]; then - sed -i 's/pip/rpm/' %{buildroot}%{python3_sitelib}/*.dist-info/INSTALLER + for distinfo in %{buildroot}%{python3_sitelib}/*.dist-info; do + echo "%ghost ${distinfo#%{buildroot}}" >> %{pyproject_ghost_distinfo} + sed -i 's/pip/rpm/' ${distinfo}/INSTALLER + done fi -if [ -d %{buildroot}%{python3_sitearch} ]; then - sed -i 's/pip/rpm/' %{buildroot}%{python3_sitearch}/*.dist-info/INSTALLER +if [ %{buildroot}%{python3_sitearch} != %{buildroot}%{python3_sitelib} ] && [ -d %{buildroot}%{python3_sitearch} ]; then + for distinfo in %{buildroot}%{python3_sitearch}/*.dist-info; do + echo "%ghost ${distinfo#%{buildroot}}" >> %{pyproject_ghost_distinfo} + sed -i 's/pip/rpm/' ${distinfo}/INSTALLER + done +fi +lines=$(wc -l %{pyproject_ghost_distinfo} | cut -f1 -d" ") +if [ $lines -ne 1 ]; then + echo -e "\\n\\nWARNING: %%%%pyproject_extras_subpkg won't work without explicit -i or -F, found $lines dist-info directories.\\n\\n" >/dev/stderr + rm %{pyproject_ghost_distinfo} # any attempt to use this will fail fi } +%python_extras_subpkg(n:i:f:F) %{expand:%{?python_extras_subpkg:%{python_extras_subpkg%{?!-i:%{?!-f:%{?!-F: -f %{pyproject_ghost_distinfo}}}} %**}}} + + %pyproject_save_files() %{expand:\\\ %{__python3} %{_rpmconfigdir}/redhat/pyproject_save_files.py \\ --output "%{pyproject_files}" \\ diff --git a/pyproject-rpm-macros.spec b/pyproject-rpm-macros.spec index 26f9384..4dd03f1 100644 --- a/pyproject-rpm-macros.spec +++ b/pyproject-rpm-macros.spec @@ -6,7 +6,7 @@ License: MIT # Keep the version at zero and increment only release Version: 0 -Release: 19%{?dist} +Release: 20%{?dist} # Macro files Source001: macros.pyproject @@ -101,6 +101,9 @@ export HOSTNAME="rpmbuild" # to speedup tox in network-less mock, see rhbz#1856 %license LICENSE %changelog +* Wed Jul 29 2020 Miro Hrončok - 0-20 +- Implement %%pyproject_extras_subpkg + * Tue Jul 28 2020 Fedora Release Engineering - 0-19 - Rebuilt for https://fedoraproject.org/wiki/Fedora_33_Mass_Rebuild diff --git a/tests/python-setuptools_scm.spec b/tests/python-setuptools_scm.spec new file mode 100644 index 0000000..82cca4c --- /dev/null +++ b/tests/python-setuptools_scm.spec @@ -0,0 +1,55 @@ +Name: python-setuptools_scm +Version: 3.5.0 +Release: 0%{?dist} +Summary: The blessed package to manage your versions by SCM tags +License: MIT +URL: https://github.com/pypa/setuptools_scm/ +Source0: %{pypi_source setuptools_scm} + +BuildArch: noarch +BuildRequires: python3-devel +BuildRequires: pyproject-rpm-macros + +%description +Here we test that %%pyproject_extras_subpkg works and generates +setuptools_scm[toml] extra subpackage. + +Note that it only works on Fedora 33+. + +%package -n python3-setuptools_scm +Summary: %{summary} + +%description -n python3-setuptools_scm +... + +%pyproject_extras_subpkg -n python3-setuptools_scm toml + + +%prep +%autosetup -p1 -n setuptools_scm-%{version} + + +%generate_buildrequires +%pyproject_buildrequires + + +%build +%pyproject_wheel + + +%install +%pyproject_install +%pyproject_save_files setuptools_scm + + +%check +# Internal check for our macros +# making sure that %%{pyproject_ghost_distinfo} has the right content +test -f %{pyproject_ghost_distinfo} +test "$(cat %{pyproject_ghost_distinfo})" == "%ghost %{python3_sitelib}/setuptools_scm-%{version}.dist-info" + + +%files -n python3-setuptools_scm -f %{pyproject_files} +%doc README.rst +%doc CHANGELOG.rst +%license LICENSE diff --git a/tests/tests.yml b/tests/tests.yml index 9322bac..b66ea8c 100644 --- a/tests/tests.yml +++ b/tests/tests.yml @@ -40,6 +40,9 @@ - mistune: dir: . run: ./mocktest.sh python-mistune + - setuptools_scm: + dir: . + run: ./mocktest.sh python-setuptools_scm required_packages: - mock - rpmdevtools