diff --git a/SOURCES/macros.pybytecompile b/SOURCES/macros.pybytecompile index f3199792..d06071e6 100644 --- a/SOURCES/macros.pybytecompile +++ b/SOURCES/macros.pybytecompile @@ -3,23 +3,22 @@ # 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 python2 as well -# Which unfortunately makes the definition more complicated than it should be -# The condition should be reversed once /usr/bin/python is python3! +# Usage: +# %py_byte_compile +# Example: +# %py_byte_compile %{__python3} %{buildroot}%{_datadir}/spam/plugins/ + +# This will terminate build on SyntaxErrors, if you want to avoid that, +# use it in a subshell like this: +# (%{py_byte_compile }) || : %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:]]' || :\ -}\ -\ -[[ "%1" == *python3* ]] || py2_byte_compile "%1" "%2" && py3_byte_compile "%1" "%2" \ -%{nil} +python_binary="%1"\ +buildroot_path="%2"\ +bytecode_compilation_path=".${buildroot_path/#$RPM_BUILD_ROOT}"\ +failure=0\ +pushd $RPM_BUILD_ROOT\ +find $bytecode_compilation_path -type f -a -name "*.py" -print0 | xargs -0 $python_binary -O -m py_compile || failure=1\ +find $bytecode_compilation_path -type f -a -name "*.py" -print0 | xargs -0 $python_binary -m py_compile || failure=1\ +popd\ +test $failure -eq 0 diff --git a/SOURCES/macros.python b/SOURCES/macros.python index 8b168b5d..7d019c4e 100644 --- a/SOURCES/macros.python +++ b/SOURCES/macros.python @@ -4,7 +4,7 @@ # Use the slashes after expand so that the command starts on the same line as # the macro %py_build() %{expand:\\\ - CFLAGS="%{optflags}" %{__python} %{py_setup} %{?py_setup_args} build --executable="%{__python2} %{py_shbang_opts}" %{?*} + CFLAGS="%{optflags}" %{__python} %{py_setup} %{?py_setup_args} build --executable="%{__python} %{py_shbang_opts}" %{?*} sleep 1 } @@ -51,8 +51,29 @@ print(string.sub(package,9,string.len(package))) print(" < ") print(vr) - elseif (string.starts(package, "python" .. rpm.expand("%{python3_pkgversion}") .. "-")) then - --No unversioned provides as python3 is not default + elseif (string.starts(package, "python3-")) then + if (rpm.expand("%{?buildarch}") ~= "noarch") then + str = "Provides: python36-" .. string.sub(package,9,string.len(package)) .. "%{?_isa} = " .. vr + print(rpm.expand(str)) + end + print("\\nProvides: python36-") + print(string.sub(package,9,string.len(package))) + print(" = ") + print(vr) + --Obsoleting the EPEL python36 package + print("\\nObsoletes: python36-") + print(string.sub(package,9,string.len(package))) + print(" < ") + print(vr) + elseif (string.starts(package, "python36-")) then + if (rpm.expand("%{?buildarch}") ~= "noarch") then + str = "Provides: python3-" .. string.sub(package,10,string.len(package)) .. "%{?_isa} = " .. vr + print(rpm.expand(str)) + end + print("\\nProvides: python3-") + print(string.sub(package,10,string.len(package))) + print(" = ") + print(vr) elseif (rpm.expand("%{?python3_other_pkgversion}") ~= "" and string.starts(package, "python" .. rpm.expand("%{python3_other_pkgversion}") .. "-")) then --No unversioned provides as python3_other is not default elseif (string.starts(package, "pypy-")) then diff --git a/SOURCES/macros.python-srpm b/SOURCES/macros.python-srpm index 397b4fae..0c431e42 100644 --- a/SOURCES/macros.python-srpm +++ b/SOURCES/macros.python-srpm @@ -57,7 +57,52 @@ end\ for arg, name in ipairs(args) do\ canonical = rpm.expand("%py_dist_name " .. name);\ - print("python3dist(" .. canonical .. ") ");\ + python3_version = rpm.expand("%python3_version");\ + print("python" .. python3_version .. "dist(" .. canonical .. ") ");\ 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/SOURCES/macros.python3 b/SOURCES/macros.python3 index 79c33f18..25c6f62d 100644 --- a/SOURCES/macros.python3 +++ b/SOURCES/macros.python3 @@ -3,6 +3,7 @@ %python3_sitearch %(%{__python3} -Ic "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))") %python3_version %(%{__python3} -Ic "import sys; sys.stdout.write(sys.version[:3])") %python3_version_nodots %(%{__python3} -Ic "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/SPECS/python-rpm-macros.spec b/SPECS/python-rpm-macros.spec index 0f6f0faa..a2bc64d9 100644 --- a/SPECS/python-rpm-macros.spec +++ b/SPECS/python-rpm-macros.spec @@ -1,42 +1,49 @@ +%global rpmmacrodir %{_sysconfdir}/rpm + Name: python-rpm-macros Version: 3 -Release: 29%{?dist} +Release: 34%{?dist} Summary: The unversioned Python RPM macros + License: MIT Source0: macros.python Source1: macros.python-srpm Source2: macros.python2 Source3: macros.python3 Source4: macros.pybytecompile + BuildArch: noarch +# The macro file has been moved from the python-devel package +Conflicts: python-devel < 2.7.5-78 # For %%python3_pkgversion used in %%python_provide Requires: python-srpm-macros -Obsoletes: python-macros < 3 -Provides: python-macros = %{version}-%{release} - %description This package contains the unversioned Python RPM macros, that most implementations should rely on. + You should not need to install this package manually as the various python?-devel packages require it. So install a python-devel package instead. %package -n python-srpm-macros Summary: RPM macros for building Python source packages + %description -n python-srpm-macros 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 python2-rpm-macros +Summary: RPM macros for building Python 2 packages +# The macro file has been moved from the python-devel package +Conflicts: python-devel < 2.7.5-78 + +%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. @@ -46,36 +53,58 @@ RPM macros for building Python 3 packages. %build %install -mkdir -p %{buildroot}//usr/lib/rpm/macros.d/ -install -m 644 \ -%{SOURCE1} \ -%{SOURCE3} \ -%{SOURCE4} \ -%{buildroot}/usr/lib/rpm/macros.d/ +mkdir -p %{buildroot}/%{_sysconfdir}/rpm +mkdir -p %{buildroot}/%{rpmmacrodir} +install -m 644 %{SOURCE0} %{SOURCE1} %{SOURCE2} %{SOURCE3} %{SOURCE4} \ + %{buildroot}/%{_sysconfdir}/rpm/ %files -#/usr/lib/rpm/macros.d//macros.python -/usr/lib/rpm/macros.d//macros.pybytecompile +%{rpmmacrodir}/macros.python +%{rpmmacrodir}/macros.pybytecompile %files -n python-srpm-macros -/usr/lib/rpm/macros.d//macros.python-srpm +%{rpmmacrodir}/macros.python-srpm -#%files -n python2-rpm-macros -#/usr/lib/rpm/macros.d//macros.python2 +%files -n python2-rpm-macros +%{rpmmacrodir}/macros.python2 %files -n python3-rpm-macros -/usr/lib/rpm/macros.d//macros.python3 +%{rpmmacrodir}/macros.python3 %changelog -* Wed Apr 18 2018 Miro Hrončok - 3-29 -- move macros.pybytecompile from python3-devel +* Tue Mar 17 2020 Miro Hrončok - 3-34 +- Make the %%py3_dist macro compatible with Python RPM generators +Resolves: rhbz#1812665 + +* Wed Mar 04 2020 Charalampos Stratakis - 3-33 +- Fix the %%py_build macro to respect the global definition of %%__python +Resolves: rhbz#1757834 + +* Wed Apr 24 2019 Miro Hrončok - 3-32 +- %%python_provide: Obsolete and provide python36- from python3- +- %%python_provide: Provide python3- from python36- +Resolves: rhbz#1702719 + +* Mon Jan 14 2019 Lumír Balhar - 3-31 +- Converting specfile from F28 to RHEL7 +- Move the macros to the standard RHEL7 macro location at /etc/rpm/, + instead of Fedora's location at /usr/lib/rpm/macros.d/ +- Import the macros.python{,2} files from the python-devel package where they + resided until now, and Conflict with that old version of python-devel +- Import the macros.pybytecompile from Fedora rawhide / RHEL8 +Resolves: rhbz#1660579 + +* Mon Jul 09 2018 Jason L Tibbitts III - 3-30 +- Backport %%python3_platform macro. + +* Mon Jun 18 2018 Jason L Tibbitts III - 3-29 +- Add %%pypi_source macro. * Fri Apr 06 2018 Tomas Orsava - 3-28 - Fix the %%py_dist_name macro to not convert dots (".") into dashes, so that - submodules can be addressed as well -Resolves: rhbz#1564095 + submodules can be addressed as well Resolves: rhbz#1564095 * Fri Mar 23 2018 Miro Hrončok - 3-27 - make LDFLAGS propagated whenever CFLAGS are