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

Paul Moore p.f.moore at gmail.com
Tue Feb 24 21:20:26 CET 2015


On 24 February 2015 at 18:58, Guido van Rossum <guido at python.org> wrote:
> Why no command-line equivalent for the other two methods?  I propose the
> following interface: if there's only one positional argument, we're asking
> to print its shebang line; if there are two and the input position is an
> archive instead of a directory, we're copying.  (In the future people will
> want an option to print more stuff, e.g. the main function or even a full
> listing.)

Thinking about this, there are 3 main uses:

1. Create an archive
2. Print the shebang
3. Change the shebang

Of these, (1) is the crucial one.

Basic usage should be

    python -m zipapp mydir [-o anothername.pyz] [-p interpreter] [-m
entry:point]

This zips up mydir to create an archive mydir.pyz. Options to change
the target name, set a shebang line (side note: --python/-p or
--interpreter/-i?) and set the entry point,

I see this as pretty non-negotiable, this is the key use case that
needs to be as simple as possible.

To print the shebang, we could use

    python -m zipapp myapp.pyz --show

This allows for future expansion by adding options, although most
other things you might want to do (list the files, display
__main__.py) can be done with a standard zip utility. I'm not keen on
the option name --show, but I can't think of anything substantially
better.

To modify an archive could be done using

    python -m zipapp old.pyz new.pyz [-p interpreter]

Default is to strip the shebang (no -p option). There's no option to
omit the target and do an inplace update because I feel the default
action (strip the shebang from the existing file with no backup) is
too dangerous.

To be explicit, "python -m zipapp app.pyz" will fail with a message
"In-place editing of python zip applications is not supported".

That seems to work.

Open questions:

1. To create an archive, use -o target for an explicit target name, or
just "target". The former is more conventional, the latter consistent
with modification. Or we could make modification use a (mandatory) -o
option.
2. -p/--python or -i/--interpreter for the shebang setting option
3. What to call the "show the shebang line" option

Paul


More information about the Python-Dev mailing list