Add common Lua functions, use a Lua function in %python_provide
This commit is contained in:
parent
daf7d32612
commit
b314efc5a7
@ -53,43 +53,32 @@
|
||||
}
|
||||
|
||||
%python_provide() %{lua:
|
||||
local python = require "fedora.srpm.python"
|
||||
function string.starts(String,Start)
|
||||
return string.sub(String,1,string.len(Start))==Start
|
||||
end
|
||||
package = rpm.expand("%{?1}")
|
||||
vr = rpm.expand("%{?epoch:%{epoch}:}%{version}-%{release}")
|
||||
local package = rpm.expand("%{?1}")
|
||||
local vr = rpm.expand("%{?epoch:%{epoch}:}%{version}-%{release}")
|
||||
local altnames = python.python_altnames(package)
|
||||
if (string.starts(package, "python3-")) then
|
||||
print("\\nProvides: python-")
|
||||
print(string.sub(package,9,string.len(package)))
|
||||
print(" = ")
|
||||
print(vr)
|
||||
print("\\nProvides: python" .. rpm.expand("%{__default_python3_pkgversion}") .. "-")
|
||||
print(string.sub(package,9,string.len(package)))
|
||||
print(" = ")
|
||||
print(vr)
|
||||
for i, altname in ipairs(altnames) do
|
||||
print("\\nProvides: " .. altname .. " = " .. vr)
|
||||
end
|
||||
--Obsoleting the previous default python package (if it doesn't have isa)
|
||||
if (string.sub(package, "-1") ~= ")") then
|
||||
print("\\nObsoletes: python-")
|
||||
print(string.sub(package,9,string.len(package)))
|
||||
print(" < ")
|
||||
print(vr)
|
||||
print(" < " .. vr)
|
||||
end
|
||||
elseif (string.starts(package, "python" .. rpm.expand("%{__default_python3_pkgversion}") .. "-")) then
|
||||
print("\\nProvides: python-")
|
||||
l = 8 + string.len(rpm.expand("%{__default_python3_pkgversion}"))
|
||||
print(string.sub(package,l,string.len(package)))
|
||||
print(" = ")
|
||||
print(vr)
|
||||
print("\\nProvides: python3-")
|
||||
print(string.sub(package,l,string.len(package)))
|
||||
print(" = ")
|
||||
print(vr)
|
||||
for i, altname in ipairs(altnames) do
|
||||
print("\\nProvides: " .. altname .. " = " .. vr)
|
||||
end
|
||||
--Obsoleting the previous default python package (if it doesn't have isa)
|
||||
if (string.sub(package, "-1") ~= ")") then
|
||||
print("\\nObsoletes: python-")
|
||||
print(string.sub(package,l,string.len(package)))
|
||||
print(" < ")
|
||||
print(vr)
|
||||
print(string.sub(package,10,string.len(package)))
|
||||
print(" < " .. vr)
|
||||
end
|
||||
elseif (string.starts(package, "python")) then
|
||||
--No unversioned provides as other python3 cases are not the default
|
||||
|
@ -3,7 +3,7 @@ Version: 3.8
|
||||
Release: 4%{?dist}
|
||||
Summary: The common Python RPM macros
|
||||
|
||||
# macros: MIT, compileall2.py: PSFv2
|
||||
# macros and lua: MIT, compileall2.py: PSFv2
|
||||
License: MIT and Python
|
||||
Source0: macros.python
|
||||
Source1: macros.python-srpm
|
||||
@ -11,6 +11,7 @@ Source2: macros.python2
|
||||
Source3: macros.python3
|
||||
Source4: macros.pybytecompile
|
||||
Source5: https://github.com/fedora-python/compileall2/raw/v0.7.1/compileall2.py
|
||||
Source6: python.lua
|
||||
|
||||
BuildArch: noarch
|
||||
# For %%python3_pkgversion used in %%python_provide and compileall2.py
|
||||
@ -64,6 +65,9 @@ mkdir -p %{buildroot}%{_rpmconfigdir}/redhat
|
||||
install -m 644 %{SOURCE5} \
|
||||
%{buildroot}%{_rpmconfigdir}/redhat/
|
||||
|
||||
mkdir -p %{buildroot}%{_rpmluadir}/fedora/srpm
|
||||
install -p -m 644 -t %{buildroot}%{_rpmluadir}/fedora/srpm %{SOURCE6}
|
||||
|
||||
%files
|
||||
%{rpmmacrodir}/macros.python
|
||||
%{rpmmacrodir}/macros.pybytecompile
|
||||
@ -71,6 +75,7 @@ install -m 644 %{SOURCE5} \
|
||||
%files -n python-srpm-macros
|
||||
%{rpmmacrodir}/macros.python-srpm
|
||||
%{_rpmconfigdir}/redhat/compileall2.py
|
||||
%{_rpmluadir}/fedora/srpm/python.lua
|
||||
|
||||
%files -n python2-rpm-macros
|
||||
%{rpmmacrodir}/macros.python2
|
||||
|
32
python.lua
Normal file
32
python.lua
Normal file
@ -0,0 +1,32 @@
|
||||
-- Convenience Lua functions that can be used within Python srpm/rpm macros
|
||||
|
||||
-- Determine alternate names provided from the given name.
|
||||
-- Used in pythonname provides generator, python_provide and py_provides.
|
||||
-- There are 2 rules:
|
||||
-- python3-foo -> python-foo, python3X-foo
|
||||
-- python3X-foo -> python-foo, python3-foo
|
||||
-- There is no python-foo -> rule, python-foo packages are version agnostic.
|
||||
-- Returns a table/array with strings. Empty when no rule matched.
|
||||
local function python_altnames(name)
|
||||
local xy = rpm.expand('%{__default_python3_pkgversion}')
|
||||
local altnames = {}
|
||||
local replaced
|
||||
-- NB: dash needs to be escaped!
|
||||
if name:match('^python3%-') then
|
||||
for i, prefix in ipairs({'python-', 'python' .. xy .. '-'}) do
|
||||
replaced = name:gsub('^python3%-', prefix)
|
||||
table.insert(altnames, replaced)
|
||||
end
|
||||
elseif name:match('^python' .. xy .. '%-') then
|
||||
for i, prefix in ipairs({'python-', 'python3-'}) do
|
||||
replaced = name:gsub('^python' .. xy .. '%-', prefix)
|
||||
table.insert(altnames, replaced)
|
||||
end
|
||||
end
|
||||
return altnames
|
||||
end
|
||||
|
||||
|
||||
return {
|
||||
python_altnames = python_altnames,
|
||||
}
|
Loading…
Reference in New Issue
Block a user