Fix brp-python-bytecompile with the new features from compileall2
Resolves: rhbz#1595265
The problem this change is intended to solve is with how `real_libdir`
is calculated. Let's assume we want to recursively byte-compile all
`*.py` files in
`/builddir/build/BUILDROOT/python-scales-1.0.9-250.fc32.x86_64/usr/lib/python3.8`.
Then, `real_libdir` is this path without `$RPM_BUILD_ROOT` with
the filename at the end which displays in the error message like this:
```
Bytecompiling .py files below /builddir/build/BUILDROOT/python-scales-1.0.9-250.fc32.x86_64/usr/lib/python3.8 using /usr/bin/python3.8
*** Error compiling '/builddir/build/BUILDROOT/python-scales-1.0.9-250.fc32.x86_64/usr/lib/python3.8/site-packages/greplin/bar.py'...
File "/usr/lib/python3.8/bar.py", line 1
import sin from math
^
SyntaxError: invalid syntax
```
`/usr/lib/python3.8/bar.py` is obviously wrong.
One of the new features of the `compileall2` module (which will
be available in stdlib in Python 3.9) is that the path byte-compiled to
`*.pyc` files is calculated for each file. This means that by using
`-s` and `-p` we can strip `$RPM_BUILD_ROOT` and prepend `/` for each
file individually which will fix the problem.
```
Bytecompiling .py files below /builddir/build/BUILDROOT/python-scales-1.0.9-250.fc32.x86_64/usr/lib/python3.8 using /usr/bin/python3.8
*** Error compiling '/builddir/build/BUILDROOT/python-scales-1.0.9-250.fc32.x86_64/usr/lib/python3.8/site-packages/greplin/bar.py'...
File "/usr/lib/python3.8/site-packages/greplin/bar.py", line 1
import sin from math
^
SyntaxError: invalid syntax
```
This change has an effect only for Python >= 3.4.
This commit is contained in:
parent
e64ffd7f26
commit
8f6bc2fd6c
@ -29,8 +29,8 @@ function python_bytecompile()
|
||||
local python_binary=$2
|
||||
local exclude=$3
|
||||
local python_libdir=$4
|
||||
local depth=$5
|
||||
local real_libdir=$6
|
||||
local depth=$5 # Not used for Python >= 3.4
|
||||
local real_libdir=$6 # Not used for Python >= 3.4
|
||||
|
||||
python_version=$($python_binary -c "import sys; sys.stdout.write('{0.major}{0.minor}'.format(sys.version_info))")
|
||||
|
||||
@ -46,7 +46,9 @@ function python_bytecompile()
|
||||
# -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
|
||||
# -s strips $RPM_BUILD_ROOT from the path
|
||||
# -p prepends the leading slash to the path to make it absolute
|
||||
PYTHONPATH=/usr/lib/rpm/redhat/ $python_binary $options -m compileall2 -q -f $exclude -s $RPM_BUILD_ROOT -p / -e $RPM_BUILD_ROOT $python_libdir
|
||||
else
|
||||
#
|
||||
# Python 3.3 and lower (incl. Python 2)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user