[Distutils] Bug? zimpimporter putting in a misleading co_filename?

Phillip J. Eby pje at telecommunity.com
Tue Dec 23 16:58:41 CET 2008

At 10:11 AM 12/23/2008 -0500, Rocky Bernstein wrote:
>This is useful information and thanks for suggesting the workaround.
>However this does not address the issue which is not about how I can 
>create an unzipped egg  for my use or the use of others. (Or what I 
>did or didn't do to create such an zipped egg).
>I am interested in writing tools that work with both zipped an 
>unzipped eggs. To the extent that setuptools/distutils is 
>responsible for setting the co_filename field in the code object 
>what should go inside that field? And how can a programmer reliably 
>and, if possible, uniformly untangle this to get/report a location.

Distutils and setuptools aren't responsible.  Python sets the 
co_filename to the original location of the source from which a file 
was compiled.  So one way to get the source file of a function is to 
look in its func_globals for a __file__, and then convert .pyc/.pyo 
on the extension to .py.

In Python 2.5 and above, the inspect and linecache modules (among 
others) have been modified to support zipped files; they 
automatically handle retrieving the source lines via the module 
__loader__.get_source() method as well.  You may want to look at that 
code to see how it's handled, if you're needing to support 2.4 or 2.3 
as well as 2.5+.

More information about the Distutils-SIG mailing list