From f95b199339183de10521f18e2bc53a733328a1fa Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Sat, 4 Sep 2010 23:53:24 +0000 Subject: Update whatsnew for Pep3147. --- Doc/whatsnew/3.2.rst | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.2.rst b/Doc/whatsnew/3.2.rst index 9181b4f..c19c094 100644 --- a/Doc/whatsnew/3.2.rst +++ b/Doc/whatsnew/3.2.rst @@ -51,12 +51,65 @@ This article explains the new features in Python 3.2, compared to 3.1. +PEP 3147: PYC Repository Directories +===================================== + +Python's scheme for caching bytecode in *.pyc* files did not work well in +environments with multiple python interpreters. If one interpreter encountered +a cached file created by another interpreter, it would recompile the source and +overwrite the cached file, thus losing the benefits of caching. + +The issue of "pyc fights" has become more pronounced as it has become +common-place for Linux distributions to ship with multiple versions of Python. +These conflicts also arise with CPython alternatives such as Unladen Swallow. + +To solve this problem, Python's import machinery has been extended to use +distinct filenames for each interpreter. Instead of Python3.2 and Python3.3 and +UnladenSwallow each competing for a file called "mymodule.pyc", they will now +look for "mymodule.cpython-32.pyc", "mymodule.cpython-33.pyc", and +"mymodule.unladen10.pyc". And to keep prevent all of these new files from +cluttering source directories, the *pyc* files are now collected in a +"__pycache__" directory stored under the package directory. + +Aside from the filenames and target directories, the new scheme has a few +aspects that are visible to the programmer: + +* Imported modules now have a :attr:`__cached__` attribute which stores the + name of the actual file that was imported:: + + >>> import collections + >>> collections.__cached__ + 'c:/py32/lib/__pycache__/collections.cpython-32.pyc' + +* The tag that is unique to each interpreter is accessible from the :mod:`imp` + module:: + + >>> import imp + >>> imp.get_tag() + 'cpython-32' + +* Scripts that try to deduce source filename from the imported file now need to + be smarter. It is no longer sufficient to simply strip the "c" from a ".pyc" + filename. Instead, use the new functions in the :mod:`imp` module: + + >>> imp.source_from_cache('c:/py32/lib/__pycache__/collections.cpython-32.pyc') + 'c:/py32/lib/collections.py' + >>> imp.cache_from_source('c:/py32/lib/collections.py') + 'c:/py32/lib/__pycache__/collections.cpython-32.pyc' + +* The :mod:`py_compile` and :mod:`compileall` modules have been updated to + reflect the new naming convention and target directory. + +.. seealso:: + + :pep:`3147` - PYC Repository Directories + PEP written by Barry Warsaw. + PEPs ==== Implemented PEPs: -* :pep:`3147` * :pep:`3149` -- cgit v0.12