Blame SOURCES/macros.python-srpm

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