Blame SOURCES/macros.python-srpm

70a2d8
# Macro to replace overly complicated references to PyPI source files.
70a2d8
# Expands to the pythonhosted URL for a package
70a2d8
# Accepts zero to three arguments:
70a2d8
# 1:  The PyPI project name, defaulting to %srcname if it is defined, then
70a2d8
#     %pypi_name if it is defined, then just %name.
70a2d8
# 2:  The PYPI version, defaulting to %version.
70a2d8
# 3:  The file extension, defaulting to "tar.gz".  (A period will be added
70a2d8
#     automatically.)
70a2d8
# Requires %__pypi_url and %__pypi_default_extension to be defined.
70a2d8
%__pypi_url https://files.pythonhosted.org/packages/source/
70a2d8
%__pypi_default_extension tar.gz
70a2d8
70a2d8
%pypi_source() %{lua:
70a2d8
    local src = rpm.expand('%1')
70a2d8
    local ver = rpm.expand('%2')
70a2d8
    local ext = rpm.expand('%3')
70a2d8
    local url = rpm.expand('%__pypi_url')
70a2d8
\
70a2d8
    -- If no first argument, try %srcname, then %pypi_name, then %name
70a2d8
    -- Note that rpm leaves macros unchanged if they are not defined.
70a2d8
    if src == '%1' then
70a2d8
        src = rpm.expand('%srcname')
70a2d8
    end
70a2d8
    if src == '%srcname' then
70a2d8
        src = rpm.expand('%pypi_name')
70a2d8
    end
70a2d8
    if src == '%pypi_name' then
70a2d8
        src = rpm.expand('%name')
70a2d8
    end
70a2d8
\
70a2d8
    -- If no second argument, use %version
70a2d8
    if ver == '%2' then
70a2d8
        ver = rpm.expand('%version')
70a2d8
    end
70a2d8
\
70a2d8
    -- If no third argument, use the preset default extension
70a2d8
    if ext == '%3' then
70a2d8
        ext = rpm.expand('%__pypi_default_extension')
70a2d8
    end
70a2d8
\
70a2d8
    local first = string.sub(src, 1, 1)
70a2d8
\
70a2d8
    print(url .. first .. '/' .. src .. '/' .. src .. '-' .. ver .. '.' .. ext)
70a2d8
}