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
This PEP adds the ability to import compiled Python modules
*.py[co] and packages from zip archives.
This PEP adds the ability to import Python modules
*.py, *.py[co] and packages from zip archives.
Specification
@ -26,12 +26,12 @@ Specification
The implementation is in C code in the Python core and works on
all supported Python platforms.
Any files may be present in the zip archive, but only files *.pyc,
*.pyo and __init__.py[co] are available for import. Zip import of
*.py and dynamic modules (*.pyd, *.so) is disallowed.
Any files may be present in the zip archive, but only files
*.py and *.py[co] are available for import. Zip import of
dynamic modules (*.pyd, *.so) is disallowed.
Just as sys.path currently has default directory names, default
zip archive names are added too. Otherwise there is no way to
Just as sys.path currently has default directory names, a default
zip archive name is added too. Otherwise there is no way to
import all Python library files from an archive.
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
the dynload_*.c, and that's probably not a good idea.
You also can't import source files *.py from a zip archive. The
problem here is what to do with the compiled files. Python would
normally write these to the same directory as *.py, but surely we
When trying to import *.pyc, if it is not available then
*.pyo will be used instead. And vice versa when looking for *.pyo.
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
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
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.
good if it is /usr/bin for example.
So the only imports zip archives support are *.pyc and *.pyo, plus
the import of __init__.py[co] for packages, and the search of the
subdirectory structure for the same.
Failing to write the compiled files will make zip imports very slow,
and the user will probably not figure out what is wrong. So it
is best to put *.pyc and *.pyo in the archive with the *.py.
Efficiency
@ -142,7 +141,7 @@ Booting
sys.path, and /usr/local/lib/python22.zip would be added.
On Windows, the directory is the directory of sys.executable.
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