<div dir="ltr"><br><br><div class="gmail_quote">On Wed, Feb 25, 2015 at 2:33 PM Paul Moore <<a href="mailto:p.f.moore@gmail.com">p.f.moore@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 25 February 2015 at 17:06, Paul Moore <<a href="mailto:p.f.moore@gmail.com" target="_blank">p.f.moore@gmail.com</a>> wrote:<br>
>> Is the difference between create and copy important? e.g., is there<br>
>> anything wrong with<br>
>><br>
>> create_archive(old_archive, output=new_archive) working as well as<br>
>> create_archive(directory, archive)?<br>
><br>
> Probably not, now. The semantics have converged enough that this might<br>
> be reasonable. It's how the command line interface works, after all.<br>
> It would mean that the behaviour would be different depending on the<br>
> value of the source argument (supplying the main argument and omitting<br>
> the target are only valid for create), but again that's how the<br>
> command line works.<br>
><br>
> I'll have a go at implementing this change this evening and see how it<br>
> plays out.<br>
<br>
That worked out pretty well, IMO. The resulting API is a lot cleaner<br>
(internally, there's not much change, I still have a copy_archive<br>
function but it's now private). I've included the resulting API<br>
documentation below. It looks pretty good to me.<br>
<br>
Does anyone have any further suggestions or comments, or does this<br>
look ready to go back to Guido for a second review?<br></blockquote><div><br></div><div>+1 from me.<br></div><div><br></div><div>-Brett</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Paul<br>
<br>
Python API<br>
----------<br>
<br>
The module defines two convenience functions:<br>
<br>
<br>
.. function:: create_archive(directory, target=None, interpreter=None,<br>
main=None)<br>
<br>
Create an application archive from *source*. The source can be any<br>
of the following:<br>
<br>
* The name of a directory, in which case a new application archive<br>
will be created from the content of that directory.<br>
* The name of an existing application archive file, in which case the<br>
file is copied to the target. The file name should include the<br>
``.pyz`` extension, if required.<br>
* A file object open for reading in bytes mode. The content of the<br>
file should be an application archive, and the file object is<br>
assumed to be positioned at the start of the archive.<br>
<br>
The *target* argument determines where the resulting archive will be<br>
written:<br>
<br>
* If it is the name of a file, the archive will be written to that<br>
file.<br>
* If it is an open file object, the archive will be written to that<br>
file object, which must be open for writing in bytes mode.<br>
* If the target is omitted (or None), the source must be a directory<br>
and the target will be a file with the same name as the source, with<br>
a ``.pyz`` extension added.<br>
<br>
The *interpreter* argument specifies the name of the Python<br>
interpreter with which the archive will be executed. It is written as<br>
a "shebang" line at the start of the archive. On POSIX, this will be<br>
interpreted by the OS, and on Windows it will be handled by the Python<br>
launcher. Omitting the *interpreter* results in no shebang line being<br>
written. If an interpreter is specified, and the target is a<br>
filename, the executable bit of the target file will be set.<br>
<br>
The *main* argument specifies the name of a callable which will be<br>
used as the main program for the archive. It can only be specified if<br>
the source is a directory, and the source does not already contain a<br>
``__main__.py`` file. The *main* argument should take the form<br>
"pkg.module:callable" and the archive will be run by importing<br>
"pkg.module" and executing the given callable with no arguments. It<br>
is an error to omit *main* if the source is a directory and does not<br>
contain a ``__main__.py`` file, as otherwise the resulting archive<br>
would not be executable.<br>
<br>
If a file object is specified for *source* or *target*, it is the<br>
caller's responsibility to close it after calling create_archive.<br>
<br>
When copying an existing archive, file objects supplied only need<br>
``read`` and ``readline``, or ``write`` methods. When creating an<br>
archive from a directory, if the target is a file object it will be<br>
passed to the ``zipfile.ZipFile`` class, and must supply the methods<br>
needed by that class.<br>
<br>
.. function:: get_interpreter(archive)<br>
<br>
Return the interpreter specified in the ``#!`` line at the start of the<br>
archive. If there is no ``#!`` line, return :const:`None`.<br>
The *archive* argument can be a filename or a file-like object open<br>
for reading in bytes mode. It is assumed to be at the start of the archive.<br>
______________________________<u></u>_________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org" target="_blank">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" target="_blank">https://mail.python.org/<u></u>mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/brett%40python.org" target="_blank">https://mail.python.org/<u></u>mailman/options/python-dev/<u></u>brett%40python.org</a><br>
</blockquote></div></div>