linecache vs egg - reading line of a file in an egg

R

R. Bernstein

Does linecache work with source in Python eggs? If not, is it
contemplated that this is going to be fixed or is there something else
like linecache that currently works?

Right now, I think pdb and pydb (and probably other debuggers) are
broken when they try to trace into code that is part of an egg.

Here's what I tried recently:

Using this egg:
http://pypi.python.org/packages/2.5/t/tracer/tracer-0.1.0-py2.5.egg

I install that and look for the filename of one of the
functions. Here's a sample session:

To read the source for tracer.py, information from "Accessing Package
Resources"
(http://peak.telecommunity.com/DevCenter/PythonEggs#accessing-package-resources)
suggests:

This gives me one long string which I can split and then index.

Note that I used "tracer.py" above, not
"build/bdist.linux-8686/egg/tracer.py" How do tracebacks and things that
read frame information deal with the discrepency?

Before reinventing the wheel and trying to extend linecache to do
something like the above, has someone already come up with a solution?

Thanks
 
R

Robert Kern

R. Bernstein said:
Does linecache work with source in Python eggs? If not, is it
contemplated that this is going to be fixed or is there something else
like linecache that currently works?

linecache works with eggs and other zipped Python source, but it had to extend
the API in order to do so. Some of the debuggers don't use the extended API.
This will be fixed in the next 2.6.x bugfix release, but not in 2.5.3.

http://bugs.python.org/issue4201

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
 
C

Chris Rebert

Does linecache work with source in Python eggs? If not, is it
contemplated that this is going to be fixed or is there something else
like linecache that currently works?

I believe it already does. FYI, eggs are just zip files with a certain
file/directory structure.
And linecache seems to handle reading from zipfile modules. Ergo,
linecache can read source from eggs.

Quoting from the linecache docs
(http://docs.python.org/library/linecache.html), emphasis mine:

linecache.getline(filename, lineno[, module_globals])
<snip>
If a file named filename is not found, the function will ***look
for it in the module search path, sys.path***, after first checking
for a PEP 302 __loader__ in module_globals, in case the module was
***imported from a zipfile*** or other non-filesystem import source.

Cheers,
Chris
 
R

R. Bernstein

Robert Kern said:
linecache works with eggs and other zipped Python source, but it had
to extend the API in order to do so. Some of the debuggers don't use
the extended API. This will be fixed in the next 2.6.x bugfix release,
but not in 2.5.3.

Ok. I have committed a change in pydb sources to deal with the 2 and 3
argument linecache.getline interface which should cover Python
releases both before and after version 2.5.

Many thanks! I should have dug deeper myself.

For pdb/bdb though isn't there still a problem in reporting the file
location? There is that weird "build" name that seems to be stored in
func_code.co_filename mentioned in the original post.

I just tried patching pdb/bdb along from the current 2.6 svn sources
and here is what I see:

$ pdb /tmp/lc.py
> /tmp/lc.py(1)<module>()
-> import tracer
(Pdb) s
--Call--
> /src/external-vcs/python/build/bdist.linux-i686/egg/tracer.py(6)<module>()

The above filename is wrong. It's very possible I did something wrong,
so I'd be grateful if someone else double checked.

Furthermore, if there is a problem I'm not sure I see how to fix this.

I can think of heuristics to tell if module lives an inside an egg,
but is there a reliable way? Is there a standard convention for
reporting a file location inside of an egg?

Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top