[Patches] [ python-Patches-401702 ] Modify co_filename in frozen programs

noreply@sourceforge.net noreply@sourceforge.net
Tue, 20 Mar 2001 12:44:55 -0800


Patches item #401702, was updated on 2000-09-29 04:38
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=401702&group_id=5470

Category: demos and tools
Group: None
>Status: Closed
>Priority: 5
Submitted By: Lawrence Hudson (lhudson)
Assigned to: Guido van Rossum (gvanrossum)
Summary: Modify co_filename in frozen programs

Initial Comment:
 

----------------------------------------------------------------------

>Comment By: Guido van Rossum (gvanrossum)
Date: 2001-03-20 12:44

Message:
Logged In: YES 
user_id=6380

Applied.  Closing now.

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2001-03-18 16:02

Message:
Logged In: YES 
user_id=6380

Sure, I see no problem with this patch.  I'll see if I can check it in.

If someone else who likes to hack freeze would have it, please go ahead!

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2001-03-01 23:12

Message:
Logged In: YES 
user_id=6380

Shit. Missed the deadline again. Will try before b2... :-(

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2001-01-19 14:45

Message:
No time to review this before the 2.1a1 release; I'll do this for 2.1a2.

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2001-01-19 07:53

Message:
I'm taking this, on the assumption that Mark's too busy and freeze is our shared responsibility.

----------------------------------------------------------------------

Comment By: Jeremy Hylton (jhylton)
Date: 2001-01-18 15:57

Message:
(somewhat) randomly reassigned; don't have time to look at this

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2000-10-25 04:19

Message:
Thanks for the new patch! I'll assign this to Jeremy for further review and to carry it to completion. (Jeremy, if you're swamped, please find someone else to do it.)

Re normpath: my mistake -- I meant normcase.

----------------------------------------------------------------------

Comment By: Lawrence Hudson (lhudson)
Date: 2000-10-25 01:36

Message:
A recursive code object transformer has been implemented as a member of the ModuleFinder.

Case sensitivity issue:
normpath strips trailing '/' or '\' which reduces the flexibility of the 
path replacement.  It also does not seem to solve the case-sensitivity problem:
    D:\>python
    Python 2.0 (#8, Oct 17 2000, 15:27:24) [MSC 32 bit (Intel)] on win32
    Type "copyright", "credits" or "license" for more information.
    >>> import os
    >>> os.path.normpath("c:\python\lib\")
    'c:\python\lib'
    >>> os.path.normpath("c:\python\Lib\")
    'c:\python\Lib'
    >>> 
ModuleFinder's debugging system is used to report the status of each unique path encountered.

Temporary file:
marshal.dump() and marshal.load() only work with file objects, not file-like objects.  Now that new code objects are being created there is no longer any reason to re-marshal so this problem disappears.


----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2000-10-23 12:33

Message:
I like the idea, but I have a few suggestions.

- To avoid the case sensitivity issue you mention, you could use os.path.normpath() before the string comparisons.

- Rather than writing to a real temporary file, you could marshal to a string and than unmarshal from a StringIO file.

- And the big whopper: rather than using a modified version of unmarshal, I suggest writing a recursive code object transformer. It takes a code object and a replace_paths list, and returns a similar code object with the co_filename attribute changed according to the list. The trick is that it should also do this, recursively, to any code object found in the co_consts tuple. (That's the only place where code objects can occur recursively.) While this is probably not much less code than the marshaller you wrote, it has the advantage of not being dependent on the details of the marshal format.
Please upload a new patch -- I'm interested in getting this into Python 2.1.

----------------------------------------------------------------------

Comment By: Jeremy Hylton (jhylton)
Date: 2000-09-29 07:28

Message:
This sounds like a reasonable enough feature, but we are in feature freeze for Python 2.0.


----------------------------------------------------------------------

Comment By: Lawrence Hudson (lhudson)
Date: 2000-09-29 04:39

Message:
A new feature for freeze.

This patch was developed primarily to reduce the size of the frozen binary.  It is particularly useful when freezing for 'small' platforms, such as Palm OS, where you really want to save that last miserable byte.

A limitation of this patch is that it does not provide any feedback about the replacements being made.  As the path matching is case-sensitive this may lead to unexpected behaviour for DOS and Windows people, eg
    > freeze.py -r C:\Python\Lib\=py\ goats.py
should probably be:
    > freeze.py -r c:\python\lib\=py\ goats.py


----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=401702&group_id=5470