From 97a7574518e5b67379933fb14fba16b04741c49f Mon Sep 17 00:00:00 2001 From: Karolina Surma Date: Wed, 13 Sep 2023 12:50:59 +0200 Subject: [PATCH] Add %_pyproject_check_import_allow_no_modules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Macro which allows to pass the import check even if no Python modules are detected in the package. Only to be used in the automated environments. Co-authored-by: Miro HronĨok --- README.md | 6 ++++++ macros.pyproject | 8 ++++++++ pyproject-rpm-macros.spec | 7 +++++-- tests/python-getmac.spec | 33 +++++++++++++++++++++++++++++++-- 4 files changed, 50 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 256f3f5..9700ef8 100644 --- a/README.md +++ b/README.md @@ -342,6 +342,12 @@ The `%pyproject_check_import` macro also accepts positional arguments with additional qualified module names to check, useful for example if some modules are installed manually. Note that filtering by `-t`/`-e` also applies to the positional arguments. +Another macro, `%_pyproject_check_import_allow_no_modules` allows to pass the import check, +even if no Python modules are detected in the package. +This may be a valid case for packages containing e.g. typing stubs. +Don't use this macro in Fedora packages. +It's only intended to be used in automated build environments such as Copr. + Generating Extras subpackages ----------------------------- diff --git a/macros.pyproject b/macros.pyproject index 12c7a64..7013de2 100644 --- a/macros.pyproject +++ b/macros.pyproject @@ -133,6 +133,14 @@ fi } +%_pyproject_check_import_allow_no_modules(e:t) \ +if [ -z "$(cat %{_pyproject_modules})" ]; then\ + echo "No modules to check found, exiting check"\ +else\ + %pyproject_check_import %{?**}\ +fi + + %default_toxenv py%{python3_version_nodots} %toxenv %{default_toxenv} diff --git a/pyproject-rpm-macros.spec b/pyproject-rpm-macros.spec index c1dcae0..ddb16b5 100644 --- a/pyproject-rpm-macros.spec +++ b/pyproject-rpm-macros.spec @@ -13,8 +13,8 @@ License: MIT # Increment Y and reset Z when new macros or features are added # Increment Z when this is a bugfix or a cosmetic change # Dropping support for EOL Fedoras is *not* considered a breaking change -Version: 1.9.0 -Release: 2%{?dist} +Version: 1.10.0 +Release: 1%{?dist} # Macro files Source001: macros.pyproject @@ -161,6 +161,9 @@ export HOSTNAME="rpmbuild" # to speedup tox in network-less mock, see rhbz#1856 %changelog +* Wed Sep 13 2023 Karolina Surma - 1.10.0-1 +- Add %%_pyproject_check_import_allow_no_modules for automated environments + * Fri Jul 21 2023 Fedora Release Engineering - 1.9.0-2 - Rebuilt for https://fedoraproject.org/wiki/Fedora_39_Mass_Rebuild diff --git a/tests/python-getmac.spec b/tests/python-getmac.spec index 95bfaa0..61863c8 100644 --- a/tests/python-getmac.spec +++ b/tests/python-getmac.spec @@ -12,7 +12,10 @@ BuildRequires: pyproject-rpm-macros %global _description %{expand: -Test that manpages are correctly processed by %%pyproject_save_files '*' +auto.} +Test that manpages are correctly processed by %%%%%%%%pyproject_save_files '*' +auto. +Run %%%%%%%%_pyproject_check_import_allow_no_modules twice +- exclude all modules and test the check still passes thanks to -M option +- regression test: test that check imports all modules even if -M option is set} %description %_description @@ -41,10 +44,36 @@ Summary: %{summary} %check +# Internal check for our macros, assert the behavior of the import check macros +# Both of the macros should succeed %pyproject_check_import +%_pyproject_check_import_allow_no_modules +(%{pyproject_check_import}) 2>pyproject_check_import.stderr +(%{_pyproject_check_import_allow_no_modules}) 2>_pyproject_check_import_allow_no_modules.stderr + +# Modules were found, stderrs should include getmac.getmac +grep '^Check import: getmac\.getmac$' pyproject_check_import.stderr +grep '^Check import: getmac\.getmac$' _pyproject_check_import_allow_no_modules.stderr + +# Now let's pretend no modules were found at all +echo -e '' > %{_pyproject_modules} + +# This should fail +(%{pyproject_check_import}) && exit 1 || true + +# This should succeed and say something about no modules found +%{_pyproject_check_import_allow_no_modules} +(%{_pyproject_check_import_allow_no_modules}) 2>_pyproject_check_import_allow_no_modules.stderr +grep '\bNo modules to check found\b' _pyproject_check_import_allow_no_modules.stderr + +# We want to ensure the rest of the %%check section is still executed +# (To avoid a temptation to call `exit 0` from %%_pyproject_check_import_allow_no_modules) +# We'll touch a marker file here and assert its presence in %%files +touch %{buildroot}/check-completed-entirely + # Internal check for our macros, assert there is a manpage: test -f %{buildroot}%{_mandir}/man1/getmac.1* %files -n python3-getmac -f %{pyproject_files} - +/check-completed-entirely