|
![](https://seccdn.libravatar.org/avatar/fe11cff032b4e7558bdfe5f7f1b6fa3166a00faecacd35fbef2218e0463b5f3f?s=16&d=retro) |
7391367 |
# Note that the path could itself be a python file, or a directory
|
|
![](https://seccdn.libravatar.org/avatar/fe11cff032b4e7558bdfe5f7f1b6fa3166a00faecacd35fbef2218e0463b5f3f?s=16&d=retro) |
7391367 |
|
|
![](https://seccdn.libravatar.org/avatar/281c1b4f9e726ace8c183e703bc93493c3fdda6c6706c9b0eee00875216507d8?s=16&d=retro) |
76681ad |
# Note that the py_byte_compile macro should work for all Python versions
|
|
![](https://seccdn.libravatar.org/avatar/281c1b4f9e726ace8c183e703bc93493c3fdda6c6706c9b0eee00875216507d8?s=16&d=retro) |
76681ad |
# Which unfortunately makes the definition more complicated than it should be
|
|
![](https://seccdn.libravatar.org/avatar/fe11cff032b4e7558bdfe5f7f1b6fa3166a00faecacd35fbef2218e0463b5f3f?s=16&d=retro) |
7391367 |
|
|
![](https://seccdn.libravatar.org/avatar/3c06a168eac5e10baa83f960445b9b006df35865b76dcf7a899f6215ea86b54f?s=16&d=retro) |
8f067ff |
# Usage:
|
|
![](https://seccdn.libravatar.org/avatar/3c06a168eac5e10baa83f960445b9b006df35865b76dcf7a899f6215ea86b54f?s=16&d=retro) |
8f067ff |
# %py_byte_compile <interpereter> <path>
|
|
![](https://seccdn.libravatar.org/avatar/3c06a168eac5e10baa83f960445b9b006df35865b76dcf7a899f6215ea86b54f?s=16&d=retro) |
8f067ff |
# Example:
|
|
![](https://seccdn.libravatar.org/avatar/3c06a168eac5e10baa83f960445b9b006df35865b76dcf7a899f6215ea86b54f?s=16&d=retro) |
8f067ff |
# %py_byte_compile %{__python3} %{buildroot}%{_datadir}/spam/plugins/
|
|
![](https://seccdn.libravatar.org/avatar/3c06a168eac5e10baa83f960445b9b006df35865b76dcf7a899f6215ea86b54f?s=16&d=retro) |
8f067ff |
|
|
![](https://seccdn.libravatar.org/avatar/3c06a168eac5e10baa83f960445b9b006df35865b76dcf7a899f6215ea86b54f?s=16&d=retro) |
8f067ff |
# This will terminate build on SyntaxErrors, if you want to avoid that,
|
|
![](https://seccdn.libravatar.org/avatar/3c06a168eac5e10baa83f960445b9b006df35865b76dcf7a899f6215ea86b54f?s=16&d=retro) |
8f067ff |
# use it in a subshell like this:
|
|
![](https://seccdn.libravatar.org/avatar/3c06a168eac5e10baa83f960445b9b006df35865b76dcf7a899f6215ea86b54f?s=16&d=retro) |
8f067ff |
# (%{py_byte_compile <interpereter> <path>}) || :
|
|
![](https://seccdn.libravatar.org/avatar/3c06a168eac5e10baa83f960445b9b006df35865b76dcf7a899f6215ea86b54f?s=16&d=retro) |
438faf7 |
|
|
![](https://seccdn.libravatar.org/avatar/fe11cff032b4e7558bdfe5f7f1b6fa3166a00faecacd35fbef2218e0463b5f3f?s=16&d=retro) |
7391367 |
%py_byte_compile()\
|
|
![](https://seccdn.libravatar.org/avatar/281c1b4f9e726ace8c183e703bc93493c3fdda6c6706c9b0eee00875216507d8?s=16&d=retro) |
76681ad |
py2_byte_compile () {\
|
|
![](https://seccdn.libravatar.org/avatar/281c1b4f9e726ace8c183e703bc93493c3fdda6c6706c9b0eee00875216507d8?s=16&d=retro) |
76681ad |
python_binary="%1"\
|
|
![](https://seccdn.libravatar.org/avatar/281c1b4f9e726ace8c183e703bc93493c3fdda6c6706c9b0eee00875216507d8?s=16&d=retro) |
76681ad |
bytecode_compilation_path="%2"\
|
|
![](https://seccdn.libravatar.org/avatar/281c1b4f9e726ace8c183e703bc93493c3fdda6c6706c9b0eee00875216507d8?s=16&d=retro) |
76681ad |
failure=0\
|
|
![](https://seccdn.libravatar.org/avatar/281c1b4f9e726ace8c183e703bc93493c3fdda6c6706c9b0eee00875216507d8?s=16&d=retro) |
4493789 |
find $bytecode_compilation_path -type f -a -name "*.py" -print0 | xargs -0 $python_binary -s -c 'import py_compile, sys; [py_compile.compile(f, dfile=f.partition("'"$RPM_BUILD_ROOT"'")[2], doraise=True) for f in sys.argv[1:]]' || failure=1\
|
|
![](https://seccdn.libravatar.org/avatar/281c1b4f9e726ace8c183e703bc93493c3fdda6c6706c9b0eee00875216507d8?s=16&d=retro) |
4493789 |
find $bytecode_compilation_path -type f -a -name "*.py" -print0 | xargs -0 $python_binary -s -O -c 'import py_compile, sys; [py_compile.compile(f, dfile=f.partition("'"$RPM_BUILD_ROOT"'")[2], doraise=True) for f in sys.argv[1:]]' || failure=1\
|
|
![](https://seccdn.libravatar.org/avatar/281c1b4f9e726ace8c183e703bc93493c3fdda6c6706c9b0eee00875216507d8?s=16&d=retro) |
76681ad |
test $failure -eq 0\
|
|
![](https://seccdn.libravatar.org/avatar/281c1b4f9e726ace8c183e703bc93493c3fdda6c6706c9b0eee00875216507d8?s=16&d=retro) |
76681ad |
}\
|
|
![](https://seccdn.libravatar.org/avatar/281c1b4f9e726ace8c183e703bc93493c3fdda6c6706c9b0eee00875216507d8?s=16&d=retro) |
76681ad |
\
|
|
![](https://seccdn.libravatar.org/avatar/281c1b4f9e726ace8c183e703bc93493c3fdda6c6706c9b0eee00875216507d8?s=16&d=retro) |
76681ad |
py3_byte_compile () {\
|
|
![](https://seccdn.libravatar.org/avatar/281c1b4f9e726ace8c183e703bc93493c3fdda6c6706c9b0eee00875216507d8?s=16&d=retro) |
76681ad |
python_binary="%1"\
|
|
![](https://seccdn.libravatar.org/avatar/281c1b4f9e726ace8c183e703bc93493c3fdda6c6706c9b0eee00875216507d8?s=16&d=retro) |
76681ad |
bytecode_compilation_path="%2"\
|
|
![](https://seccdn.libravatar.org/avatar/281c1b4f9e726ace8c183e703bc93493c3fdda6c6706c9b0eee00875216507d8?s=16&d=retro) |
4493789 |
PYTHONPATH="%{_rpmconfigdir}/redhat" $python_binary -s -B -m compileall2 -o 0 -o 1 -s $RPM_BUILD_ROOT -p / $bytecode_compilation_path \
|
|
![](https://seccdn.libravatar.org/avatar/281c1b4f9e726ace8c183e703bc93493c3fdda6c6706c9b0eee00875216507d8?s=16&d=retro) |
76681ad |
}\
|
|
![](https://seccdn.libravatar.org/avatar/281c1b4f9e726ace8c183e703bc93493c3fdda6c6706c9b0eee00875216507d8?s=16&d=retro) |
76681ad |
\
|
|
![](https://seccdn.libravatar.org/avatar/281c1b4f9e726ace8c183e703bc93493c3fdda6c6706c9b0eee00875216507d8?s=16&d=retro) |
eb32743 |
# Path to intepreter should not contain any arguments \
|
|
![](https://seccdn.libravatar.org/avatar/281c1b4f9e726ace8c183e703bc93493c3fdda6c6706c9b0eee00875216507d8?s=16&d=retro) |
eb32743 |
[[ "%1" =~ " -" ]] && echo "ERROR py_byte_compile: Path to interpreter should not contain any arguments" >&2 && exit 1 \
|
|
![](https://seccdn.libravatar.org/avatar/281c1b4f9e726ace8c183e703bc93493c3fdda6c6706c9b0eee00875216507d8?s=16&d=retro) |
76681ad |
# Get version without a dot (36 instead of 3.6), bash doesn't compare floats well \
|
|
![](https://seccdn.libravatar.org/avatar/281c1b4f9e726ace8c183e703bc93493c3fdda6c6706c9b0eee00875216507d8?s=16&d=retro) |
76681ad |
python_version=$(%1 -c "import sys; sys.stdout.write('{0.major}{0.minor}'.format(sys.version_info))") \
|
|
![](https://seccdn.libravatar.org/avatar/281c1b4f9e726ace8c183e703bc93493c3fdda6c6706c9b0eee00875216507d8?s=16&d=retro) |
76681ad |
# compileall2 Python module is not compatible with Python < 3.4 \
|
|
![](https://seccdn.libravatar.org/avatar/281c1b4f9e726ace8c183e703bc93493c3fdda6c6706c9b0eee00875216507d8?s=16&d=retro) |
76681ad |
if [ "$python_version" -ge 34 ]; then py3_byte_compile "%1" "%2"; else py2_byte_compile "%1" "%2"; fi
|