Allow multiline arguments processing for %%py3_check_import
Fixes the regression introduced with the macro reimplementation. Related: rhbz#1950291
This commit is contained in:
parent
eb3f38ce4b
commit
62cbbbc802
@ -39,6 +39,10 @@ def read_modules_from_cli(argv):
|
||||
# we need to unify the output to a list of particular elements
|
||||
modules_as_str = ' '.join(argv)
|
||||
modules = re.split(r'[\s,]+', modules_as_str)
|
||||
# Because of shell expansion in some less typical cases it may happen
|
||||
# that a trailing space will occur at the end of the list.
|
||||
# Remove the empty items from the list before passing it further
|
||||
modules = [m for m in modules if m]
|
||||
return modules
|
||||
|
||||
|
||||
|
@ -79,8 +79,11 @@
|
||||
PATH="%{buildroot}%{_bindir}:$PATH"\\\
|
||||
PYTHONPATH="${PYTHONPATH:-%{buildroot}%{python_sitearch}:%{buildroot}%{python_sitelib}}"\\\
|
||||
PYTHONDONTWRITEBYTECODE=1\\\
|
||||
%{__python} -%{py_shebang_flags} %{_rpmconfigdir}/redhat/import_all_modules.py %{?**}
|
||||
}
|
||||
%{__python} -%{py_shebang_flags} %{_rpmconfigdir}/redhat/import_all_modules.py\\\
|
||||
%{lua:
|
||||
-- handle multiline arguments correctly, see https://bugzilla.redhat.com/2018809
|
||||
local args=rpm.expand('%{?**}'):gsub("[%s\\\\]*%s+", " ");print(args)
|
||||
}}
|
||||
|
||||
%python_provide() %{lua:
|
||||
local python = require "fedora.srpm.python"
|
||||
|
@ -77,8 +77,11 @@
|
||||
PATH="%{buildroot}%{_bindir}:$PATH"\\\
|
||||
PYTHONPATH="${PYTHONPATH:-%{buildroot}%{python3_sitearch}:%{buildroot}%{python3_sitelib}}"\\\
|
||||
PYTHONDONTWRITEBYTECODE=1\\\
|
||||
%{__python3} -%{py3_shebang_flags} %{_rpmconfigdir}/redhat/import_all_modules.py %{?**}
|
||||
}
|
||||
%{__python3} -%{py3_shebang_flags} %{_rpmconfigdir}/redhat/import_all_modules.py\\\
|
||||
%{lua:
|
||||
-- handle multiline arguments correctly, see https://bugzilla.redhat.com/2018809
|
||||
local args=rpm.expand('%{?**}'):gsub("[%s\\\\]*%s+", " ");print(args)
|
||||
}}
|
||||
|
||||
# This only supports Python 3.5+ and will never work with Python 2.
|
||||
# Hence, it has no Python version in the name.
|
||||
|
@ -1,6 +1,6 @@
|
||||
Name: python-rpm-macros
|
||||
Version: 3.9
|
||||
Release: 45%{?dist}
|
||||
Release: 46%{?dist}
|
||||
Summary: The common Python RPM macros
|
||||
URL: https://src.fedoraproject.org/rpms/python-rpm-macros/
|
||||
|
||||
@ -101,6 +101,9 @@ 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
|
||||
|
||||
* Mon Oct 25 2021 Karolina Surma <ksurma@redhat.com> - 3.9-45
|
||||
- Introduce -f (read from file) option to %%py{3}_check_import
|
||||
- Introduce -t (filter top-level modules) option to %%py{3}_check_import
|
||||
|
@ -653,20 +653,22 @@ def test_python3_sitearch_value_alternate_python(lib, alt_x_y):
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'args',
|
||||
'args, expected_args',
|
||||
[
|
||||
'six',
|
||||
'-f foo.txt',
|
||||
'-t -f foo.txt six, seven',
|
||||
'-e "foo*" -f foo.txt six, seven',
|
||||
'six.quarter six.half,, SIX',
|
||||
('six', 'six'),
|
||||
('-f foo.txt', '-f foo.txt'),
|
||||
('-t -f foo.txt six, seven', '-t -f foo.txt six, seven'),
|
||||
('-e "foo*" -f foo.txt six, seven', '-e "foo*" -f foo.txt six, seven'),
|
||||
('six.quarter six.half,, SIX', 'six.quarter six.half,, SIX'),
|
||||
('-f foo.txt six\nsix.half\nSIX', '-f foo.txt six six.half SIX'),
|
||||
('six \\ -e six.half', 'six -e six.half'),
|
||||
]
|
||||
)
|
||||
@pytest.mark.parametrize('__python3',
|
||||
[None,
|
||||
f'/usr/bin/python{X_Y}',
|
||||
'/usr/bin/pythonX.Y'])
|
||||
def test_py3_check_import(args, __python3, lib):
|
||||
def test_py3_check_import(args, expected_args, __python3, lib):
|
||||
x_y = X_Y
|
||||
macros = {
|
||||
'buildroot': 'BUILDROOT',
|
||||
@ -682,7 +684,8 @@ def test_py3_check_import(args, __python3, lib):
|
||||
if (match := re.match(r'.+python(\d+\.\d+)$', __python3)):
|
||||
x_y = match.group(1)
|
||||
|
||||
lines = rpm_eval(f'%py3_check_import {args}', **macros)
|
||||
invocation = '%{py3_check_import ' + args +'}'
|
||||
lines = rpm_eval(invocation, **macros)
|
||||
|
||||
# An equality check is a bit inflexible here,
|
||||
# every time we change the macro we need to change this test.
|
||||
@ -693,6 +696,7 @@ def test_py3_check_import(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 {args}
|
||||
{__python3 or '/usr/bin/python3'} -s RPMCONFIGDIR/redhat/import_all_modules.py
|
||||
{expected_args}
|
||||
""")
|
||||
assert lines == expected.splitlines()
|
||||
|
@ -30,6 +30,7 @@ def preserve_sys_modules():
|
||||
('five six seven', ['five', 'six', 'seven']),
|
||||
('six,seven, eight', ['six', 'seven', 'eight']),
|
||||
('six.quarter six.half,, SIX', ['six.quarter', 'six.half', 'SIX']),
|
||||
('six.quarter six.half,, SIX \\ ', ['six.quarter', 'six.half', 'SIX']),
|
||||
]
|
||||
)
|
||||
def test_read_modules_from_cli(args, imports):
|
||||
|
Loading…
Reference in New Issue
Block a user