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/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/macros.python-srpm b/macros.python-srpm index 87ce887..82a14ed 100644 --- a/macros.python-srpm +++ b/macros.python-srpm @@ -1,8 +1,54 @@ # 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 to avoid %ifdefs and %{? in specfiles +# Set to /bin/true when not active to avoid %ifdefs and %{? in specfiles %__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/macros.python2 b/macros.python2 index 789ca09..0a75d76 100644 --- a/macros.python2 +++ b/macros.python2 @@ -1,8 +1,13 @@ -%__python2 /usr/bin/python2 +# 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('{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/macros.python3 b/macros.python3 index 4f44bd1..41345e3 100644 --- a/macros.python3 +++ b/macros.python3 @@ -1,8 +1,17 @@ -%__python3 /usr/bin/python3 +# 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))") %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 d63753d..0d33824 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: 15%{?dist} Summary: The unversioned Python RPM macros License: MIT @@ -8,12 +8,11 @@ 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 Requires: python-srpm-macros -Obsoletes: python-macros < 3 -Provides: python-macros = %{version}-%{release} %description This package contains the unversioned Python RPM macros, that most @@ -30,16 +29,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. @@ -50,25 +45,49 @@ RPM macros for building Python 3 packages. %build %install -mkdir -p %{buildroot}/%{_rpmconfigdir}/macros.d/ -install -m 644 %{SOURCE0} %{SOURCE1} %{SOURCE2} %{SOURCE3} \ - %{buildroot}/%{_rpmconfigdir}/macros.d/ +mkdir -p %{buildroot}/%{rpmmacrodir} +install -m 644 %{SOURCE0} %{SOURCE1} %{SOURCE2} %{SOURCE3} %{SOURCE5} \ + %{buildroot}/%{rpmmacrodir} %files -%{_rpmconfigdir}/macros.d/macros.python +%{rpmmacrodir}/macros.python +%{rpmmacrodir}/macros.pybytecompile %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 +* 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 +- 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. + +* 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. +- 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} @@ -81,12 +100,18 @@ install -m 644 %{SOURCE0} %{SOURCE1} %{SOURCE2} %{SOURCE3} \ * Thu Feb 04 2016 Fedora Release Engineering - 3-7 - Rebuilt for https://fedoraproject.org/wiki/Fedora_24_Mass_Rebuild +* 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 * Thu Jan 14 2016 Orion Poplawski 3-5 - Handle noarch python sub-packages (bug #1290900) +* 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