| OLD | NEW |
| 1 :mod:`py_compile` --- Compile Python source files | 1 :mod:`py_compile` --- Compile Python source files |
| 2 ================================================= | 2 ================================================= |
| 3 | 3 |
| 4 .. module:: py_compile | 4 .. module:: py_compile |
| 5 :synopsis: Generate byte-code files from Python source files. | 5 :synopsis: Generate byte-code files from Python source files. |
| 6 .. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org> | 6 .. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org> |
| 7 .. documentation based on module docstrings | 7 .. documentation based on module docstrings |
| 8 | 8 |
| 9 .. index:: pair: file; byte-code | 9 .. index:: pair: file; byte-code |
| 10 | 10 |
| 11 The :mod:`py_compile` module provides a function to generate a byte-code file | 11 The :mod:`py_compile` module provides a function to generate a byte-code file |
| 12 from a source file, and another function used when the module source file is | 12 from a source file, and another function used when the module source file is |
| 13 invoked as a script. | 13 invoked as a script. |
| 14 | 14 |
| 15 Though not often needed, this function can be useful when installing modules for | 15 Though not often needed, this function can be useful when installing modules for |
| 16 shared use, especially if some of the users may not have permission to write the | 16 shared use, especially if some of the users may not have permission to write the |
| 17 byte-code cache files in the directory containing the source code. | 17 byte-code cache files in the directory containing the source code. |
| 18 | 18 |
| 19 | 19 |
| 20 .. exception:: PyCompileError | 20 .. exception:: PyCompileError |
| 21 | 21 |
| 22 Exception raised when an error occurs while attempting to compile the file. | 22 Exception raised when an error occurs while attempting to compile the file. |
| 23 | 23 |
| 24 | 24 |
| 25 .. function:: compile(file, cfile=None, dfile=None, doraise=False) | 25 .. function:: compile(file, cfile=None, dfile=None, doraise=False, optimize=-1) |
| 26 | 26 |
| 27 Compile a source file to byte-code and write out the byte-code cache file.
The | 27 Compile a source file to byte-code and write out the byte-code cache file.
The |
| 28 source code is loaded from the file name *file*. The byte-code is written t
o | 28 source code is loaded from the file name *file*. The byte-code is written t
o |
| 29 *cfile*, which defaults to the :PEP:`3147` path, ending in ``.pyc`` | 29 *cfile*, which defaults to the :PEP:`3147` path, ending in ``.pyc`` |
| 30 (``'.pyo`` if optimization is enabled in the current interpreter). For | 30 (``'.pyo`` if optimization is enabled in the current interpreter). For |
| 31 example, if *file* is ``/foo/bar/baz.py`` *cfile* will default to | 31 example, if *file* is ``/foo/bar/baz.py`` *cfile* will default to |
| 32 ``/foo/bar/__pycache__/baz.cpython-32.pyc`` for Python 3.2. If *dfile* is sp
ecified, it is used as the | 32 ``/foo/bar/__pycache__/baz.cpython-32.pyc`` for Python 3.2. If *dfile* is sp
ecified, it is used as the |
| 33 name of the source file in error messages instead of *file*. If *doraise* is | 33 name of the source file in error messages instead of *file*. If *doraise* is |
| 34 true, a :exc:`PyCompileError` is raised when an error is encountered while | 34 true, a :exc:`PyCompileError` is raised when an error is encountered while |
| 35 compiling *file*. If *doraise* is false (the default), an error string is | 35 compiling *file*. If *doraise* is false (the default), an error string is |
| 36 written to ``sys.stderr``, but no exception is raised. This function | 36 written to ``sys.stderr``, but no exception is raised. This function |
| 37 returns the path to byte-compiled file, i.e. whatever *cfile* value was | 37 returns the path to byte-compiled file, i.e. whatever *cfile* value was |
| 38 used. | 38 used. |
| 39 |
| 40 *optimze* controls the optimization level and is passed to the built-in |
| 41 :func:`compile` function. The default of ``-1`` selects the optimization |
| 42 level of the current interpreter. |
| 43 |
| 44 .. versionchanged:: 3.2 |
| 45 Added the *optimze* parameter. |
| 39 | 46 |
| 40 | 47 |
| 41 .. function:: main(args=None) | 48 .. function:: main(args=None) |
| 42 | 49 |
| 43 Compile several source files. The files named in *args* (or on the command | 50 Compile several source files. The files named in *args* (or on the command |
| 44 line, if *args* is ``None``) are compiled and the resulting bytecode is | 51 line, if *args* is ``None``) are compiled and the resulting bytecode is |
| 45 cached in the normal manner. This function does not search a directory | 52 cached in the normal manner. This function does not search a directory |
| 46 structure to locate source files; it only compiles files named explicitly. | 53 structure to locate source files; it only compiles files named explicitly. |
| 47 | 54 |
| 48 When this module is run as a script, the :func:`main` is used to compile all the | 55 When this module is run as a script, the :func:`main` is used to compile all the |
| 49 files named on the command line. The exit status is nonzero if one of the files | 56 files named on the command line. The exit status is nonzero if one of the files |
| 50 could not be compiled. | 57 could not be compiled. |
| 51 | 58 |
| 52 | 59 |
| 53 .. seealso:: | 60 .. seealso:: |
| 54 | 61 |
| 55 Module :mod:`compileall` | 62 Module :mod:`compileall` |
| 56 Utilities to compile all Python source files in a directory tree. | 63 Utilities to compile all Python source files in a directory tree. |
| 57 | 64 |
| OLD | NEW |