Blame SOURCES/macros.python-srpm

f245b7
# python3_pkgversion specifies the version of Python 3 in the distro.  It can be
f245b7
# a specific version (e.g. 34 in Fedora EPEL7)
f245b7
%python3_pkgversion 3
f245b7
f245b7
# Set to /bin/true to avoid %ifdefs and %{? in specfiles
f245b7
%__python3_other /bin/true
f245b7
%py3_other_build /bin/true
f245b7
%py3_other_install /bin/true
f245b7
f245b7
f245b7
f245b7
# === Macros for Build/Requires tags using Python dist tags ===
f245b7
# - https://fedoraproject.org/wiki/Changes/Automatic_Provides_for_Python_RPM_Packages
f245b7
# - These macros need to be in macros.python-srpm, because BuildRequires tags
f245b7
#   get rendered as runtime requires into the metadata of SRPMs.
f245b7
f245b7
# Converts Python dist name to a canonical format
f245b7
%py_dist_name() %{lua:\
f245b7
        name = rpm.expand("%{?1:%{1}}");\
f245b7
        canonical = string.gsub(string.lower(name), "[^%w%.]+", "-");\
f245b7
        print(canonical);\
f245b7
}
f245b7
f245b7
# Creates Python 2 dist tag(s) after converting names to canonical format
f245b7
#   Needs to first put all arguments into a list, because invoking a different
f245b7
#   macro (%py_dist_name) overwrites them
f245b7
%py2_dist() %{lua:\
f245b7
        args = {}\
f245b7
        arg = 1\
f245b7
        while (true) do\
f245b7
                name = rpm.expand("%{?" .. arg .. ":%{" .. arg .. "}}");\
f245b7
                if (name == nil or name == '') then\
f245b7
                        break\
f245b7
                end\
f245b7
                args[arg] = name\
f245b7
                arg = arg + 1\
f245b7
        end\
f245b7
        for arg, name in ipairs(args) do\
f245b7
                canonical = rpm.expand("%py_dist_name " .. name);\
f245b7
                print("python2dist(" .. canonical .. ") ");\
f245b7
        end\
f245b7
}
f245b7
f245b7
# Creates Python 3 dist tag(s) after converting names to canonical format
f245b7
#   Needs to first put all arguments into a list, because invoking a different
f245b7
#   macro (%py_dist_name) overwrites them
f245b7
%py3_dist() %{lua:\
f245b7
        args = {}\
f245b7
        arg = 1\
f245b7
        while (true) do\
f245b7
                name = rpm.expand("%{?" .. arg .. ":%{" .. arg .. "}}");\
f245b7
                if (name == nil or name == '') then\
f245b7
                        break\
f245b7
                end\
f245b7
                args[arg] = name\
f245b7
                arg = arg + 1\
f245b7
        end\
f245b7
        for arg, name in ipairs(args) do\
f245b7
                canonical = rpm.expand("%py_dist_name " .. name);\
4c5d06
                python3_version = rpm.expand("%python3_version");\
4c5d06
                print("python" .. python3_version .. "dist(" .. canonical .. ") ");\
f245b7
        end\
f245b7
}
f245b7
f245b7
# Macro to replace overly complicated references to PyPI source files.
f245b7
# Expands to the pythonhosted URL for a package
f245b7
# Accepts zero to three arguments:
f245b7
# 1:  The PyPI project name, defaulting to %srcname if it is defined, then
f245b7
#     %pypi_name if it is defined, then just %name.
f245b7
# 2:  The PYPI version, defaulting to %version.
f245b7
# 3:  The file extension, defaulting to "tar.gz".  (A period will be added
f245b7
#     automatically.)
f245b7
# Requires %__pypi_url and %__pypi_default_extension to be defined.
f245b7
%__pypi_url https://files.pythonhosted.org/packages/source/
f245b7
%__pypi_default_extension tar.gz
f245b7
f245b7
%pypi_source() %{lua:
f245b7
    local src = rpm.expand('%1')
f245b7
    local ver = rpm.expand('%2')
f245b7
    local ext = rpm.expand('%3')
f245b7
    local url = rpm.expand('%__pypi_url')
f245b7
\
f245b7
    -- If no first argument, try %srcname, then %pypi_name, then %name
f245b7
    -- Note that rpm leaves macros unchanged if they are not defined.
f245b7
    if src == '%1' then
f245b7
        src = rpm.expand('%srcname')
f245b7
    end
f245b7
    if src == '%srcname' then
f245b7
        src = rpm.expand('%pypi_name')
f245b7
    end
f245b7
    if src == '%pypi_name' then
f245b7
        src = rpm.expand('%name')
f245b7
    end
f245b7
\
f245b7
    -- If no second argument, use %version
f245b7
    if ver == '%2' then
f245b7
        ver = rpm.expand('%version')
f245b7
    end
f245b7
\
f245b7
    -- If no third argument, use the preset default extension
f245b7
    if ext == '%3' then
f245b7
        ext = rpm.expand('%__pypi_default_extension')
f245b7
    end
f245b7
\
f245b7
    local first = string.sub(src, 1, 1)
f245b7
\
f245b7
    print(url .. first .. '/' .. src .. '/' .. src .. '-' .. ver .. '.' .. ext)
f245b7
}