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
This commit is contained in:
Miro Hrončok 2022-07-19 16:34:01 +02:00
parent 3cce7271e4
commit 24dc66a003
4 changed files with 12 additions and 2 deletions

View File

@ -13,7 +13,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:\\\

View File

@ -11,7 +11,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:\\\

View File

@ -153,6 +153,7 @@ grep -E '^#[^%%]*%%[^%%]' %{buildroot}%{rpmmacrodir}/macros.* && exit 1 || true
%changelog
* Tue Jul 19 2022 Miro Hrončok <mhroncok@redhat.com> - 3.10-19
- 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
* Thu May 26 2022 Owen Taylor <otaylor@redhat.com> - 3.10-18
- Support installing to %%{_prefix} other than /usr

View File

@ -418,6 +418,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)