List Info

Thread: Add a -z interpreter flag to execute a zip file




Re: Add a -z interpreter flag to execute a zip file
user name
2007-07-13 23:38:12
On 7/13/07, Greg Ewing <greg.ewingcanterbury.ac.nz>
wrote:
> Andy C wrote:
> > What does "if __name__ == '__main__"
mean in
> > __main__.py?  : )  If someone tries does import
__main__ from another
> > module in the program, won't that result in an
infinite loop?
>
> Is there a reason not to use __init__.py for this?

Well, you might have multiple executable .py files in the
same source
tree.  So then you would want to build multiple .pyz files,
each of
which has a different __zipmain__.

I think of __zipmain__ as part of the format of the .pyz
file, not
part of the source tree.  In particular, it specifies what
module/function to run in the zipped source tree (and I
imagine it
will be adapted for other uses).  In this model you're
separating your
development tree and the thing you deploy, which is not
always the
case in Python.

Andy
_______________________________________________
Python-Dev mailing list
Python-Devpython.org
ht
tp://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/p
ython-dev/nessto%40sharedlog.com

Re: Add a -z interpreter flag to execute a zip file
country flaguser name
United States
2007-07-14 08:58:56
At 02:58 PM 7/14/2007 +1200, Greg Ewing wrote:
>Andy C wrote:
> > What does "if __name__ == '__main__"
mean in
> > __main__.py?  : )  If someone tries does import
__main__ from another
> > module in the program, won't that result in an
infinite loop?
>
>Is there a reason not to use __init__.py for this?

Even some moderately-experienced Python developers confuse
the 
concepts of "package" and "directory
containing Python code" -- let's 
not make it worse by encouraging the inclusion of an
__init__ module 
in the top-level package namespace!

_______________________________________________
Python-Dev mailing list
Python-Devpython.org
ht
tp://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/p
ython-dev/nessto%40sharedlog.com

Re: Add a -z interpreter flag to execute a zip file
user name
2007-07-12 10:08:08
On 7/11/07, Andy C <andychupgmail.com> wrote:
> The good thing about this is that it's extremely simple
-- basically
> 20 lines of C code to add a -z flag that calls a 3-line
Python
> function in the runpy module.

Instead of requiring a -z flag, why not have the interpreter
peak at
the file to see if it starts with one of the ZIP magic
numbers?

That way it Just Works.

-- 
Daniel Stutzbach, Ph.D.             President, Stutzbach
Enterprises LLC
_______________________________________________
Python-Dev mailing list
Python-Devpython.org
ht
tp://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/p
ython-dev/nessto%40sharedlog.com

Re: Add a -z interpreter flag to execute a zip file
user name
2007-07-23 11:55:14
On 7/12/07, Daniel Stutzbach <danielstutzbachenterprises.com> wrote:
> On 7/11/07, Andy C <andychupgmail.com> wrote:
> > The good thing about this is that it's extremely
simple -- basically
> > 20 lines of C code to add a -z flag that calls a
3-line Python
> > function in the runpy module.
>
> Instead of requiring a -z flag, why not have the
interpreter peak at
> the file to see if it starts with one of the ZIP magic
numbers?
>
> That way it Just Works.

I guess you wouldn't recognize a zip file if it hits you in
the face.
Literally. 

Zip files don't start with a magic number.

-- 
--Guido van Rossum (home page: http://www.python.org/~
guido/)
_______________________________________________
Python-Dev mailing list
Python-Devpython.org
ht
tp://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/p
ython-dev/nessto%40sharedlog.com

Re: Add a -z interpreter flag to execute a zip file
country flaguser name
United States
2007-07-23 12:12:40

Crutcher Dunnavant

On Jul 23, 2007, at 9:55 AM, "Guido van Rossum"
<guidopython.org>  
wrote:

> On 7/12/07, Daniel Stutzbach <danielstutzbachenterprises.com> wrote:
>> On 7/11/07, Andy C <andychupgmail.com> wrote:
>>> The good thing about this is that it's
extremely simple -- basically
>>> 20 lines of C code to add a -z flag that calls
a 3-line Python
>>> function in the runpy module.
>>
>> Instead of requiring a -z flag, why not have the
interpreter peak at
>> the file to see if it starts with one of the ZIP
magic numbers?
>>
>> That way it Just Works.
>
> I guess you wouldn't recognize a zip file if it hits
you in the face.
> Literally. 
>
> Zip files don't start with a magic number.

Don't they end with a sentinel? If so, what would be the
difference?
>
> -- 
> --Guido van Rossum (home page: http://www.python.org/~
guido/)
> _______________________________________________
> Python-Dev mailing list
> Python-Devpython.org
> ht
tp://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/pyt
hon-dev/crutcher%40gmail.com
_______________________________________________
Python-Dev mailing list
Python-Devpython.org
ht
tp://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/p
ython-dev/nessto%40sharedlog.com

Re: Add a -z interpreter flag to execute a zip file
user name
2007-07-23 12:34:33
On 7/23/07, Crutcher Dunnavant <crutchergmail.com> wrote:
>
>
> Crutcher Dunnavant
>
> On Jul 23, 2007, at 9:55 AM, "Guido van
Rossum" <guidopython.org>
> wrote:
>
> > On 7/12/07, Daniel Stutzbach <danielstutzbachenterprises.com> wrote:
> >> On 7/11/07, Andy C <andychupgmail.com> wrote:
> >>> The good thing about this is that it's
extremely simple -- basically
> >>> 20 lines of C code to add a -z flag that
calls a 3-line Python
> >>> function in the runpy module.
> >>
> >> Instead of requiring a -z flag, why not have
the interpreter peak at
> >> the file to see if it starts with one of the
ZIP magic numbers?
> >>
> >> That way it Just Works.
> >
> > I guess you wouldn't recognize a zip file if it
hits you in the face.
> > Literally. 
> >
> > Zip files don't start with a magic number.
>
> Don't they end with a sentinel? If so, what would be
the difference?

There's an ambiguity -- a Zip file could start with a Python
(or
shell, or Perl) script that bootstraps execution. This is
used
regularly. Changing the semantics just because the file
*ends* with
something funny sounds like asking for trouble.

-- 
--Guido van Rossum (home page: http://www.python.org/~
guido/)
_______________________________________________
Python-Dev mailing list
Python-Devpython.org
ht
tp://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/p
ython-dev/nessto%40sharedlog.com

Re: Add a -z interpreter flag to execute a zip file
country flaguser name
United States
2007-07-23 12:54:55
At 09:55 AM 7/23/2007 -0700, Guido van Rossum wrote:
>On 7/12/07, Daniel Stutzbach <danielstutzbachenterprises.com> wrote:
> > On 7/11/07, Andy C <andychupgmail.com> wrote:
> > > The good thing about this is that it's
extremely simple -- basically
> > > 20 lines of C code to add a -z flag that
calls a 3-line Python
> > > function in the runpy module.
> >
> > Instead of requiring a -z flag, why not have the
interpreter peak at
> > the file to see if it starts with one of the ZIP
magic numbers?
> >
> > That way it Just Works.
>
>I guess you wouldn't recognize a zip file if it hits you
in the face.
>Literally. 
>
>Zip files don't start with a magic number.

I've actually started on a patch that uses the standard
import hooks 
to figure out how to import __main__ from sys.argv[0], if
it's 
something that an import hook can be found for (otherwise,
it falls 
back to normal behavior).

At this point, the problem is that __main__ is a builtin
module and 
already exists when this processing is being done, so trying
to 
reload it in a straightforward way doesn't work.  (Nor does
using the 
standard -m logic.)

If I can figure out how to work around that bit, we won't
need a -z 
flag, which means a #! line for zipfiles is possible on
'nix, and we 
can support arbitrary import hooks for sys.argv[0]. 
(Assuming 
they're either built-in or registered via sitecustomize,
that is.)

_______________________________________________
Python-Dev mailing list
Python-Devpython.org
ht
tp://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/p
ython-dev/nessto%40sharedlog.com

Re: Add a -z interpreter flag to execute a zip file
country flaguser name
United States
2007-07-23 13:02:08
At 10:34 AM 7/23/2007 -0700, Guido van Rossum wrote:
>There's an ambiguity -- a Zip file could start with a
Python (or
>shell, or Perl) script that bootstraps execution. This
is used
>regularly. Changing the semantics just because the file
*ends* with
>something funny sounds like asking for trouble.

Actually, it isn't, because you can't start a zipfile with a
Python 
script.  Lord knows I've *tried*, but the Python interpreter
just 
won't accept arbitrary binary data as part of a script. 


Second, unless you somehow managed to overcome that little
obstacle, 
you're not going to be trying to run the zipfile with the
Python 
interpreter, anyway.  Instead, the #! line (or .exe header
on 
Windows) will be invoking whatever interpreter or program
actually 
works for that file.

Third, if you mistakenly pass an existing such zipfile to a
new 
Python interpreter that supports zipfiles, and there's no 
__main__.py* file in it, you're just going to get a
different error 
message than the syntax error you'd have received from an
older 
Python.interpreter to run it with -- but otherwise no
difference.

In other words, AFAICT there's really no ambiguity here.

_______________________________________________
Python-Dev mailing list
Python-Devpython.org
ht
tp://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/p
ython-dev/nessto%40sharedlog.com

Re: Add a -z interpreter flag to execute a zip file
user name
2007-07-23 16:57:34
On 23/07/07, Phillip J. Eby <pjetelecommunity.com>
wrote:
> Actually, it isn't, because you can't start a zipfile
with a Python
> script.  Lord knows I've *tried*, but the Python
interpreter just
> won't accept arbitrary binary data as part of a script.
 

That bit me a while back, hard enough that I thought of
putting
together a patch for it (probably just to stop processing
the script
at a NUL byte), but never did as I didn't think I could put
a
convincing enough case for it being *useful*.

Anyway, I'd be happy enough with the -z patch as it stands,
or if
someone comes up with something better, that would suit me
too...

Paul.
_______________________________________________
Python-Dev mailing list
Python-Devpython.org
ht
tp://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/p
ython-dev/nessto%40sharedlog.com

Re: Add a -z interpreter flag to execute a zip file
user name
2007-07-23 21:37:10
Just to update everyone on the status of this, the next
thing on my
list is to figure out the Windows build and set up the the
file
association in the installer.  Actually, I should ask if
there's
anything else that I should pay attention to here, e.g. do I
have to
add an icon association for Windows or something like that?

Is there any documentation like a wiki page on this?  I
looked at the
README in the PC* directories and it doesn't seem to talk
about the
installer.  Maybe it will become clearer when I get Visual
Studio.

Andy

On 7/23/07, Paul Moore <p.f.mooregmail.com> wrote:
> On 23/07/07, Phillip J. Eby <pjetelecommunity.com> wrote:
> > Actually, it isn't, because you can't start a
zipfile with a Python
> > script.  Lord knows I've *tried*, but the Python
interpreter just
> > won't accept arbitrary binary data as part of a
script.  
>
> That bit me a while back, hard enough that I thought of
putting
> together a patch for it (probably just to stop
processing the script
> at a NUL byte), but never did as I didn't think I could
put a
> convincing enough case for it being *useful*.
>
> Anyway, I'd be happy enough with the -z patch as it
stands, or if
> someone comes up with something better, that would suit
me too...
>
> Paul.
> _______________________________________________
> Python-Dev mailing list
> Python-Devpython.org
> ht
tp://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/pyt
hon-dev/andychup%40gmail.com
>
_______________________________________________
Python-Dev mailing list
Python-Devpython.org
ht
tp://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/p
ython-dev/nessto%40sharedlog.com

[1-10] [11-20] [21-30] [31-40] [41-42]

about | contact  Other archives ( Real Estate discussion Medical topics )