diff --git a/macros.python b/macros.python index ddc737b..1ed0219 100644 --- a/macros.python +++ b/macros.python @@ -10,7 +10,14 @@ %py_shbang_opts -s %py_shbang_opts_nodash %(opts=%{py_shbang_opts}; echo ${opts#-}) %py_shebang_flags %(opts=%{py_shbang_opts}; echo ${opts#-}) -%py_shebang_fix %{expand:/usr/bin/pathfix.py -pni %{__python} -k%{?py_shebang_flags:a %py_shebang_flags}} +%py_shebang_fix %{expand:\\\ + if [ -f /usr/bin/pathfix%{python_version}.py ]; then + pathfix=/usr/bin/pathfix%{python_version}.py + else + # older versions of Python don't have it and must BR /usr/bin/pathfix.py from python3-devel explicitly + pathfix=/usr/bin/pathfix.py + fi + $pathfix -pni %{__python} -k%{?py_shebang_flags:a %py_shebang_flags}} # Use the slashes after expand so that the command starts on the same line as # the macro diff --git a/macros.python3 b/macros.python3 index 42e7143..cfd8019 100644 --- a/macros.python3 +++ b/macros.python3 @@ -8,7 +8,14 @@ %py3_shbang_opts -s %py3_shbang_opts_nodash %(opts=%{py3_shbang_opts}; echo ${opts#-}) %py3_shebang_flags %(opts=%{py3_shbang_opts}; echo ${opts#-}) -%py3_shebang_fix %{expand:/usr/bin/pathfix.py -pni %{__python3} -k%{?py3_shebang_flags:a %py3_shebang_flags}} +%py3_shebang_fix %{expand:\\\ + if [ -f /usr/bin/pathfix%{python3_version}.py ]; then + pathfix=/usr/bin/pathfix%{python3_version}.py + else + # older versions of Python don't have it and must BR /usr/bin/pathfix.py from python3-devel explicitly + pathfix=/usr/bin/pathfix.py + fi + $pathfix -pni %{__python3} -k%{?py3_shebang_flags:a %py3_shebang_flags}} # Use the slashes after expand so that the command starts on the same line as # the macro diff --git a/python-rpm-macros.spec b/python-rpm-macros.spec index 8128055..579fae1 100644 --- a/python-rpm-macros.spec +++ b/python-rpm-macros.spec @@ -1,6 +1,6 @@ Name: python-rpm-macros Version: 3.9 -Release: 8%{?dist} +Release: 9%{?dist} Summary: The common Python RPM macros # macros and lua: MIT, compileall2.py: PSFv2 @@ -107,6 +107,9 @@ install -m 644 compileall2.py %{buildroot}%{_rpmconfigdir}/redhat/ %changelog +* Fri Jul 24 2020 Lumír Balhar - 3.9-9 +- Adapt %%py[3]_shebang_fix to use versioned pathfixX.Y.py + * Fri Jul 24 2020 Lumír Balhar - 3.9-8 - Disable Python hash seed randomization in %%py_byte_compile diff --git a/tests/test_evals.py b/tests/test_evals.py index fa49439..ec26668 100644 --- a/tests/test_evals.py +++ b/tests/test_evals.py @@ -228,23 +228,23 @@ def test_pypi_source_explicit_tilde(): def test_py3_shebang_fix(): - cmd = rpm_eval('%py3_shebang_fix arg1 arg2 arg3')[0] - assert cmd == '/usr/bin/pathfix.py -pni /usr/bin/python3 -ka s arg1 arg2 arg3' + cmd = rpm_eval('%py3_shebang_fix arg1 arg2 arg3')[-1].strip() + assert cmd == '$pathfix -pni /usr/bin/python3 -ka s arg1 arg2 arg3' def test_py3_shebang_fix_custom_flags(): - cmd = rpm_eval('%py3_shebang_fix arg1 arg2 arg3', py3_shebang_flags='Es')[0] - assert cmd == '/usr/bin/pathfix.py -pni /usr/bin/python3 -ka Es arg1 arg2 arg3' + cmd = rpm_eval('%py3_shebang_fix arg1 arg2 arg3', py3_shebang_flags='Es')[-1].strip() + assert cmd == '$pathfix -pni /usr/bin/python3 -ka Es arg1 arg2 arg3' def test_py3_shebang_fix_empty_flags(): - cmd = rpm_eval('%py3_shebang_fix arg1 arg2 arg3', py3_shebang_flags=None)[0] - assert cmd == '/usr/bin/pathfix.py -pni /usr/bin/python3 -k arg1 arg2 arg3' + cmd = rpm_eval('%py3_shebang_fix arg1 arg2 arg3', py3_shebang_flags=None)[-1].strip() + assert cmd == '$pathfix -pni /usr/bin/python3 -k arg1 arg2 arg3' def test_py_shebang_fix_custom(): - cmd = rpm_eval('%py_shebang_fix arg1 arg2 arg3', __python='/usr/bin/pypy')[0] - assert cmd == '/usr/bin/pathfix.py -pni /usr/bin/pypy -ka s arg1 arg2 arg3' + cmd = rpm_eval('%py_shebang_fix arg1 arg2 arg3', __python='/usr/bin/pypy')[-1].strip() + assert cmd == '$pathfix -pni /usr/bin/pypy -ka s arg1 arg2 arg3' def test_pycached_in_sitelib():