Use compileall from stdlib for Python >= 3.9
All enhancements from compileall2 are merged in Python 3.9.
This commit is contained in:
parent
331ffabd7e
commit
8a4f0edb9a
@ -24,14 +24,15 @@ 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:
|
# This function now implements Python byte-compilation in three different ways:
|
||||||
# Python >= 3.4 uses a new module compileall2 - https://github.com/fedora-python/compileall2
|
# Python >= 3.4 and < 3.9 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
|
# 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:
|
# 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
|
# - -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
|
# - -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()
|
# - removed useless $depth - both compileall and compileall2 are limited by sys.getrecursionlimit()
|
||||||
# These changes will make this script much simpler
|
# These changes will make this script much simpler
|
||||||
|
# In Python >= 3.9, compileall2 was merged back to standard library (compileall) so we can use it directly again.
|
||||||
function python_bytecompile()
|
function python_bytecompile()
|
||||||
{
|
{
|
||||||
local options=$1
|
local options=$1
|
||||||
@ -43,10 +44,25 @@ function python_bytecompile()
|
|||||||
|
|
||||||
python_version=$($python_binary -c "import sys; sys.stdout.write('{0.major}{0.minor}'.format(sys.version_info))")
|
python_version=$($python_binary -c "import sys; sys.stdout.write('{0.major}{0.minor}'.format(sys.version_info))")
|
||||||
|
|
||||||
|
#
|
||||||
|
# Python 3.9 and higher
|
||||||
|
#
|
||||||
|
if [ "$python_version" -ge 39 ]; then
|
||||||
|
|
||||||
|
[ ! -z $exclude ] && exclude="-x '$exclude'"
|
||||||
|
# -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
|
||||||
|
# -s strips $RPM_BUILD_ROOT from the path
|
||||||
|
# -p prepends the leading slash to the path to make it absolute
|
||||||
|
$python_binary -B $options -m compileall -q -f $exclude -s $RPM_BUILD_ROOT -p / -e $RPM_BUILD_ROOT $python_libdir
|
||||||
|
|
||||||
#
|
#
|
||||||
# Python 3.4 and higher
|
# Python 3.4 and higher
|
||||||
#
|
#
|
||||||
if [ "$python_version" -ge 34 ]; then
|
elif [ "$python_version" -ge 34 ]; then
|
||||||
|
|
||||||
[ ! -z $exclude ] && exclude="-x '$exclude'"
|
[ ! -z $exclude ] && exclude="-x '$exclude'"
|
||||||
# /usr/lib/rpm/redhat/ contains compileall2 Python module
|
# /usr/lib/rpm/redhat/ contains compileall2 Python module
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
Summary: Red Hat specific rpm configuration files
|
Summary: Red Hat specific rpm configuration files
|
||||||
Name: redhat-rpm-config
|
Name: redhat-rpm-config
|
||||||
Version: 161
|
Version: 161
|
||||||
Release: 1%{?dist}
|
Release: 2%{?dist}
|
||||||
# No version specified.
|
# No version specified.
|
||||||
License: GPL+
|
License: GPL+
|
||||||
URL: https://src.fedoraproject.org/rpms/redhat-rpm-config
|
URL: https://src.fedoraproject.org/rpms/redhat-rpm-config
|
||||||
@ -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
|
||||||
|
* Tue Jun 16 2020 Lumír Balhar <lbalhar@redhat.com> - 161-2
|
||||||
|
- Use stdlib compileall for Python >= 3.9
|
||||||
|
|
||||||
* Mon Jun 15 2020 Lumír Balhar <lbalhar@redhat.com> - 161-1
|
* Mon Jun 15 2020 Lumír Balhar <lbalhar@redhat.com> - 161-1
|
||||||
- No more automagic Python bytecompilation (phase 3)
|
- No more automagic Python bytecompilation (phase 3)
|
||||||
https://fedoraproject.org/wiki/Changes/No_more_automagic_Python_bytecompilation_phase_3
|
https://fedoraproject.org/wiki/Changes/No_more_automagic_Python_bytecompilation_phase_3
|
||||||
|
Loading…
Reference in New Issue
Block a user