Jim's latest update

This commit is contained in:
Barry Warsaw 2001-11-02 20:44:57 +00:00
parent 5b12f72b7d
commit ba76a39d7f
1 changed files with 18 additions and 19 deletions

View File

@ -11,8 +11,8 @@ Python-Version: 2.3
Abstract Abstract
This PEP adds the ability to import compiled Python modules This PEP adds the ability to import Python modules
*.py[co] and packages from zip archives. *.py, *.py[co] and packages from zip archives.
Specification Specification
@ -26,12 +26,12 @@ Specification
The implementation is in C code in the Python core and works on The implementation is in C code in the Python core and works on
all supported Python platforms. all supported Python platforms.
Any files may be present in the zip archive, but only files *.pyc, Any files may be present in the zip archive, but only files
*.pyo and __init__.py[co] are available for import. Zip import of *.py and *.py[co] are available for import. Zip import of
*.py and dynamic modules (*.pyd, *.so) is disallowed. dynamic modules (*.pyd, *.so) is disallowed.
Just as sys.path currently has default directory names, default Just as sys.path currently has default directory names, a default
zip archive names are added too. Otherwise there is no way to zip archive name is added too. Otherwise there is no way to
import all Python library files from an archive. import all Python library files from an archive.
Reading compressed zip archives requires the zlib module. An Reading compressed zip archives requires the zlib module. An
@ -68,20 +68,19 @@ Subdirectory Equivalence
But that would mean creating temporary files, and dealing with all But that would mean creating temporary files, and dealing with all
the dynload_*.c, and that's probably not a good idea. the dynload_*.c, and that's probably not a good idea.
You also can't import source files *.py from a zip archive. The When trying to import *.pyc, if it is not available then
problem here is what to do with the compiled files. Python would *.pyo will be used instead. And vice versa when looking for *.pyo.
normally write these to the same directory as *.py, but surely we If neither *.pyc nor *.pyo is available, or if the magic numbers
are invalid, then *.py will be compiled and used to satisfy the
import, but the compiled file will not be saved. Python would
normally write it to the same directory as *.py, but surely we
don't want to write to the zip file. We could write to the don't want to write to the zip file. We could write to the
directory of the zip archive, but that would clutter it up, not directory of the zip archive, but that would clutter it up, not
good if it is /usr/bin for example. We could just fail to write good if it is /usr/bin for example.
the compiled files, but that makes zip imports very slow, and the
user would probably not figure out what is wrong. It is probably
best for users to put *.pyc into zip archives in the first place,
and this PEP enforces that rule.
So the only imports zip archives support are *.pyc and *.pyo, plus Failing to write the compiled files will make zip imports very slow,
the import of __init__.py[co] for packages, and the search of the and the user will probably not figure out what is wrong. So it
subdirectory structure for the same. is best to put *.pyc and *.pyo in the archive with the *.py.
Efficiency Efficiency
@ -142,7 +141,7 @@ Booting
sys.path, and /usr/local/lib/python22.zip would be added. sys.path, and /usr/local/lib/python22.zip would be added.
On Windows, the directory is the directory of sys.executable. On Windows, the directory is the directory of sys.executable.
The zip archive name is always inserted as the second item The zip archive name is always inserted as the second item
in sys.path. The first always seems to be ''. in sys.path. The first is the directory of the main.py (thanks Tim).
Implementation Implementation