|
|
61e6f0 |
# python3_pkgversion specifies the version of Python 3 in the distro. It can be
|
|
|
61e6f0 |
# a specific version (e.g. 34 in Fedora EPEL7)
|
|
|
61e6f0 |
%python3_pkgversion 3
|
|
|
61e6f0 |
|
|
|
61e6f0 |
# Set to /bin/true to avoid %ifdefs and %{? in specfiles
|
|
|
61e6f0 |
%__python3_other /bin/true
|
|
|
61e6f0 |
%py3_other_build /bin/true
|
|
|
61e6f0 |
%py3_other_install /bin/true
|
|
|
61e6f0 |
|
|
|
5a0278 |
# Define where Python wheels will be stored and the prefix of -wheel packages
|
|
|
5a0278 |
# - In Fedora we want wheel subpackages named e.g. `python-pip-wheel` that
|
|
|
5a0278 |
# install packages into `/usr/share/python-wheels`. Both names are not
|
|
|
5a0278 |
# versioned, because they're used by all Python 3 stacks.
|
|
|
5a0278 |
# - In RHEL we want wheel packages named e.g. `python3-pip-wheel` and
|
|
|
5a0278 |
# `python3.11-pip-wheel` that install packages into similarly versioned
|
|
|
5a0278 |
# locations. We want each Python stack in RHEL to have their own wheels,
|
|
|
5a0278 |
# because the main python3 wheels (which we can't upgrade) will likely be
|
|
|
5a0278 |
# quite old by the time we're adding new alternate Python stacks.
|
|
|
5a0278 |
# - In ELN we want to follow Fedora, because builds for ELN and Fedora rawhide
|
|
|
5a0278 |
# need to be interoperable.
|
|
|
5a0278 |
%python_wheel_pkg_prefix python%{?rhel:%{!?eln:%{python3_pkgversion}}}
|
|
|
5a0278 |
%python_wheel_dir %{_datadir}/%{python_wheel_pkg_prefix}-wheels
|
|
|
61e6f0 |
|
|
|
61e6f0 |
|
|
|
61e6f0 |
# === Macros for Build/Requires tags using Python dist tags ===
|
|
|
61e6f0 |
# - https://fedoraproject.org/wiki/Changes/Automatic_Provides_for_Python_RPM_Packages
|
|
|
61e6f0 |
# - These macros need to be in macros.python-srpm, because BuildRequires tags
|
|
|
61e6f0 |
# get rendered as runtime requires into the metadata of SRPMs.
|
|
|
61e6f0 |
|
|
|
61e6f0 |
# Converts Python dist name to a canonical format
|
|
|
61e6f0 |
%py_dist_name() %{lua:\
|
|
|
61e6f0 |
name = rpm.expand("%{?1:%{1}}");\
|
|
|
61e6f0 |
canonical = string.gsub(string.lower(name), "[^%w%.]+", "-");\
|
|
|
61e6f0 |
print(canonical);\
|
|
|
61e6f0 |
}
|
|
|
61e6f0 |
|
|
|
61e6f0 |
# Creates Python 2 dist tag(s) after converting names to canonical format
|
|
|
61e6f0 |
# Needs to first put all arguments into a list, because invoking a different
|
|
|
61e6f0 |
# macro (%py_dist_name) overwrites them
|
|
|
61e6f0 |
%py2_dist() %{lua:\
|
|
|
61e6f0 |
args = {}\
|
|
|
61e6f0 |
arg = 1\
|
|
|
61e6f0 |
while (true) do\
|
|
|
61e6f0 |
name = rpm.expand("%{?" .. arg .. ":%{" .. arg .. "}}");\
|
|
|
61e6f0 |
if (name == nil or name == '') then\
|
|
|
61e6f0 |
break\
|
|
|
61e6f0 |
end\
|
|
|
61e6f0 |
args[arg] = name\
|
|
|
61e6f0 |
arg = arg + 1\
|
|
|
61e6f0 |
end\
|
|
|
61e6f0 |
for arg, name in ipairs(args) do\
|
|
|
61e6f0 |
canonical = rpm.expand("%py_dist_name " .. name);\
|
|
|
61e6f0 |
print("python2dist(" .. canonical .. ") ");\
|
|
|
61e6f0 |
end\
|
|
|
61e6f0 |
}
|
|
|
61e6f0 |
|
|
|
9e4ce9 |
# RHEL 9+ and Fedora compatibility macro
|
|
|
9e4ce9 |
# Only use in macro backports, not intended to be used in spec files!
|
|
|
9e4ce9 |
# In the future, the %%python3_pkgversion macro has a dot, e.g. 3.9 or 3.11
|
|
|
9e4ce9 |
# However, in RHEL 8 at least, it does not, e.g. 38, 39
|
|
|
9e4ce9 |
# This is a helpful macro that determines the proper "Python version" string with dot
|
|
|
9e4ce9 |
# from %%python3_pkgversion without actually having Python installed.
|
|
|
9e4ce9 |
# For values other than 3X, it should expand to %%python3_pkgversion unchanged.
|
|
|
9e4ce9 |
# Examples of %%python3_pkgversion -> %%_python3_pkgversion_with_dot:
|
|
|
9e4ce9 |
# 3 -> 3
|
|
|
9e4ce9 |
# 38 -> 3.8
|
|
|
9e4ce9 |
# 39 -> 3.9
|
|
|
9e4ce9 |
# 310 -> 3.10
|
|
|
9e4ce9 |
# 3.12 -> 3.12
|
|
|
9e4ce9 |
# 4 -> 4
|
|
|
9e4ce9 |
# 412 -> 412
|
|
|
9e4ce9 |
%_python3_pkgversion_with_dot %{lua:print((rpm.expand("%python3_pkgversion"):gsub('^3(%d)', '3.%1')))}
|
|
|
9e4ce9 |
|
|
|
61e6f0 |
# Creates Python 3 dist tag(s) after converting names to canonical format
|
|
|
61e6f0 |
# Needs to first put all arguments into a list, because invoking a different
|
|
|
61e6f0 |
# macro (%py_dist_name) overwrites them
|
|
|
61e6f0 |
%py3_dist() %{lua:\
|
|
|
9e4ce9 |
python3_pkgversion_with_dot = rpm.expand("%_python3_pkgversion_with_dot")\
|
|
|
61e6f0 |
args = {}\
|
|
|
61e6f0 |
arg = 1\
|
|
|
61e6f0 |
while (true) do\
|
|
|
61e6f0 |
name = rpm.expand("%{?" .. arg .. ":%{" .. arg .. "}}");\
|
|
|
61e6f0 |
if (name == nil or name == '') then\
|
|
|
61e6f0 |
break\
|
|
|
61e6f0 |
end\
|
|
|
61e6f0 |
args[arg] = name\
|
|
|
61e6f0 |
arg = arg + 1\
|
|
|
61e6f0 |
end\
|
|
|
61e6f0 |
for arg, name in ipairs(args) do\
|
|
|
61e6f0 |
canonical = rpm.expand("%py_dist_name " .. name);\
|
|
|
9e4ce9 |
print("python" .. python3_pkgversion_with_dot .. "dist(" .. canonical .. ") ");\
|
|
|
61e6f0 |
end\
|
|
|
61e6f0 |
}
|
|
|
61e6f0 |
|
|
|
61e6f0 |
# Macro to replace overly complicated references to PyPI source files.
|
|
|
61e6f0 |
# Expands to the pythonhosted URL for a package
|
|
|
61e6f0 |
# Accepts zero to three arguments:
|
|
|
61e6f0 |
# 1: The PyPI project name, defaulting to %srcname if it is defined, then
|
|
|
61e6f0 |
# %pypi_name if it is defined, then just %name.
|
|
|
39158c |
# 2: The PYPI version, defaulting to %version with tildes stripped.
|
|
|
61e6f0 |
# 3: The file extension, defaulting to "tar.gz". (A period will be added
|
|
|
61e6f0 |
# automatically.)
|
|
|
61e6f0 |
# Requires %__pypi_url and %__pypi_default_extension to be defined.
|
|
|
61e6f0 |
%__pypi_url https://files.pythonhosted.org/packages/source/
|
|
|
61e6f0 |
%__pypi_default_extension tar.gz
|
|
|
61e6f0 |
|
|
|
61e6f0 |
%pypi_source() %{lua:
|
|
|
61e6f0 |
local src = rpm.expand('%1')
|
|
|
61e6f0 |
local ver = rpm.expand('%2')
|
|
|
61e6f0 |
local ext = rpm.expand('%3')
|
|
|
61e6f0 |
local url = rpm.expand('%__pypi_url')
|
|
|
61e6f0 |
\
|
|
|
61e6f0 |
-- If no first argument, try %srcname, then %pypi_name, then %name
|
|
|
61e6f0 |
-- Note that rpm leaves macros unchanged if they are not defined.
|
|
|
61e6f0 |
if src == '%1' then
|
|
|
61e6f0 |
src = rpm.expand('%srcname')
|
|
|
61e6f0 |
end
|
|
|
61e6f0 |
if src == '%srcname' then
|
|
|
61e6f0 |
src = rpm.expand('%pypi_name')
|
|
|
61e6f0 |
end
|
|
|
61e6f0 |
if src == '%pypi_name' then
|
|
|
61e6f0 |
src = rpm.expand('%name')
|
|
|
61e6f0 |
end
|
|
|
61e6f0 |
\
|
|
|
61e6f0 |
-- If no second argument, use %version
|
|
|
61e6f0 |
if ver == '%2' then
|
|
|
39158c |
ver = rpm.expand('%version'):gsub('~', '')
|
|
|
61e6f0 |
end
|
|
|
61e6f0 |
\
|
|
|
61e6f0 |
-- If no third argument, use the preset default extension
|
|
|
61e6f0 |
if ext == '%3' then
|
|
|
61e6f0 |
ext = rpm.expand('%__pypi_default_extension')
|
|
|
61e6f0 |
end
|
|
|
61e6f0 |
\
|
|
|
61e6f0 |
local first = string.sub(src, 1, 1)
|
|
|
61e6f0 |
\
|
|
|
61e6f0 |
print(url .. first .. '/' .. src .. '/' .. src .. '-' .. ver .. '.' .. ext)
|
|
|
61e6f0 |
}
|
|
|
86545d |
|
|
|
86545d |
# Python packages in RHEL 8 should not provide unversioned python- names
|
|
|
86545d |
# so this macro here is just a compatibility layer and only provides the given name.
|
|
|
86545d |
%py_provides() %{lua:
|
|
|
86545d |
local name = rpm.expand('%1')
|
|
|
86545d |
if name == '%1' then
|
|
|
86545d |
rpm.expand('%{error:%%py_provides requires at least 1 argument, the name to provide}')
|
|
|
86545d |
end
|
|
|
86545d |
local evr = rpm.expand('%2')
|
|
|
86545d |
if evr == '%2' then
|
|
|
86545d |
evr = rpm.expand('%{?epoch:%{epoch}:}%{version}-%{release}')
|
|
|
86545d |
end
|
|
|
86545d |
print('Provides: ' .. name .. ' = ' .. evr .. '\\n')
|
|
|
86545d |
}
|