python-rpm-generators/pythonprerel.attr
2025-11-21 14:56:31 +01:00

55 lines
2.3 KiB
Text

%__pythonprerel_provides() %{lua:
-- Match buildroot/payload paths of the form
-- /PATH/OF/BUILDROOT/usr/bin/pythonMAJOR.MINOR
-- generating a line of the form
-- python(prerel-abi) = MAJOR.MINOR.MICRO~RELEASELEVELSERIAL
-- (Don't match against -config tools e.g. /usr/bin/python3.14-config)
local path = rpm.expand('%1')
if path:match('/usr/bin/python%d+%.%d+$') then
if not _pythonprerel_version_cache then
_pythonprerel_version_cache = {}
end
local version = _pythonprerel_version_cache[path]
if not version then
local ld_library_path = rpm.expand('%{buildroot}%{_libdir}')
local cmd = 'LD_LIBRARY_PATH=' .. ld_library_path .. ' ' .. path .. [[ -Esc "import sys; sys.stdout.write('{0.major}.{0.minor}.{0.micro}~{0.releaselevel}{0.serial}'.format(sys.version_info))"]]
version = io.popen(cmd):read("*a")
-- Cache the version for future calls
_pythonprerel_version_cache[path] = version
end
local provides = 'python(prerel-abi) = ' .. version
print(provides)
end
}
%__pythonprerel_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(prerel-abi) = MAJOR.MINOR.MICRO~RELEASELEVELSERIAL
local path = rpm.expand('%1')
local pyver = path:match('/usr/lib%d*/python(%d+%.%d+)/.*')
if pyver then
if not _pythonprerel_version_cache then
_pythonprerel_version_cache = {}
end
local python_path = '/usr/bin/python' .. pyver
local version = _pythonprerel_version_cache[python_path]
if not version then
local cmd = python_path .. [[ -Esc "import sys; sys.stdout.write('{0.major}.{0.minor}.{0.micro}~{0.releaselevel}{0.serial}'.format(sys.version_info))"]]
version = io.popen(cmd):read("*a")
-- Cache the version for future calls
_pythonprerel_version_cache[python_path] = version
end
local requires = 'python(prerel-abi) = ' .. version
print(requires)
end
}
%__pythonprerel_path ^((/usr/lib(64)?/python[[:digit:]]+\\.[[:digit:]]+/site-packages/.*\\.so)|(%{_bindir}/python[[:digit:]]+\\.[[:digit:]]+))$