Fix %%py_shebang_flags handling within %%py_check_import
%%py{3}_check_import now respects the custom setting of %%py{3}_shebang_flags and invokes Python with the respective values. If %%py{3}_shebang_flags is undefined or set to no value, there no flags are passed to Python on invoke. Related: rhbz#1950291
This commit is contained in:
parent
62cbbbc802
commit
b2a5690d6b
@ -70,6 +70,7 @@
|
||||
|
||||
# With $PATH and $PYTHONPATH set to the %%buildroot,
|
||||
# try to import the Python module(s) given as command-line args or read from file (-f).
|
||||
# Respect the custom values of %%py_shebang_flags or set nothing if it's undefined.
|
||||
# Filter and check import on only top-level modules using -t flag.
|
||||
# Exclude unwanted modules by passing their globs to -e option.
|
||||
# Useful as a smoke test in %%check when running tests is not feasible.
|
||||
@ -79,11 +80,17 @@
|
||||
PATH="%{buildroot}%{_bindir}:$PATH"\\\
|
||||
PYTHONPATH="${PYTHONPATH:-%{buildroot}%{python_sitearch}:%{buildroot}%{python_sitelib}}"\\\
|
||||
PYTHONDONTWRITEBYTECODE=1\\\
|
||||
%{__python} -%{py_shebang_flags} %{_rpmconfigdir}/redhat/import_all_modules.py\\\
|
||||
%{lua:
|
||||
local command = "%{__python} "
|
||||
if rpm.expand("%{?py_shebang_flags}") ~= "" then
|
||||
command = command .. "-%{py_shebang_flags}"
|
||||
end
|
||||
command = command .. " %{_rpmconfigdir}/redhat/import_all_modules.py "
|
||||
-- handle multiline arguments correctly, see https://bugzilla.redhat.com/2018809
|
||||
local args=rpm.expand('%{?**}'):gsub("[%s\\\\]*%s+", " ");print(args)
|
||||
}}
|
||||
local args=rpm.expand('%{?**}'):gsub("[%s\\\\]*%s+", " ")
|
||||
print(command .. args)
|
||||
}
|
||||
}
|
||||
|
||||
%python_provide() %{lua:
|
||||
local python = require "fedora.srpm.python"
|
||||
|
@ -68,6 +68,7 @@
|
||||
|
||||
# With $PATH and $PYTHONPATH set to the %%buildroot,
|
||||
# try to import the Python 3 module(s) given as command-line args or read from file (-f).
|
||||
# Respect the custom values of %%py3_shebang_flags or set nothing if it's undefined.
|
||||
# Filter and check import on only top-level modules using -t flag.
|
||||
# Exclude unwanted modules by passing their globs to -e option.
|
||||
# Useful as a smoke test in %%check when running tests is not feasible.
|
||||
@ -77,11 +78,17 @@
|
||||
PATH="%{buildroot}%{_bindir}:$PATH"\\\
|
||||
PYTHONPATH="${PYTHONPATH:-%{buildroot}%{python3_sitearch}:%{buildroot}%{python3_sitelib}}"\\\
|
||||
PYTHONDONTWRITEBYTECODE=1\\\
|
||||
%{__python3} -%{py3_shebang_flags} %{_rpmconfigdir}/redhat/import_all_modules.py\\\
|
||||
%{lua:
|
||||
local command = "%{__python3} "
|
||||
if rpm.expand("%{?py3_shebang_flags}") ~= "" then
|
||||
command = command .. "-%{py3_shebang_flags}"
|
||||
end
|
||||
command = command .. " %{_rpmconfigdir}/redhat/import_all_modules.py "
|
||||
-- handle multiline arguments correctly, see https://bugzilla.redhat.com/2018809
|
||||
local args=rpm.expand('%{?**}'):gsub("[%s\\\\]*%s+", " ");print(args)
|
||||
}}
|
||||
local args=rpm.expand('%{?**}'):gsub("[%s\\\\]*%s+", " ")
|
||||
print(command .. args)
|
||||
}
|
||||
}
|
||||
|
||||
# This only supports Python 3.5+ and will never work with Python 2.
|
||||
# Hence, it has no Python version in the name.
|
||||
|
@ -103,6 +103,7 @@ install -m 644 import_all_modules.py %{buildroot}%{_rpmconfigdir}/redhat/
|
||||
%changelog
|
||||
* Mon Nov 01 2021 Karolina Surma <ksurma@redhat.com> - 3.9-46
|
||||
- Fix multiline arguments processing for %%py_check_import
|
||||
- Fix %%py_shebang_flags handling within %%py_check_import
|
||||
|
||||
* Mon Oct 25 2021 Karolina Surma <ksurma@redhat.com> - 3.9-45
|
||||
- Introduce -f (read from file) option to %%py{3}_check_import
|
||||
|
@ -673,6 +673,7 @@ def test_py3_check_import(args, expected_args, __python3, lib):
|
||||
macros = {
|
||||
'buildroot': 'BUILDROOT',
|
||||
'_rpmconfigdir': 'RPMCONFIGDIR',
|
||||
'py3_shebang_flags': 's',
|
||||
}
|
||||
if __python3 is not None:
|
||||
if 'X.Y' in __python3:
|
||||
@ -696,7 +697,27 @@ def test_py3_check_import(args, expected_args, __python3, lib):
|
||||
PATH="BUILDROOT/usr/bin:$PATH"
|
||||
PYTHONPATH="${{PYTHONPATH:-BUILDROOT/usr/{lib}/python{x_y}/site-packages:BUILDROOT/usr/lib/python{x_y}/site-packages}}"
|
||||
PYTHONDONTWRITEBYTECODE=1
|
||||
{__python3 or '/usr/bin/python3'} -s RPMCONFIGDIR/redhat/import_all_modules.py
|
||||
{expected_args}
|
||||
{__python3 or '/usr/bin/python3'} -s RPMCONFIGDIR/redhat/import_all_modules.py {expected_args}
|
||||
""")
|
||||
assert lines == expected.splitlines()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'shebang_flags_value, expected_shebang_flags',
|
||||
[
|
||||
('s', '-s'),
|
||||
('%{nil}', ''),
|
||||
(None, ''),
|
||||
('Es', '-Es'),
|
||||
]
|
||||
)
|
||||
def test_py3_check_import_respects_shebang_flags(shebang_flags_value, expected_shebang_flags, lib):
|
||||
macros = {
|
||||
'_rpmconfigdir': 'RPMCONFIGDIR',
|
||||
'__python3': '/usr/bin/python3',
|
||||
'py3_shebang_flags': shebang_flags_value,
|
||||
}
|
||||
lines = rpm_eval('%py3_check_import sys', **macros)
|
||||
# Compare the last line of the command, that's where lua part is evaluated
|
||||
expected = f'/usr/bin/python3 {expected_shebang_flags} RPMCONFIGDIR/redhat/import_all_modules.py sys'
|
||||
assert lines[-1].strip() == expected
|
||||
|
Loading…
Reference in New Issue
Block a user