From 4abed5f105028158000c4d105840b1953fec5877 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Tue, 19 Jul 2022 01:15:20 +0200 Subject: [PATCH] Use the values of %_py3_shebang_s and %_py3_shebang_P in the shebang opts/flags As proposed in https://src.fedoraproject.org/rpms/python-rpm-macros/pull-request/141#comment-109228 And discussed in: - https://lists.fedoraproject.org/archives/list/python-devel@lists.fedoraproject.org/thread/4YD2X7HU5U5DFO3N4FWJLPSKVMKH4VSB/ - https://lists.fedoraproject.org/archives/list/packaging@lists.fedoraproject.org/thread/4YD2X7HU5U5DFO3N4FWJLPSKVMKH4VSB/ --- macros.python | 4 +++- macros.python3 | 4 +++- tests/test_evals.py | 25 +++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/macros.python b/macros.python index 8cee2d8..77b3793 100644 --- a/macros.python +++ b/macros.python @@ -13,7 +13,9 @@ %python_cache_tag %(RPM_BUILD_ROOT= %{__python} -Esc "import sys; print(sys.implementation.cache_tag)") %py_setup setup.py -%py_shbang_opts -s%(RPM_BUILD_ROOT= %{__python} -Esc "import sys; print('P' if hasattr(sys.flags, 'safe_path') else '')") +%_py_shebang_s s +%_py_shebang_P %(RPM_BUILD_ROOT= %{__python} -Esc "import sys; print('P' if hasattr(sys.flags, 'safe_path') else '')") +%py_shbang_opts -%{?_py_shebang_s}%{?_py_shebang_P} %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 0fb7ce1..06aab31 100644 --- a/macros.python3 +++ b/macros.python3 @@ -11,7 +11,9 @@ %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%(RPM_BUILD_ROOT= %{__python3} -Ic "import sys; print('P' if hasattr(sys.flags, 'safe_path') else '')") +%_py3_shebang_s s +%_py3_shebang_P %(RPM_BUILD_ROOT= %{__python3} -Ic "import sys; print('P' if hasattr(sys.flags, 'safe_path') else '')") +%py3_shbang_opts -%{?_py3_shebang_s}%{?_py3_shebang_P} %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/tests/test_evals.py b/tests/test_evals.py index d20d184..8b95e94 100644 --- a/tests/test_evals.py +++ b/tests/test_evals.py @@ -423,6 +423,31 @@ 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' + expected = f'-ka{safe_path_flag(X_Y)}' if safe_path_flag(X_Y) else '-k' + assert shell_stdout('\n'.join(lines)) == expected + + +@pytest.mark.parametrize('_py3_shebang_P', [None, '%{nil}']) +def test_py3_shebang_fix_undefined_py3_shebang_P(_py3_shebang_P): + lines = rpm_eval('%py3_shebang_fix arg1 arg2', _py3_shebang_P=_py3_shebang_P) + lines[-1] = 'echo $shebang_flags' + assert shell_stdout('\n'.join(lines)) == '-kas' + + +@pytest.mark.parametrize('_py3_shebang_s', [None, '%{nil}']) +@pytest.mark.parametrize('_py3_shebang_P', [None, '%{nil}']) +def test_py3_shebang_fix_undefined_py3_shebang_sP(_py3_shebang_s, _py3_shebang_P): + lines = rpm_eval('%py3_shebang_fix arg1 arg2', + _py3_shebang_s=_py3_shebang_s, + _py3_shebang_P=_py3_shebang_P) + 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)