From 05b5b0ae2c852bbd9f0047bdfa5bb4250a8974fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Wed, 14 Jul 2021 18:49:40 +0200 Subject: [PATCH] Introduce %py3_check_import With $PATH and $PYTHONPATH set to the %buildroot, the macro tries to import the given Python 3 module(s). Useful as a smoke test in %check when ruining tests is not feasible. Accepts spaces or commas as separators. Backport of https://src.fedoraproject.org/rpms/python-rpm-macros/c/c2305ea3 --- epel-rpm-macros.spec | 5 ++++- macros.epel-rpm-macros | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/epel-rpm-macros.spec b/epel-rpm-macros.spec index 310c479..41b73bb 100644 --- a/epel-rpm-macros.spec +++ b/epel-rpm-macros.spec @@ -1,6 +1,6 @@ Name: epel-rpm-macros Version: 8 -Release: 21 +Release: 22 Summary: Extra Packages for Enterprise Linux RPM macros Group: System Environment/Base @@ -65,6 +65,9 @@ install -Dpm 644 %{SOURCE3} \ %changelog +* Wed Jul 14 2021 Miro HronĨok - 8-22 +- Introduce %%py3_check_import + * Wed May 19 2021 Neal Gompa - 8-21 - Drop custom CMake macros, RHEL 8.4 includes them now (cf. rhbz#1858983) diff --git a/macros.epel-rpm-macros b/macros.epel-rpm-macros index dfe4f40..c693891 100644 --- a/macros.epel-rpm-macros +++ b/macros.epel-rpm-macros @@ -82,6 +82,35 @@ end } +# With $PATH and $PYTHONPATH set to the %%buildroot, +# try to import the given Python module(s). +# Useful as a smoke test in %%check when running tests is not feasible. +# Use spaces or commas as separators. +%py_check_import() %{expand:\\\ + (cd %{_topdir} &&\\\ + PATH="%{buildroot}%{_bindir}:$PATH"\\\ + PYTHONPATH="${PYTHONPATH:-%{buildroot}%{python_sitearch}:%{buildroot}%{python_sitelib}}"\\\ + PYTHONDONTWRITEBYTECODE=1\\\ + %{__python} -c "import %{lua:local m=rpm.expand('%{?*}'):gsub('[%s,]+', ', ');print(m)}" + ) +} +%py2_check_import() %{expand:\\\ + (cd %{_topdir} &&\\\ + PATH="%{buildroot}%{_bindir}:$PATH"\\\ + PYTHONPATH="${PYTHONPATH:-%{buildroot}%{python2_sitearch}:%{buildroot}%{python2_sitelib}}"\\\ + PYTHONDONTWRITEBYTECODE=1\\\ + %{__python2} -c "import %{lua:local m=rpm.expand('%{?*}'):gsub('[%s,]+', ', ');print(m)}" + ) +} +%py3_check_import() %{expand:\\\ + (cd %{_topdir} &&\\\ + PATH="%{buildroot}%{_bindir}:$PATH"\\\ + PYTHONPATH="${PYTHONPATH:-%{buildroot}%{python3_sitearch}:%{buildroot}%{python3_sitelib}}"\\\ + PYTHONDONTWRITEBYTECODE=1\\\ + %{__python3} -c "import %{lua:local m=rpm.expand('%{?*}'):gsub('[%s,]+', ', ');print(m)}" + ) +} + %python_disable_dependency_generator() \ %undefine __pythondist_requires \ %{nil}