Add python(prerel-abi) provides/requirements

This commit is contained in:
Karolina Surma 2025-11-19 14:39:34 +01:00
commit 01c48c8ad5
3 changed files with 69 additions and 2 deletions

58
pythonprerel.attr Normal file
View file

@ -0,0 +1,58 @@
%__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 buildroot = rpm.expand('%{buildroot}')
local ld_library_path = buildroot .. '/usr/lib64:' .. buildroot .. '/usr/lib'
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 buildroot = rpm.expand('%{buildroot}')
local python_path = buildroot .. '/usr/bin/python' .. pyver
local version = _pythonprerel_version_cache[python_path]
if not version then
local ld_library_path = buildroot .. '/usr/lib64:' .. buildroot .. '/usr/lib'
local cmd = 'LD_LIBRARY_PATH=' .. ld_library_path .. ' ' .. 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:]]+/.*\\.so)|(%{_bindir}/python[[:digit:]]+\\.[[:digit:]]+))$