summaryrefslogtreecommitdiffstats
path: root/Doc/packaging
diff options
context:
space:
mode:
authorÉric Araujo <merwok@netwok.org>2011-11-03 04:08:28 (GMT)
committerÉric Araujo <merwok@netwok.org>2011-11-03 04:08:28 (GMT)
commit880801501b778d93079afc11672dba86e60eab94 (patch)
tree32bad2da11ff3f125f67e46d93c308f18c311eab /Doc/packaging
parentdfd232898d4ae64a4c176ed492eec5e1ab209ef8 (diff)
downloadcpython-880801501b778d93079afc11672dba86e60eab94.zip
cpython-880801501b778d93079afc11672dba86e60eab94.tar.gz
cpython-880801501b778d93079afc11672dba86e60eab94.tar.bz2
Improve byte-compilation in packaging to be independent of -O or -B.
The code I fixed to comply with PEP 3147 still had one bug: When run under python -O, some paths for pyc files would be pyo, because I called imp.cache_from_source without explicit debug_override argument in some places, and under -O that would return .pyo (this is well explained in the imp docs). Now all code (util.byte_compile, build_py, install_lib) can create .pyo files according to options given by users, without interference from the calling Python’s own optimize mode. On a related topic, I also removed the code that prevented byte compilation under python -B. The rationale is that packaging gives control over the creation of pyc files to the user with its own explicit option, and the behavior should not be changed if the calling Python happens to run with -B for whatever reason. I will argue that this is a bug fix and ask to be allowed to backport this change to distutils. Finally, I moved one nugget of information about the --compile and --optimize options from the source into the doc. It clears up a misunderstanding that I (and maybe other people) had.
Diffstat (limited to 'Doc/packaging')
-rw-r--r--Doc/packaging/builtdist.rst4
-rw-r--r--Doc/packaging/commandref.rst28
2 files changed, 27 insertions, 5 deletions
diff --git a/Doc/packaging/builtdist.rst b/Doc/packaging/builtdist.rst
index b1e5e93..1d9a349 100644
--- a/Doc/packaging/builtdist.rst
+++ b/Doc/packaging/builtdist.rst
@@ -164,9 +164,7 @@ will reflect this and now has the form :file:`foo-1.0.win32-py2.0.exe`. You
have to create a separate installer for every Python version you want to
support.
-.. TODO Add :term: markup to bytecode when merging into the stdlib
-
-The installer will try to compile pure modules into bytecode after installation
+The installer will try to compile pure modules into :term:`bytecode` after installation
on the target system in normal and optimizing mode. If you don't want this to
happen for some reason, you can run the :command:`bdist_wininst` command with
the :option:`--no-target-compile` and/or the :option:`--no-target-optimize`
diff --git a/Doc/packaging/commandref.rst b/Doc/packaging/commandref.rst
index 0ec7505..2165b56 100644
--- a/Doc/packaging/commandref.rst
+++ b/Doc/packaging/commandref.rst
@@ -115,7 +115,24 @@ Build C/C++ extension modules.
-------------------
Build the Python modules (just copy them to the build directory) and
-byte-compile them to .pyc files.
+:term:`byte-compile <bytecode>` them to :file:`.pyc` and/or :file:`.pyo` files.
+
+The byte compilation is controlled by two sets of options:
+
+- ``--compile`` and ``--no-compile`` are used to control the creation of
+ :file:`.pyc` files; the default is ``--no-compile``.
+
+- ``--optimize N`` (or ``-ON``) is used to control the creation of :file:`.pyo`
+ files: ``-O1`` turns on basic optimizations, ``-O2`` also discards docstrings,
+ ``-O0`` does not create :file:`.pyo` files; the default is ``-O0``.
+
+You can mix and match these options: for example, ``--no-compile --optimize 2``
+will create :file:`.pyo` files but no :file:`.pyc` files.
+
+.. XXX these option roles do not work
+
+Calling Python with :option:`-O` or :option:`-B` does not control the creation
+of bytecode files, only the options described above do.
:command:`build_scripts`
@@ -341,7 +358,14 @@ Install C/C++ header files.
:command:`install_lib`
----------------------
-Install C library files.
+Install all modules (extensions and pure Python).
+
+.. XXX what about C libraries created with build_clib?
+
+Similarly to ``build_py``, there are options to control the compilation of
+Python code to :term:`bytecode` files (see above). By default, :file:`.pyc`
+files will be created (``--compile``) and :file:`.pyo` files will not
+(``--optimize 0``).
:command:`install_scripts`