From d83a32823cf8758cb52bda89d545a8a35dbe6792 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Tue, 19 Jul 2022 16:34:01 +0200 Subject: [PATCH] Define and use %{_py3_shebang_s} in the shebang macros for easier opt-out This is in-line with https://fedoraproject.org/wiki/Changes/PythonSafePath#Opting_out Backported from https://src.fedoraproject.org/rpms/python-rpm-macros/pull-request/141 --- macros.python | 3 ++- macros.python3 | 3 ++- python-rpm-macros.spec | 1 + tests/test_evals.py | 7 +++++++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/macros.python b/macros.python index 9cec71c..71a0bae 100644 --- a/macros.python +++ b/macros.python @@ -12,7 +12,8 @@ %python_cache_tag %(RPM_BUILD_ROOT= %{__python} -Esc "import sys; print(sys.implementation.cache_tag)") %py_setup setup.py -%py_shbang_opts -s +%_py_shebang_s s +%py_shbang_opts -%{?_py_shebang_s} %py_shbang_opts_nodash %(opts=%{py_shbang_opts}; echo ${opts#-}) %py_shebang_flags %(opts=%{py_shbang_opts}; echo ${opts#-}) %py_shebang_fix %{expand:\\\ diff --git a/macros.python3 b/macros.python3 index a29c5ef..b3a0d2c 100644 --- a/macros.python3 +++ b/macros.python3 @@ -10,7 +10,8 @@ %python3_cache_tag %(RPM_BUILD_ROOT= %{__python3} -Ic "import sys; print(sys.implementation.cache_tag)") %py3dir %{_builddir}/python3-%{name}-%{version}-%{release} -%py3_shbang_opts -s +%_py3_shebang_s s +%py3_shbang_opts -%{?_py3_shebang_s} %py3_shbang_opts_nodash %(opts=%{py3_shbang_opts}; echo ${opts#-}) %py3_shebang_flags %(opts=%{py3_shbang_opts}; echo ${opts#-}) %py3_shebang_fix %{expand:\\\ diff --git a/python-rpm-macros.spec b/python-rpm-macros.spec index e3f5b65..c93d2b2 100644 --- a/python-rpm-macros.spec +++ b/python-rpm-macros.spec @@ -148,6 +148,7 @@ install -m 755 brp-* %{buildroot}%{_rpmconfigdir}/redhat/ %changelog * Tue Jul 19 2022 Miro Hrončok - 3.10-12 - Define %%python3_cache_tag / %%python_cache_tag, e.g. cpython-311 +- Define and use %%{_py3_shebang_s} in the shebang macros for easier opt-out * Mon Feb 07 2022 Miro Hrončok - 3.10-11 - Set $RPM_BUILD_ROOT in %%{python3_...} macros diff --git a/tests/test_evals.py b/tests/test_evals.py index 5060705..43ac6f2 100644 --- a/tests/test_evals.py +++ b/tests/test_evals.py @@ -334,6 +334,13 @@ def test_py3_shebang_fix_custom_shebang_flags(): assert shell_stdout('\n'.join(lines)) == '-kaEs' +@pytest.mark.parametrize('_py3_shebang_s', [None, '%{nil}']) +def test_py3_shebang_fix_undefined_py3_shebang_s(_py3_shebang_s): + lines = rpm_eval('%py3_shebang_fix arg1 arg2', _py3_shebang_s=_py3_shebang_s) + lines[-1] = 'echo $shebang_flags' + assert shell_stdout('\n'.join(lines)) == '-k' + + @pytest.mark.parametrize('flags', [None, '%{nil}']) def test_py3_shebang_fix_no_shebang_flags(flags): lines = rpm_eval('%py3_shebang_fix arg1 arg2', py3_shebang_flags=flags)