Skip to content

bpo-38112: Compileall improvements #16012

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Sep 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion Doc/library/compileall.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ compile Python sources.
cases where the source file does not exist at the time the byte-code file is
executed.

.. cmdoption:: -s strip_prefix
.. cmdoption:: -p prepend_prefix

Remove (``-s``) or append (``-p``) the given prefix of paths
recorded in the ``.pyc`` files.
Cannot be combined with ``-d``.

.. cmdoption:: -x regex

regex is used to search the full path to each file considered for
Expand Down Expand Up @@ -96,6 +103,16 @@ compile Python sources.
variable is not set, and ``checked-hash`` if the ``SOURCE_DATE_EPOCH``
environment variable is set.

.. cmdoption:: -o level

Compile with the given optimization level. May be used multiple times
to compile for multiple levels at a time (for example,
``compileall -o 1 -o 2``).

.. cmdoption:: -e dir

Ignore symlinks pointing outside the given directory.

.. versionchanged:: 3.2
Added the ``-i``, ``-b`` and ``-h`` options.

Expand All @@ -107,6 +124,12 @@ compile Python sources.
.. versionchanged:: 3.7
Added the ``--invalidation-mode`` option.

.. versionchanged:: 3.9
Added the ``-s``, ``-p``, ``-e`` options.
Raised the default recursion limit from 10 to
:py:func:`sys.getrecursionlimit()`.
Added the possibility to specify the ``-o`` option multiple times.


There is no command-line option to control the optimization level used by the
:func:`compile` function, because the Python interpreter itself already
Expand All @@ -120,7 +143,7 @@ runtime.
Public functions
----------------

.. function:: compile_dir(dir, maxlevels=10, ddir=None, force=False, rx=None, quiet=0, legacy=False, optimize=-1, workers=1, invalidation_mode=None)
.. function:: compile_dir(dir, maxlevels=sys.getrecursionlimit(), ddir=None, force=False, rx=None, quiet=0, legacy=False, optimize=-1, workers=1, invalidation_mode=None, stripdir=None, prependdir=None, limit_sl_dest=None)

Recursively descend the directory tree named by *dir*, compiling all :file:`.py`
files along the way. Return a true value if all the files compiled successfully,
Expand Down Expand Up @@ -166,6 +189,10 @@ Public functions
:class:`py_compile.PycInvalidationMode` enum and controls how the generated
pycs are invalidated at runtime.

The *stripdir*, *prependdir* and *limit_sl_dest* arguments correspond to
the ``-s``, ``-p`` and ``-e`` options described above.
They may be specified as ``str``, ``bytes`` or :py:class:`os.PathLike`.

.. versionchanged:: 3.2
Added the *legacy* and *optimize* parameter.

Expand All @@ -191,6 +218,9 @@ Public functions
.. versionchanged:: 3.8
Setting *workers* to 0 now chooses the optimal number of cores.

.. versionchanged:: 3.9
Added *stripdir*, *prependdir* and *limit_sl_dest* arguments.

.. function:: compile_file(fullname, ddir=None, force=False, rx=None, quiet=0, legacy=False, optimize=-1, invalidation_mode=None)

Compile the file with path *fullname*. Return a true value if the file
Expand Down Expand Up @@ -223,6 +253,10 @@ Public functions
:class:`py_compile.PycInvalidationMode` enum and controls how the generated
pycs are invalidated at runtime.

The *stripdir*, *prependdir* and *limit_sl_dest* arguments correspond to
the ``-s``, ``-p`` and ``-e`` options described above.
They may be specified as ``str``, ``bytes`` or :py:class:`os.PathLike`.

.. versionadded:: 3.2

.. versionchanged:: 3.5
Expand All @@ -238,6 +272,9 @@ Public functions
.. versionchanged:: 3.7.2
The *invalidation_mode* parameter's default value is updated to None.

.. versionchanged:: 3.9
Added *stripdir*, *prependdir* and *limit_sl_dest* arguments.

.. function:: compile_path(skip_curdir=True, maxlevels=0, force=False, quiet=0, legacy=False, optimize=-1, invalidation_mode=None)

Byte-compile all the :file:`.py` files found along ``sys.path``. Return a
Expand Down
Loading