diff options
author | Brett Cannon <brett@python.org> | 2015-04-13 18:21:02 (GMT) |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2015-04-13 18:21:02 (GMT) |
commit | f299abdafa0f2b6eb7abae274861b19b361c96bc (patch) | |
tree | afc3a2bf560e30c7725510eda3b57d71ceddba00 /Lib/py_compile.py | |
parent | a63cc212348e276c8ede32773313c60ff7fda651 (diff) | |
download | cpython-f299abdafa0f2b6eb7abae274861b19b361c96bc.zip cpython-f299abdafa0f2b6eb7abae274861b19b361c96bc.tar.gz cpython-f299abdafa0f2b6eb7abae274861b19b361c96bc.tar.bz2 |
Issue #23731: Implement PEP 488.
The concept of .pyo files no longer exists. Now .pyc files have an
optional `opt-` tag which specifies if any extra optimizations beyond
the peepholer were applied.
Diffstat (limited to 'Lib/py_compile.py')
-rw-r--r-- | Lib/py_compile.py | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/Lib/py_compile.py b/Lib/py_compile.py index 1277b93..166c488 100644 --- a/Lib/py_compile.py +++ b/Lib/py_compile.py @@ -1,4 +1,4 @@ -"""Routine to "compile" a .py file to a .pyc (or .pyo) file. +"""Routine to "compile" a .py file to a .pyc file. This module has intimate knowledge of the format of .pyc files. """ @@ -67,7 +67,7 @@ def compile(file, cfile=None, dfile=None, doraise=False, optimize=-1): :param file: The source file name. :param cfile: The target byte compiled file name. When not given, this - defaults to the PEP 3147 location. + defaults to the PEP 3147/PEP 488 location. :param dfile: Purported file name, i.e. the file name that shows up in error messages. Defaults to the source file name. :param doraise: Flag indicating whether or not an exception should be @@ -85,12 +85,12 @@ def compile(file, cfile=None, dfile=None, doraise=False, optimize=-1): Note that it isn't necessary to byte-compile Python modules for execution efficiency -- Python itself byte-compiles a module when it is loaded, and if it can, writes out the bytecode to the - corresponding .pyc (or .pyo) file. + corresponding .pyc file. However, if a Python installation is shared between users, it is a good idea to byte-compile all modules upon installation, since other users may not be able to write in the source directories, - and thus they won't be able to write the .pyc/.pyo file, and then + and thus they won't be able to write the .pyc file, and then they would be byte-compiling every module each time it is loaded. This can slow down program start-up considerably. @@ -105,8 +105,9 @@ def compile(file, cfile=None, dfile=None, doraise=False, optimize=-1): """ if cfile is None: if optimize >= 0: + optimization = optimize if optimize >= 1 else '' cfile = importlib.util.cache_from_source(file, - debug_override=not optimize) + optimization=optimization) else: cfile = importlib.util.cache_from_source(file) if os.path.islink(cfile): |