This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Option to select the optimization level on compileall
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.3, Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Claudiu.Popa, Sworddragon, eric.araujo
Priority: normal Keywords:

Created on 2013-11-20 21:29 by Sworddragon, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (5)
msg203533 - (view) Author: (Sworddragon) Date: 2013-11-20 21:29
Currently on calling one of the compileall functions it is not possible to pass the optimization level as argument. The bytecode will be created depending of the optimization level of the current script instance. But if a script wants to compile .pyc files for one destination and .pyo files for another destination this will be a little tricky.
msg203577 - (view) Author: PCManticore (Claudiu.Popa) * (Python triager) Date: 2013-11-21 06:20
Hi. Since Python 3.2, compileall functions supports the optimization level through the `optimize` parameter. I guess you are using Python2.7 or so? Also, there's a note in compileall's documentation regarding the command line switch for the optimization level:

"
There is no command-line option to control the optimization level used by the compile() function, because the Python interpreter itself already provides the option: python -O -m compileall.
"
http://docs.python.org/3.2/library/compileall.html#command-line-use
msg203626 - (view) Author: (Sworddragon) Date: 2013-11-21 12:53
> Hi. Since Python 3.2, compileall functions supports the optimization level through the `optimize` parameter.

> There is no command-line option to control the optimization level used by the compile() function, because the Python interpreter itself already provides the option: python -O -m compileall.

This is the problem: You can't pass the optimization level to compile_dir|compile_file|compile_path. What, if you want for location a .pyc files and for location b .pyo files? Or even .pyc files and .pyo files for both locations? The only solution is to make a command call within the script which is a little bit ugly.
msg203868 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2013-11-22 20:50
If I understand correctly, compileall is intended as a command-line tool, but there is py_compile if you want programmatic access.  Does py_compile provide functions that let you control the optimization level?
msg203888 - (view) Author: (Sworddragon) Date: 2013-11-22 21:34
After checking it: Yes it does, thanks for the hint. In this case I'm closing this ticket now.
History
Date User Action Args
2022-04-11 14:57:53adminsetgithub: 63870
2013-11-22 21:34:24Sworddragonsetstatus: open -> closed
resolution: not a bug
messages: + msg203888
2013-11-22 20:50:56eric.araujosetnosy: + eric.araujo
messages: + msg203868
2013-11-21 12:53:09Sworddragonsetmessages: + msg203626
2013-11-21 06:20:47Claudiu.Popasetnosy: + Claudiu.Popa
messages: + msg203577
2013-11-20 21:29:40Sworddragoncreate