Blame SOURCES/macros.python-srpm

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