This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: distutils.cmd breaks inspect
Type: Stage:
Components: None Versions: Python 2.5
Status: closed Resolution: duplicate
Dependencies: Superseder: re.match.func_code.co_filename returns ""
View: 1665
Assigned To: Nosy List: AstraLuma, christian.heimes, draghuram, gvanrossum
Priority: normal Keywords:

Created on 2008-01-03 19:26 by AstraLuma, last changed 2022-04-11 14:56 by admin. This issue is now closed.

File name Uploaded Description Edit
regen AstraLuma, 2008-01-03 22:07 The original python script which I found the bug with.
Messages (12)
msg59145 - (view) Author: Jamie Bliss (AstraLuma) Date: 2008-01-03 19:26
Something about distutils/ breaks inspect.findsource(). I am
unsure if this is a bug with DistUtils or the inspect module.

>>> import inspect, distutils.cmd
>>> inspect.findsource(distutils.cmd.install_misc.get_outputs)

Causes findsource() to receive an IndexError.

From some hacking, I've found that the root cause appears to be that
linecache.getlines() returns a number of lines that do not match the
actual file. (In my case, getlines() returns 405 lines when
distutils/ has 478 lines.)

This bug causes pydoc to break when it is pointed at distutils.cmd.

This is on Ubuntu Gutsy, Python 2.5.1
msg59147 - (view) Author: Raghuram Devarakonda (draghuram) (Python triager) Date: 2008-01-03 19:42
I can't reproduce it with 2.5.1 on SuSE 10. Can you please report the
exact traceback you see?
msg59150 - (view) Author: Jamie Bliss (AstraLuma) Date: 2008-01-03 19:55
sqlite3/test/ also seems to cause the same error, although the
difference is much wider (101 lines vs. 351).
msg59151 - (view) Author: Jamie Bliss (AstraLuma) Date: 2008-01-03 19:57
The exact traceback is as follows:

>>> findsource(distutils.cmd.install_misc.get_outputs)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.5/", line 510, in findsource
    if pat.match(lines[lnum]): break
IndexError: list index out of range
msg59157 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2008-01-03 20:53
Can't repro either.

I strongly suspect that this is because somehow linecache finds a
different version of the module on sys.path.
msg59159 - (view) Author: Jamie Bliss (AstraLuma) Date: 2008-01-03 21:30
Indeed. For the distutils.cmd case, linecache.updatecache() takes
"" and tracks that down to /usr/lib/python2.5/ This would
also explain the sqlite3.tests.types problem.

The bug seems to be that the inspect module doesn't pass enough context
information to linecache to unambiguously locate the file.
msg59161 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2008-01-03 21:35
Can you trace this a bit further?  Can you suggest a specific
modification that would fix this issue?
msg59162 - (view) Author: Raghuram Devarakonda (draghuram) (Python triager) Date: 2008-01-03 21:41
When I printed the file name that is being passed to
linecache.getlines() by findsource(), the file name is absolute path.
So there may be nothing wrong with linecache itself. Can you see what
is the name being passed in your case? We still need to trace what
specific setting on OP's system is causing the problem.
msg59167 - (view) Author: Jamie Bliss (AstraLuma) Date: 2008-01-03 22:07
depending on the use case, updatecache() will be passed
'distutils/', but still turn that into '/usr/lib/python2.5/'.

I have not messed with my stock Python modules. My sys.path is:
* /usr/lib/python2.5/site-packages/recaptcha_client-1.0.1-py2.5.egg
* /usr/lib/
* /usr/lib/python2.5/lib-dynload
* /usr/lib/python2.5/site-packages/Numeric
* /usr/lib/python2.5/site-packages/PIL
* /usr/lib/python2.5/site-packages/wx-2.8-gtk2-unicode
* /usr/lib/python2.5/site-packages
* /usr/lib/python2.5
* /usr/lib/python2.5/plat-linux2
* /usr/lib/python2.5/lib-tk
* /usr/local/lib/python2.5/site-packages
* /usr/lib/python2.5/site-packages/gst-0.10
* /var/lib/python-support/python2.5/pyinotify
* /var/lib/python-support/python2.5
* /usr/lib/python2.5/site-packages/gtk-2.0
* /var/lib/python-support/python2.5/gtk-2.0
* /usr/lib/site-python

I've also attached the script I used to discover the bug originally.
(Much larger than the snippets I've been pasting here.) Just be warned
that it writes a large number of files and produces considerable output.
msg59170 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2008-01-03 23:10
The issue is probably related to
msg59171 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2008-01-03 23:12
Do you happen to be on Ubuntu?

Maybe this is the same as issue #1665 ?
msg59195 - (view) Author: Jamie Bliss (AstraLuma) Date: 2008-01-04 00:39
They might be the same bug, with different manifestations.

That bug is starting to get rather annoying.

(At first, I thought it wasn't. Surprise, surprise.)
Date User Action Args
2022-04-11 14:56:29adminsetgithub: 46069
2008-01-04 01:11:43gvanrossumsetstatus: open -> closed
resolution: duplicate
superseder: re.match.func_code.co_filename returns ""
2008-01-04 00:39:33AstraLumasetmessages: + msg59195
2008-01-03 23:12:07gvanrossumsetmessages: + msg59171
2008-01-03 23:10:39christian.heimessetnosy: + christian.heimes
messages: + msg59170
2008-01-03 22:07:29AstraLumasetfiles: + regen
messages: + msg59167
2008-01-03 21:41:02draghuramsetmessages: + msg59162
2008-01-03 21:35:13gvanrossumsetmessages: + msg59161
2008-01-03 21:30:50AstraLumasetmessages: + msg59159
2008-01-03 20:53:17gvanrossumsetnosy: + gvanrossum
messages: + msg59157
2008-01-03 19:57:07AstraLumasetmessages: + msg59151
2008-01-03 19:55:33AstraLumasetmessages: + msg59150
2008-01-03 19:42:28draghuramsetnosy: + draghuram
messages: + msg59147
2008-01-03 19:26:29AstraLumacreate