python-rpm-generators/python.attr
Miro Hrončok ff7b9b1ae0 Reimplement pythondeps.sh as parametric macro generators
pythondeps.sh was written in shell and unlike the Python dist generators,
it uses no Python, it plainly determines the provide / requires from the path.
As the script was run for every Python file, we were potentially doing hundreds
of shelling outs to execute a script that calls grep and sed.

In Lua, this is much more efficient.

Some timings:
    https://github.com/rpm-software-management/rpm/pull/1153#issuecomment-607146356

Parametric macro generators require RPM 4.16+:
    https://fedoraproject.org/wiki/Changes/RPM-4.16

Fixes https://github.com/rpm-software-management/rpm/issues/1152
Upstream PR: https://github.com/rpm-software-management/rpm/pull/1153

Since this is intended for Fedora 33+ only, clean some old cruft.
2020-04-01 15:53:15 +02:00

29 lines
1.1 KiB
Plaintext

%__python_provides() %{lua:
-- Match buildroot/payload paths of the form
-- /PATH/OF/BUILDROOT/usr/bin/pythonMAJOR.MINOR
-- generating a line of the form
-- python(abi) = MAJOR.MINOR
-- (Don't match against -config tools e.g. /usr/bin/python2.6-config)
local path = rpm.expand('%1')
if path:match('/usr/bin/python%d+%.%d+$') then
provides = path:gsub('.*/usr/bin/python(%d+%.%d+)', 'python(abi) = %1')
print(provides)
end
}
%__python_requires() %{lua:
-- Match buildroot paths of the form
-- /PATH/OF/BUILDROOT/usr/lib/pythonMAJOR.MINOR/ and
-- /PATH/OF/BUILDROOT/usr/lib64/pythonMAJOR.MINOR/
-- generating a line of the form:
-- python(abi) = MAJOR.MINOR
local path = rpm.expand('%1')
if path:match('/usr/lib%d*/python%d+%.%d+/.*') then
requires = path:gsub('.*/usr/lib%d*/python(%d+%.%d+)/.*', 'python(abi) = %1')
print(requires)
end
}
%__python_path ^((/usr/lib(64)?/python[[:digit:]]\\.[[:digit:]]+/.*\\.(py[oc]?|so))|(^%{_bindir}/python[[:digit:]]\\.[[:digit:]]+))$
%__python_magic [Pp]ython.*(executable|byte-compiled)