[Python-Dev] Request for Pronouncement: PEP 441 (original) (raw)

[Python-Dev] Request for Pronouncement: PEP 441 - Improving Python ZIP Application Support

Paul Moore p.f.moore at gmail.com
Wed Feb 25 20:33:19 CET 2015


On 25 February 2015 at 17:06, Paul Moore <p.f.moore at gmail.com> wrote:

Is the difference between create and copy important? e.g., is there anything wrong with

createarchive(oldarchive, output=newarchive) working as well as createarchive(directory, archive)? Probably not, now. The semantics have converged enough that this might be reasonable. It's how the command line interface works, after all. It would mean that the behaviour would be different depending on the value of the source argument (supplying the main argument and omitting the target are only valid for create), but again that's how the command line works. I'll have a go at implementing this change this evening and see how it plays out.

That worked out pretty well, IMO. The resulting API is a lot cleaner (internally, there's not much change, I still have a copy_archive function but it's now private). I've included the resulting API documentation below. It looks pretty good to me.

Does anyone have any further suggestions or comments, or does this look ready to go back to Guido for a second review?

Paul

Python API

The module defines two convenience functions:

.. function:: create_archive(directory, target=None, interpreter=None, main=None)

Create an application archive from source. The source can be any of the following:

The target argument determines where the resulting archive will be written:

The interpreter argument specifies the name of the Python interpreter with which the archive will be executed. It is written as a "shebang" line at the start of the archive. On POSIX, this will be interpreted by the OS, and on Windows it will be handled by the Python launcher. Omitting the interpreter results in no shebang line being written. If an interpreter is specified, and the target is a filename, the executable bit of the target file will be set.

The main argument specifies the name of a callable which will be used as the main program for the archive. It can only be specified if the source is a directory, and the source does not already contain a __main__.py file. The main argument should take the form "pkg.module:callable" and the archive will be run by importing "pkg.module" and executing the given callable with no arguments. It is an error to omit main if the source is a directory and does not contain a __main__.py file, as otherwise the resulting archive would not be executable.

If a file object is specified for source or target, it is the caller's responsibility to close it after calling create_archive.

When copying an existing archive, file objects supplied only need read and readline, or write methods. When creating an archive from a directory, if the target is a file object it will be passed to the zipfile.ZipFile class, and must supply the methods needed by that class.

.. function:: get_interpreter(archive)

Return the interpreter specified in the #! line at the start of the archive. If there is no #! line, return :const:None. The archive argument can be a filename or a file-like object open for reading in bytes mode. It is assumed to be at the start of the archive.



More information about the Python-Dev mailing list