[issue4223] inspect.getsource doesn't work on functions imported from a zipfile

2008-12-14 Thread Nick Coghlan

Nick Coghlan ncogh...@gmail.com added the comment:

Final revisions for fix:
2.7 = r67751 (there was a new test file missing from the initial checkin)
2.6 = r67752
3.1 = r67753
3.0 = r67754

--
resolution:  - fixed
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue4223
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4223] inspect.getsource doesn't work on functions imported from a zipfile

2008-12-14 Thread Nick Coghlan

Nick Coghlan ncogh...@gmail.com added the comment:

Fixed for 2.7 in r67750.

Will be ported to 2.6, 3.0 and 3.1.

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue4223
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4223] inspect.getsource doesn't work on functions imported from a zipfile

2008-12-13 Thread Nick Coghlan

Nick Coghlan ncogh...@gmail.com added the comment:

After looking into this, I think Alexander is correct. There is no
standard mapping between __file__ and __name__ and linecache is mistaken
in assuming such a mapping exists for all importers (and is the same as
the standard filesystem to name mapping to boot).

In this particular case, it was the differences between the way the two
relate for a package vs a normal module that was confusing linecache,
but for more exotic cases the filesystem based rules that linecache was
attempting to enforce may be completely irrelevant.

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue4223
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4223] inspect.getsource doesn't work on functions imported from a zipfile

2008-12-03 Thread Nick Coghlan

Changes by Nick Coghlan [EMAIL PROTECTED]:


--
assignee:  - ncoghlan
nosy: +ncoghlan

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue4223
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4223] inspect.getsource doesn't work on functions imported from a zipfile

2008-10-28 Thread Guilherme Polo

Guilherme Polo [EMAIL PROTECTED] added the comment:

Well anyway, some sample code:

import zipfile

z = zipfile.ZipFile('aaa.zip', mode='w')
z.writestr('aa.py', 'def x(): print hi there\n\ndef y(): print hi')
z.close()


and then:


import sys
import inspect

sys.path.append('aaa.zip')
import aa

inspect.getsource(aa.x)
inspect.getsource(aa.y)


Doesn't that work for you ?

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue4223
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4223] inspect.getsource doesn't work on functions imported from a zipfile

2008-10-28 Thread Jean-Paul Calderone

Jean-Paul Calderone [EMAIL PROTECTED] added the comment:

It seems to depend on working directory:

[EMAIL PROTECTED]:/tmp$ python
Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) 
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type help, copyright, credits or license for more information.
 import sys
 sys.path.append('/home/exarkun/foobar.zip')
 import foobar, inspect
 inspect.getsource(foobar.foo)
Traceback (most recent call last):
  File stdin, line 1, in module
  File /usr/lib/python2.5/inspect.py, line 629, in getsource
lines, lnum = getsourcelines(object)
  File /usr/lib/python2.5/inspect.py, line 618, in getsourcelines
lines, lnum = findsource(object)
  File /usr/lib/python2.5/inspect.py, line 468, in findsource
raise IOError('could not get source code')
IOError: could not get source code
 

versus:

[EMAIL PROTECTED]:~$ python
Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) 
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type help, copyright, credits or license for more information.
 import sys
 sys.path.append('/home/exarkun/foobar.zip')
 import foobar, inspect
 inspect.getsource(foobar.foo)
'def foo():\npass\n'


___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue4223
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4223] inspect.getsource doesn't work on functions imported from a zipfile

2008-10-28 Thread Alexander Belopolsky

Alexander Belopolsky [EMAIL PROTECTED] added the comment:

This must be very similar to #4197 and #4201 that I reported a few days 
ago.  I'll see if a similar patch would work in this case.

--
nosy: +belopolsky

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue4223
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4223] inspect.getsource doesn't work on functions imported from a zipfile

2008-10-28 Thread Alexander Belopolsky

Alexander Belopolsky [EMAIL PROTECTED] added the comment:

Hmm, apparently inspect was made to work with zipped modules back in r45248 .

I cannot reproduce the problem either.

Jean-Paul, can you attach your foobar.zip?  What else do you have in your 
/tmp directory?

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue4223
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4223] inspect.getsource doesn't work on functions imported from a zipfile

2008-10-28 Thread Martin v. Löwis

Martin v. Löwis [EMAIL PROTECTED] added the comment:

In any case, it's clearly not a candidate for 2.5.3, due to the lack of
a clear problem description, and a working patch. That essentially means
that associating the version 2.5 is also fairly pointless, but I'll
leave that in, anyway.

--
nosy: +loewis
versions:  -Python 2.5.3

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue4223
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4223] inspect.getsource doesn't work on functions imported from a zipfile

2008-10-28 Thread Jean-Paul Calderone

Jean-Paul Calderone [EMAIL PROTECTED] added the comment:

Here is a transcript for a complete, self-contained, minimal reproduction:

[EMAIL PROTECTED]:~$ cd /tmp
[EMAIL PROTECTED]:/tmp$ mkdir zipimportbugexample
[EMAIL PROTECTED]:/tmp$ cd zipimportbugexample/
[EMAIL PROTECTED]:/tmp/zipimportbugexample$ mkdir foobar
[EMAIL PROTECTED]:/tmp/zipimportbugexample$ echo def foo(): pass 
foobar/__init__.py
[EMAIL PROTECTED]:/tmp/zipimportbugexample$ zip foobar.zip foobar
  adding: foobar/ (stored 0%)
[EMAIL PROTECTED]:/tmp/zipimportbugexample$ zip foobar.zip foobar/__init__.py 
  adding: foobar/__init__.py (stored 0%)
[EMAIL PROTECTED]:/tmp/zipimportbugexample$ rm -r foobar
[EMAIL PROTECTED]:/tmp/zipimportbugexample$ mkdir workingdirectory
[EMAIL PROTECTED]:/tmp/zipimportbugexample$ cd workingdirectory/
[EMAIL PROTECTED]:/tmp/zipimportbugexample/workingdirectory$ python
Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) 
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type help, copyright, credits or license for more information.
 import sys
 sys.path.append('/tmp/zipimportbugexample/foobar.zip')
 import foobar, inspect
 inspect.getsource(foobar.foo)
Traceback (most recent call last):
  File stdin, line 1, in module
  File /usr/lib/python2.5/inspect.py, line 629, in getsource
lines, lnum = getsourcelines(object)
  File /usr/lib/python2.5/inspect.py, line 618, in getsourcelines
lines, lnum = findsource(object)
  File /usr/lib/python2.5/inspect.py, line 468, in findsource
raise IOError('could not get source code')
IOError: could not get source code


___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue4223
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4223] inspect.getsource doesn't work on functions imported from a zipfile

2008-10-28 Thread Alexander Belopolsky

Alexander Belopolsky [EMAIL PROTECTED] added the comment:

Thanks, Jean-Paul, I can now reproduce your problem and I think I found 
the culprit.

I believe the file name check in linecache.updatecache is unnecessary 
and is responsible for this problem.  With the following patch:

--- Lib/linecache.py(revision 67040)
+++ Lib/linecache.py(working copy)
@@ -88,7 +88,7 @@
 get_source = getattr(loader, 'get_source', None)
 
 if name and get_source:
-if basename.startswith(name.split('.')[-1]+'.'):
+#if basename.startswith(name.split('.')[-1]+'.'):
 try:
 data = get_source(name)
 except (ImportError, IOError):


and Jean-Paul's foobar:

$ PYTHONPATH=/tmp/foobar.zip ./python.exe  -c import inspect,foobar; 
print inspect.getsource(foobar)
def foo(): pass


Martin, is there a chance for this issue and  #4197, #4201  to make it 
to 2.5.3?  If so, I'll prepare a combined patch with tests for your 
consideration shortly.

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue4223
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com