From 37a004eed88a71503a497bdfda6e830ffec2e353 Mon Sep 17 00:00:00 2001 From: Jason Tibbitts Date: Jun 18 2018 17:54:12 +0000 Subject: Add %pypi_source macro. Adds the %pypi_source macro, as well as %__pypi_url and %__pypi_default_extension. This should make references to sources in PyPI much simpler for nearly all Python packages. --- diff --git a/macros.python-srpm b/macros.python-srpm index 397b4fa..c4bdd1c 100644 --- a/macros.python-srpm +++ b/macros.python-srpm @@ -61,3 +61,47 @@ end\ } +# Macro to replace overly complicated references to PyPI source files. +# Expands to the pythonhosted URL for a package +# Accepts zero to three arguments: +# 1: The PyPI project name, defaulting to %srcname if it is defined, then +# %pypi_name if it is defined, then just %name. +# 2: The PYPI version, defaulting to %version. +# 3: The file extension, defaulting to "tar.gz". (A period will be added +# automatically.) +# Requires %__pypi_url and %__pypi_default_extension to be defined. +%__pypi_url https://files.pythonhosted.org/packages/source/ +%__pypi_default_extension tar.gz + +%pypi_source() %{lua: + local src = rpm.expand('%1') + local ver = rpm.expand('%2') + local ext = rpm.expand('%3') + local url = rpm.expand('%__pypi_url') +\ + -- If no first argument, try %srcname, then %pypi_name, then %name + -- Note that rpm leaves macros unchanged if they are not defined. + if src == '%1' then + src = rpm.expand('%srcname') + end + if src == '%srcname' then + src = rpm.expand('%pypi_name') + end + if src == '%pypi_name' then + src = rpm.expand('%name') + end +\ + -- If no second argument, use %version + if ver == '%2' then + ver = rpm.expand('%version') + end +\ + -- If no third argument, use the preset default extension + if ext == '%3' then + ext = rpm.expand('%__pypi_default_extension') + end +\ + local first = string.sub(src, 1, 1) +\ + print(url .. first .. '/' .. src .. '/' .. src .. '-' .. ver .. '.' .. ext) +} diff --git a/python-rpm-macros.spec b/python-rpm-macros.spec index 8115155..fb4e8d3 100644 --- a/python-rpm-macros.spec +++ b/python-rpm-macros.spec @@ -1,6 +1,6 @@ Name: python-rpm-macros Version: 3 -Release: 29%{?dist} +Release: 30%{?dist} Summary: The unversioned Python RPM macros License: MIT @@ -71,6 +71,10 @@ install -m 644 %{SOURCE0} %{SOURCE1} %{SOURCE2} %{SOURCE3} %{SOURCE4} \ %changelog +* Mon Jun 18 2018 Jason L Tibbitts III - 3-30 +- Add %%pypi_source macro, as well as %%__pypi_url and + %%_pypi_default_extension. + * Wed Apr 18 2018 Miro HronĨok - 3-29 - move macros.pybytecompile from python3-devel