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
epel9
Miro Hrončok 3 years ago
parent 81296b67df
commit 05b5b0ae2c

@ -1,6 +1,6 @@
Name: epel-rpm-macros Name: epel-rpm-macros
Version: 8 Version: 8
Release: 21 Release: 22
Summary: Extra Packages for Enterprise Linux RPM macros Summary: Extra Packages for Enterprise Linux RPM macros
Group: System Environment/Base Group: System Environment/Base
@ -65,6 +65,9 @@ install -Dpm 644 %{SOURCE3} \
%changelog %changelog
* Wed Jul 14 2021 Miro Hrončok <mhroncok@redhat.com> - 8-22
- Introduce %%py3_check_import
* Wed May 19 2021 Neal Gompa <ngompa13@gmail.com> - 8-21 * Wed May 19 2021 Neal Gompa <ngompa13@gmail.com> - 8-21
- Drop custom CMake macros, RHEL 8.4 includes them now (cf. rhbz#1858983) - Drop custom CMake macros, RHEL 8.4 includes them now (cf. rhbz#1858983)

@ -82,6 +82,35 @@
end 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() \ %python_disable_dependency_generator() \
%undefine __pythondist_requires \ %undefine __pythondist_requires \
%{nil} %{nil}

Loading…
Cancel
Save