Blame SOURCES/macros.python-srpm

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
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
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:\
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("python3dist(" .. 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
}