From 86a7ec8de5a6de252986e63c8268cb394cb493f5 Mon Sep 17 00:00:00 2001 From: Orion Poplawski Date: Thu, 14 Jan 2016 14:32:55 -0700 Subject: [PATCH 1/9] EPEL version --- macros.python-srpm | 7 ++++++- python-rpm-macros.spec | 11 ++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/macros.python-srpm b/macros.python-srpm index 4257beb..b515582 100644 --- a/macros.python-srpm +++ b/macros.python-srpm @@ -1,3 +1,8 @@ # python3_pkgversion specifies the version of Python 3 in the distro. It can be # a specific version (e.g. 34 in Fedora EPEL7) -%python3_pkgversion 3 +%python3_pkgversion 34 +#python3_other_pkgversion 35 +# Set to /bin/true when not active to avoid %ifdefs in specfiles +%__python3_other /bin/true +%py3_other_build /bin/true +%py3_other_install /bin/true diff --git a/python-rpm-macros.spec b/python-rpm-macros.spec index d71e19c..52a97a2 100644 --- a/python-rpm-macros.spec +++ b/python-rpm-macros.spec @@ -1,6 +1,6 @@ Name: python-rpm-macros Version: 3 -Release: 4%{?dist} +Release: 4%{?dist}.1 Summary: The unversioned Python RPM macros License: MIT @@ -10,8 +10,6 @@ Source2: macros.python2 Source3: macros.python3 BuildArch: noarch -Obsoletes: python-macros < 3 -Provides: python-macros = %{version}-%{release} %description This package contains the unversioned Python RPM macros, that most @@ -28,16 +26,12 @@ RPM macros for building Python source packages. %package -n python2-rpm-macros Summary: RPM macros for building Python 2 packages -# Would need to be different for each release - worth it? -#Conflicts: python2-devel < 2.7.11-3 %description -n python2-rpm-macros RPM macros for building Python 2 packages. %package -n python3-rpm-macros Summary: RPM macros for building Python 3 packages -# Would need to be different for each release - worth it? -#Conflicts: python3-devel < 3.5.1-3 %description -n python3-rpm-macros RPM macros for building Python 3 packages. @@ -67,6 +61,9 @@ install -m 644 %{SOURCE0} %{SOURCE1} %{SOURCE2} %{SOURCE3} \ %changelog +* Thu Jan 14 2016 Orion Poplawski 3-4.1 +- EPEL version + * Wed Jan 13 2016 Orion Poplawski 3-4 - Fix python2/3-rpm-macros package names From 237061d265a11c86275ecae37d4c0117820ed79c Mon Sep 17 00:00:00 2001 From: Orion Poplawski Date: Thu, 14 Jan 2016 14:46:42 -0700 Subject: [PATCH 2/9] Handle python3_other_pkgversion in python_provide; Drop duplicate py3_other macros from macros.python --- macros.python | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/macros.python b/macros.python index 4a5cb2a..a4c2fc8 100644 --- a/macros.python +++ b/macros.python @@ -29,8 +29,10 @@ CFLAGS="%{optflags}" %{__python} %{py_setup} %{?py_setup_args} install -O1 --ski print(string.sub(package,9,string.len(package)));\ print(" < ");\ print(vr);\ - elseif (string.starts(package, "python3-")) then\ + elseif (string.starts(str, "python" .. rpm.expand("%{python3_pkgversion}") .. "-")) then\ --No unversioned provides as python3 is not default\ + elseif (rpm.expand("%{?python3_other_pkgversion}") != "" and string.starts(str, "python" .. rpm.expand("%{python3_other_pkgversion}") .. "-")) then\ + --No unversioned provides as python3_other is not default\ elseif (string.starts(package, "pypy-")) then\ --No unversioned provides as pypy is not default\ elseif (string.starts(package, "pypy3-")) then\ @@ -47,8 +49,3 @@ CFLAGS="%{optflags}" %{__python} %{py_setup} %{?py_setup_args} install -O1 --ski print("not recognized.");\ end\ } - -# Set to /bin/true to avoid %ifdefs in specfiles -%__python3_other /bin/true -%py3_other_build /bin/true -%py3_other_install /bin/true From cc0b15603c86a16c2727a7a19bf8b93442ac046d Mon Sep 17 00:00:00 2001 From: Orion Poplawski Date: Mon, 25 Jan 2016 16:55:23 -0700 Subject: [PATCH 3/9] Set %__python3 to /usr/bin/python3.4 --- macros.python3 | 4 +++- python-rpm-macros.spec | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/macros.python3 b/macros.python3 index a633c72..7f00724 100644 --- a/macros.python3 +++ b/macros.python3 @@ -1,4 +1,6 @@ -%__python3 /usr/bin/python3 +%__python3 /usr/bin/python3.4 +#__python3_other /usr/bin/python3.5 + %python3_sitelib %(%{__python3} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") %python3_sitearch %(%{__python3} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))") %python3_version %(%{__python3} -c "import sys; sys.stdout.write(sys.version[:3])") diff --git a/python-rpm-macros.spec b/python-rpm-macros.spec index b703fcb..b720e8d 100644 --- a/python-rpm-macros.spec +++ b/python-rpm-macros.spec @@ -1,6 +1,6 @@ Name: python-rpm-macros Version: 3 -Release: 6%{?dist} +Release: 6%{?dist}.1 Summary: The unversioned Python RPM macros License: MIT @@ -61,6 +61,9 @@ install -m 644 %{SOURCE0} %{SOURCE1} %{SOURCE2} %{SOURCE3} \ %changelog +* Mon Jan 25 2016 Orion Poplawski 3-6.1 +- Set %%__python3 to /usr/bin/python3.4 + * Thu Jan 14 2016 Orion Poplawski 3-6 - Fix typo in %%python_provide From 83441663a4ad710ec9c07d90743944ccee31b684 Mon Sep 17 00:00:00 2001 From: Jason Tibbitts Date: Thu, 15 Sep 2016 15:40:12 -0500 Subject: [PATCH 4/9] Fix up issue with python2_version* macros Also move the macros to the proper location (%rpmmacrodir) and copy over one fix from the macros that were in epel-rpm-macros. --- macros.python2 | 6 +++--- python-rpm-macros.spec | 22 +++++++++++++++------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/macros.python2 b/macros.python2 index 789ca09..66e9c5a 100644 --- a/macros.python2 +++ b/macros.python2 @@ -1,8 +1,8 @@ -%__python2 /usr/bin/python2 +%__python2 /usr/bin/python2.6 %python2_sitelib %(%{__python2} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") %python2_sitearch %(%{__python2} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))") -%python2_version %(%{__python2} -c "import sys; sys.stdout.write('{0.major}.{0.minor}'.format(sys.version_info))") -%python2_version_nodots %(%{__python2} -c "import sys; sys.stdout.write('{0.major}{0.minor}'.format(sys.version_info))") +%python2_version %(%{__python2} -c "import sys; sys.stdout.write(sys.version[:3])") +%python2_version_nodots %(%{__python2} -c "import sys; sys.stdout.write(sys.version[:3:2])") %py2_shbang_opts -s diff --git a/python-rpm-macros.spec b/python-rpm-macros.spec index 51b5e40..f2c2bff 100644 --- a/python-rpm-macros.spec +++ b/python-rpm-macros.spec @@ -1,6 +1,6 @@ Name: python-rpm-macros Version: 3 -Release: 10%{?dist} +Release: 11%{?dist} Summary: The unversioned Python RPM macros License: MIT @@ -44,25 +44,33 @@ RPM macros for building Python 3 packages. %build %install -mkdir -p %{buildroot}/%{_rpmconfigdir}/macros.d/ +mkdir -p %{buildroot}/%{rpmmacrodir} install -m 644 %{SOURCE0} %{SOURCE1} %{SOURCE2} %{SOURCE3} \ - %{buildroot}/%{_rpmconfigdir}/macros.d/ + %{buildroot}/%{rpmmacrodir} %files -%{_rpmconfigdir}/macros.d/macros.python +%{rpmmacrodir}/macros.python %files -n python-srpm-macros -%{_rpmconfigdir}/macros.d/macros.python-srpm +%{rpmmacrodir}/macros.python-srpm %files -n python2-rpm-macros -%{_rpmconfigdir}/macros.d/macros.python2 +%{rpmmacrodir}/macros.python2 %files -n python3-rpm-macros -%{_rpmconfigdir}/macros.d/macros.python3 +%{rpmmacrodir}/macros.python3 %changelog +* Thu Sep 15 2016 Jason L Tibbitts III - 3-11 +- Use %%rpmmacrodir to put the macros in the proper location. +- Change %%python2_version* to a form that works on EL6. +- Change %%__python2 to point explicitly to python2.6 to avoid breakage in + Amazon Linux, which links /usr/bin/python to python2.7. This syncs up with + the macros which were in epel-rpm-macros. See + https://bugzilla.redhat.com/show_bug.cgi?id=1347019 + * Tue Jul 12 2016 Orion Poplawski 3-10 - Do not generate useless Obsoletes with %%{?_isa} From 133ccf712356b3645831d61aa66a3d7476948841 Mon Sep 17 00:00:00 2001 From: Jason Tibbitts Date: Mon, 18 Jun 2018 18:38:44 -0500 Subject: [PATCH 5/9] Add %pypi_source macro. --- macros.python-srpm | 45 ++++++++++++++++++++++++++++++++++++++++++ python-rpm-macros.spec | 5 ++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/macros.python-srpm b/macros.python-srpm index 274e1c8..82a14ed 100644 --- a/macros.python-srpm +++ b/macros.python-srpm @@ -7,3 +7,48 @@ %__python3_other /bin/true %py3_other_build /bin/true %py3_other_install /bin/true + +# 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 f2c2bff..ee9a965 100644 --- a/python-rpm-macros.spec +++ b/python-rpm-macros.spec @@ -1,6 +1,6 @@ Name: python-rpm-macros Version: 3 -Release: 11%{?dist} +Release: 12%{?dist} Summary: The unversioned Python RPM macros License: MIT @@ -63,6 +63,9 @@ install -m 644 %{SOURCE0} %{SOURCE1} %{SOURCE2} %{SOURCE3} \ %changelog +* Mon Jun 18 2018 Jason L Tibbitts III - 3-12 +- Add %%pypi_source macro. + * Thu Sep 15 2016 Jason L Tibbitts III - 3-11 - Use %%rpmmacrodir to put the macros in the proper location. - Change %%python2_version* to a form that works on EL6. From 5e1687a64cdd279cf27a6d981fba5936a84d9994 Mon Sep 17 00:00:00 2001 From: Jason Tibbitts Date: Mon, 9 Jul 2018 14:34:36 -0500 Subject: [PATCH 6/9] Backport %python3_platform macro. --- macros.python3 | 1 + python-rpm-macros.spec | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/macros.python3 b/macros.python3 index 2ef1fe7..7226ccc 100644 --- a/macros.python3 +++ b/macros.python3 @@ -5,6 +5,7 @@ %python3_sitearch %(%{__python3} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))") %python3_version %(%{__python3} -c "import sys; sys.stdout.write(sys.version[:3])") %python3_version_nodots %(%{__python3} -c "import sys; sys.stdout.write(sys.version[:3].replace('.',''))") +%python3_platform %(%{__python3} -Ic "import sysconfig; print(sysconfig.get_platform())") %py3dir %{_builddir}/python3-%{name}-%{version}-%{release} %py3_shbang_opts -s diff --git a/python-rpm-macros.spec b/python-rpm-macros.spec index ee9a965..bef8854 100644 --- a/python-rpm-macros.spec +++ b/python-rpm-macros.spec @@ -1,6 +1,6 @@ Name: python-rpm-macros Version: 3 -Release: 12%{?dist} +Release: 13%{?dist} Summary: The unversioned Python RPM macros License: MIT @@ -63,6 +63,9 @@ install -m 644 %{SOURCE0} %{SOURCE1} %{SOURCE2} %{SOURCE3} \ %changelog +* Mon Jul 09 2018 Jason L Tibbitts III - 3-13 +- Backport %%python3_platform macro. + * Mon Jun 18 2018 Jason L Tibbitts III - 3-12 - Add %%pypi_source macro. From 0fa5a2d81130bd5428f91d766a172192c808a3c8 Mon Sep 17 00:00:00 2001 From: Carl George Date: Wed, 6 Mar 2019 08:11:49 -0600 Subject: [PATCH 7/9] Move macros.pybytecompile in here from python3X-devel Backporting to el6 branch from #10 (epel7). --- macros.pybytecompile | 27 +++++++++++++++++++++++++++ python-rpm-macros.spec | 11 +++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 macros.pybytecompile diff --git a/macros.pybytecompile b/macros.pybytecompile new file mode 100644 index 0000000..f5439cf --- /dev/null +++ b/macros.pybytecompile @@ -0,0 +1,27 @@ +# Note that the path could itself be a python file, or a directory + +# Python's compile_all module only works on directories, and requires a max +# recursion depth + +# Note that the py_byte_compile macro should work for all Python versions +# Which unfortunately makes the definition more complicated than it should be + +%py_byte_compile()\ +py2_byte_compile () {\ + python_binary="%1"\ + bytecode_compilation_path="%2"\ + find $bytecode_compilation_path -type f -a -name "*.py" -print0 | xargs -0 $python_binary -c 'import py_compile, sys; [py_compile.compile(f, dfile=f.partition("$RPM_BUILD_ROOT")[2]) for f in sys.argv[1:]]' || :\ + find $bytecode_compilation_path -type f -a -name "*.py" -print0 | xargs -0 $python_binary -O -c 'import py_compile, sys; [py_compile.compile(f, dfile=f.partition("$RPM_BUILD_ROOT")[2]) for f in sys.argv[1:]]' || :\ +}\ +\ +py3_byte_compile () {\ + python_binary="%1"\ + bytecode_compilation_path="%2"\ + find $bytecode_compilation_path -type f -a -name "*.py" -print0 | xargs -0 $python_binary -O -c 'import py_compile, sys; [py_compile.compile(f, dfile=f.partition("$RPM_BUILD_ROOT")[2], optimize=opt) for opt in range(2) for f in sys.argv[1:]]' || :\ +}\ +\ +# Get version without a dot (36 instead of 3.6), bash doesn't compare floats well \ +python_version=$(%1 -c "import sys; sys.stdout.write('{0.major}{0.minor}'.format(sys.version_info))") \ +# The bytecompilation syntax has changed between Python 3.4 and Python 3.5, so for 3.4 and earlier we use the "Python 2" syntax \ +[ "$python_version" -ge 35 ] && py3_byte_compile "%1" "%2" || py2_byte_compile "%1" "%2" \ +%{nil} diff --git a/python-rpm-macros.spec b/python-rpm-macros.spec index bef8854..c4ad781 100644 --- a/python-rpm-macros.spec +++ b/python-rpm-macros.spec @@ -1,6 +1,6 @@ Name: python-rpm-macros Version: 3 -Release: 13%{?dist} +Release: 14%{?dist} Summary: The unversioned Python RPM macros License: MIT @@ -8,6 +8,7 @@ Source0: macros.python Source1: macros.python-srpm Source2: macros.python2 Source3: macros.python3 +Source5: macros.pybytecompile BuildArch: noarch # For %%python3_pkgversion used in %%python_provide @@ -45,12 +46,13 @@ RPM macros for building Python 3 packages. %install mkdir -p %{buildroot}/%{rpmmacrodir} -install -m 644 %{SOURCE0} %{SOURCE1} %{SOURCE2} %{SOURCE3} \ +install -m 644 %{SOURCE0} %{SOURCE1} %{SOURCE2} %{SOURCE3} %{SOURCE5} \ %{buildroot}/%{rpmmacrodir} %files %{rpmmacrodir}/macros.python +%{rpmmacrodir}/macros.pybytecompile %files -n python-srpm-macros %{rpmmacrodir}/macros.python-srpm @@ -63,6 +65,11 @@ install -m 644 %{SOURCE0} %{SOURCE1} %{SOURCE2} %{SOURCE3} \ %changelog +* Wed Mar 06 2019 Carl George - 3-14 +- Move macros.pybytecompile in here from python3X-devel +- macros.pybytecompile: Detect Python version through sys.version_info instead + of guessing from the executable name + * Mon Jul 09 2018 Jason L Tibbitts III - 3-13 - Backport %%python3_platform macro. From dee3401a7efa5f30143526e56e222d7fdcaedac3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Mon, 30 Sep 2019 14:35:43 +0200 Subject: [PATCH 8/9] Define %python2 and %python3 See https://pagure.io/packaging-committee/issue/907 Redefine %__pythonX to change the behavior of %pythonX, %pythonX_version, etc. Use %pythonX in spec. --- macros.python2 | 5 +++++ macros.python3 | 6 ++++++ python-rpm-macros.spec | 5 ++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/macros.python2 b/macros.python2 index 66e9c5a..0a75d76 100644 --- a/macros.python2 +++ b/macros.python2 @@ -1,4 +1,9 @@ +# use the underscored macros to redefine the behavior of %%python2_version etc. %__python2 /usr/bin/python2.6 + +# use the non-underscored macros to refer to Python in spec, etc. +%python2 %__python2 + %python2_sitelib %(%{__python2} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") %python2_sitearch %(%{__python2} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))") %python2_version %(%{__python2} -c "import sys; sys.stdout.write(sys.version[:3])") diff --git a/macros.python3 b/macros.python3 index 7226ccc..41345e3 100644 --- a/macros.python3 +++ b/macros.python3 @@ -1,5 +1,11 @@ +# use the underscored macros to redefine the behavior of %%python3_version etc. %__python3 /usr/bin/python3.4 + +# use the non-underscored macros to refer to Python in spec, etc. +%python3 %__python3 + #__python3_other /usr/bin/python3.5 +#python3_other %%__python3_other %python3_sitelib %(%{__python3} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") %python3_sitearch %(%{__python3} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))") diff --git a/python-rpm-macros.spec b/python-rpm-macros.spec index c4ad781..0f73e16 100644 --- a/python-rpm-macros.spec +++ b/python-rpm-macros.spec @@ -1,6 +1,6 @@ Name: python-rpm-macros Version: 3 -Release: 14%{?dist} +Release: 15%{?dist} Summary: The unversioned Python RPM macros License: MIT @@ -65,6 +65,9 @@ install -m 644 %{SOURCE0} %{SOURCE1} %{SOURCE2} %{SOURCE3} %{SOURCE5} \ %changelog +* Fri Sep 27 2019 Miro Hrončok - 3-15 +- Define %%python2 and %%python3 + * Wed Mar 06 2019 Carl George - 3-14 - Move macros.pybytecompile in here from python3X-devel - macros.pybytecompile: Detect Python version through sys.version_info instead From d4418433fa1c204527a3a49db11f89ac9f6ab657 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Wed, 2 Oct 2019 16:20:57 +0200 Subject: [PATCH 9/9] Drop hardcoded python2 from %py_build --- macros.python | 2 +- python-rpm-macros.spec | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/macros.python b/macros.python index 94e769c..2153629 100644 --- a/macros.python +++ b/macros.python @@ -2,7 +2,7 @@ %py_shbang_opts -s %py_build() %{expand:\ -CFLAGS="%{optflags}" %{__python} %{py_setup} %{?py_setup_args} build --executable="%{__python2} %{py_shbang_opts}" %{?1}\ +CFLAGS="%{optflags}" %{__python} %{py_setup} %{?py_setup_args} build --executable="%{__python} %{py_shbang_opts}" %{?1}\ } %py_install() %{expand:\ diff --git a/python-rpm-macros.spec b/python-rpm-macros.spec index 0f73e16..0d33824 100644 --- a/python-rpm-macros.spec +++ b/python-rpm-macros.spec @@ -67,6 +67,7 @@ install -m 644 %{SOURCE0} %{SOURCE1} %{SOURCE2} %{SOURCE3} %{SOURCE5} \ %changelog * Fri Sep 27 2019 Miro Hrončok - 3-15 - Define %%python2 and %%python3 +- Drop hardcoded python2 from %%py_build * Wed Mar 06 2019 Carl George - 3-14 - Move macros.pybytecompile in here from python3X-devel