Bug 1531253

Summary: %py_byte_compile() macro works for Python 3 only
Product: [Fedora] Fedora Reporter: Terje Røsten <terje.rosten>
Component: python3Assignee: Miro Hrončok <mhroncok>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 27CC: bkabrda, cstratak, dmalcolm, ishcherb, lzachar, mcyprian, mhroncok, pviktori, rkuska, rolf, tomspur, torsava
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: python3-3.6.5-1.fc26 python3-3.6.5-1.fc27 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-04-09 18:35:14 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Terje Røsten 2018-01-04 19:54:34 UTC
Description of problem:

$ rpm -qf /usr/lib/rpm/macros.d/macros.pybytecompile3.6
python3-devel-3.6.3-2.fc26.x86_64

$ cat /usr/lib/rpm/macros.d/macros.pybytecompile3.6

%py_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:]]' || :\
%{nil}

Docs says macros should be used by Python 2 and 3:

 https://fedoraproject.org/wiki/Packaging:Python_Appendix#Manual_byte_compilation

# Manually invoke the python byte compile macro for each path that needs byte
# compilation.
%py_byte_compile %{__python2} %{buildroot}%{_datadir}/mypackage/foo
%py_byte_compile %{__python3} %{buildroot}%{_datadir}/mypackage/bar


However, macro %py_byte_compile only works for Python 3 as function
py_compile.compile() in Python 2 don't support the optimize argument.


Compare:
 https://docs.python.org/2/library/py_compile.html
 https://docs.python.org/3/library/py_compile.html


This blocks packaging of Python 2 and 3 scripts in the same package for me.

Comment 1 Miro Hrončok 2018-01-05 11:11:05 UTC
*** Bug 1484993 has been marked as a duplicate of this bug. ***

Comment 2 Terje Røsten 2018-01-10 16:19:30 UTC
FYI: as workaround in recoll I created two bash functions:

 https://src.fedoraproject.org/cgit/rpms/recoll.git/tree/recoll.spec#n91

Comment 3 Miro Hrončok 2018-01-18 16:04:32 UTC
Proposed fix https://src.fedoraproject.org/rpms/python37/pull-request/3

Comment 4 Fedora Update System 2018-04-05 15:55:45 UTC
python-pip-9.0.3-1.fc26 python3-3.6.5-1.fc26 python3-docs-3.6.5-1.fc26 has been submitted as an update to Fedora 26. https://bodhi.fedoraproject.org/updates/FEDORA-2018-aa8de9d66a

Comment 5 Fedora Update System 2018-04-05 15:56:55 UTC
python-pip-9.0.3-1.fc26 python3-3.6.5-1.fc26 python3-docs-3.6.5-1.fc26 has been submitted as an update to Fedora 26. https://bodhi.fedoraproject.org/updates/FEDORA-2018-aa8de9d66a

Comment 6 Fedora Update System 2018-04-05 16:13:19 UTC
python-pip-9.0.3-1.fc27 python3-3.6.5-1.fc27 python3-docs-3.6.5-1.fc27 has been submitted as an update to Fedora 27. https://bodhi.fedoraproject.org/updates/FEDORA-2018-a042f795b2

Comment 7 Fedora Update System 2018-04-05 16:14:29 UTC
python-pip-9.0.3-1.fc27 python3-3.6.5-1.fc27 python3-docs-3.6.5-1.fc27 has been submitted as an update to Fedora 27. https://bodhi.fedoraproject.org/updates/FEDORA-2018-a042f795b2

Comment 8 Fedora Update System 2018-04-06 16:52:14 UTC
python-pip-9.0.3-1.fc26, python3-3.6.5-1.fc26, python3-docs-3.6.5-1.fc26 has been pushed to the Fedora 26 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2018-aa8de9d66a

Comment 9 Fedora Update System 2018-04-06 17:16:48 UTC
python-pip-9.0.3-1.fc27, python3-3.6.5-1.fc27, python3-docs-3.6.5-1.fc27 has been pushed to the Fedora 27 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2018-a042f795b2

Comment 10 Fedora Update System 2018-04-09 18:35:14 UTC
python-pip-9.0.3-1.fc26, python3-3.6.5-1.fc26, python3-docs-3.6.5-1.fc26 has been pushed to the Fedora 26 stable repository. If problems still persist, please make note of it in this bug report.

Comment 11 Fedora Update System 2018-04-09 19:08:57 UTC
python-pip-9.0.3-1.fc27, python3-3.6.5-1.fc27, python3-docs-3.6.5-1.fc27 has been pushed to the Fedora 27 stable repository. If problems still persist, please make note of it in this bug report.