Use compileall2 Python module for byte-compilation in brp-python-bytecompile
This commit is contained in:
parent
53617406d9
commit
5437dfca81
@ -15,6 +15,14 @@ if [ -z "$depth" -o "$depth" -le "1" ]; then
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# This function now implements Python byte-compilation in two different ways:
|
||||||
|
# Python >= 3.4 uses a new module compileall2 - https://github.com/fedora-python/compileall2
|
||||||
|
# Python < 3.4 (inc. Python 2) uses compileall module from stdlib with some hacks
|
||||||
|
# When we drop support for Python 2, we'd be able to use all compileall2 features like:
|
||||||
|
# - -s and -p options to manipulate with a path baked into pyc files instead of $real_libdir
|
||||||
|
# - -o 0 -o 1 to produce multiple files in one run - each with a different optimization level - instead of $options
|
||||||
|
# - removed useless $depth - both compileall and compileall2 are limited by sys.getrecursionlimit()
|
||||||
|
# These changes will make this script much simpler
|
||||||
function python_bytecompile()
|
function python_bytecompile()
|
||||||
{
|
{
|
||||||
local options=$1
|
local options=$1
|
||||||
@ -24,6 +32,26 @@ function python_bytecompile()
|
|||||||
local depth=$5
|
local depth=$5
|
||||||
local real_libdir=$6
|
local real_libdir=$6
|
||||||
|
|
||||||
|
python_version=$($python_binary -c "import sys; sys.stdout.write('{0.major}{0.minor}'.format(sys.version_info))")
|
||||||
|
|
||||||
|
#
|
||||||
|
# Python 3.4 and higher
|
||||||
|
#
|
||||||
|
if [ "$python_version" -ge 34 ]; then
|
||||||
|
|
||||||
|
[ ! -z $exclude ] && exclude="-x '$exclude'"
|
||||||
|
# /usr/lib/rpm/redhat/ contains compileall2 Python module
|
||||||
|
# -q disables verbose output
|
||||||
|
# -f forces the process to overwrite existing compiled files
|
||||||
|
# -x excludes paths defined by regex
|
||||||
|
# -e excludes symbolic links pointing outside the build root
|
||||||
|
# -x and -e together implements the same functionality as the Filter class below
|
||||||
|
PYTHONPATH=/usr/lib/rpm/redhat/ $python_binary $options -m compileall2 -q -f $exclude -d $real_libdir -e $RPM_BUILD_ROOT $python_libdir
|
||||||
|
else
|
||||||
|
#
|
||||||
|
# Python 3.3 and lower (incl. Python 2)
|
||||||
|
#
|
||||||
|
|
||||||
cat << EOF | $python_binary $options
|
cat << EOF | $python_binary $options
|
||||||
import compileall, sys, os, re
|
import compileall, sys, os, re
|
||||||
|
|
||||||
@ -42,6 +70,8 @@ class Filter:
|
|||||||
|
|
||||||
sys.exit(not compileall.compile_dir(python_libdir, depth, real_libdir, force=1, rx=Filter(), quiet=1))
|
sys.exit(not compileall.compile_dir(python_libdir, depth, real_libdir, force=1, rx=Filter(), quiet=1))
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# .pyc/.pyo files embed a "magic" value, identifying the ABI version of Python
|
# .pyc/.pyo files embed a "magic" value, identifying the ABI version of Python
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
Summary: Red Hat specific rpm configuration files
|
Summary: Red Hat specific rpm configuration files
|
||||||
Name: redhat-rpm-config
|
Name: redhat-rpm-config
|
||||||
Version: 138
|
Version: 139
|
||||||
Release: 1%{?dist}
|
Release: 1%{?dist}
|
||||||
# No version specified.
|
# No version specified.
|
||||||
License: GPL+
|
License: GPL+
|
||||||
@ -207,6 +207,9 @@ install -p -m 644 -t %{buildroot}%{_rpmluadir}/fedora/srpm forge.lua
|
|||||||
%{_rpmconfigdir}/macros.d/macros.kmp
|
%{_rpmconfigdir}/macros.d/macros.kmp
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Wed Jul 17 2019 Lumír Balhar <lbalhar@redhat.com> - 139-1
|
||||||
|
- Use compileall2 Python module for byte-compilation in brp-python-bytecompile
|
||||||
|
|
||||||
* Tue Jul 09 2019 Miro Hrončok <mhroncok@redhat.com> - 138-1
|
* Tue Jul 09 2019 Miro Hrončok <mhroncok@redhat.com> - 138-1
|
||||||
- Move brp-python-bytecompile from rpm, so we can easily adapt it
|
- Move brp-python-bytecompile from rpm, so we can easily adapt it
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user