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.

classification
Title: re.match.func_code.co_filename returns "re.py"
Type: behavior Stage:
Components: None Versions: 3rd party
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: Nosy List: christian.heimes, gvanrossum, thekorn
Priority: normal Keywords:

Created on 2007-12-19 22:55 by thekorn, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (9)
msg58838 - (view) Author: Markus Korn (thekorn) Date: 2007-12-19 23:02
re.match.func_code.co_filename returns "re.py"
I expect something like "/usr/lib/python2.5/re.py"

This causes issues in the "inspect"-module like:
>>> inspect.getabsfile(re.match)
>>> '<current-dir>/re.py'

Sorry, this is my first python-bugreport, please ping me if you need any
further details.

Markus
msg58840 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2007-12-19 23:05
I can't reproduce this.

How did you install Python?

Python 2.5.2a0 (release25-maint, Nov 27 2007, 14:00:00) 
[GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> re.match.func_code.co_filename
'/usr/local/lib/python2.5/re.py'
>>>
msg58841 - (view) Author: Markus Korn (thekorn) Date: 2007-12-19 23:13
Thanks for your fast reply.
I'm using the python package of ubuntu-feisty,
$ python
Python 2.5.1 (r251:54863, Oct  5 2007, 13:50:07) 
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> re.match.func_code.co_filename
're.py'
>>> 

So maybe it's ubuntu-specific!?
msg58845 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2007-12-19 23:55
Then I suggest you talk to the Ubuntu developers or whoever packaged
Python 2.5.1 for it.
msg58855 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2007-12-20 05:00
I'm able to reproduce the problem on Ubuntu. It's probably caused by
their compile step in python2.5.postinst:

        cd /usr/lib/python2.5
        files=$(dpkg -L python2.5 | sed -n
'/\.py$/s,^/usr/lib/python2.5/,,p')
        /usr/bin/python2.5 /usr/lib/python2.5/py_compile.py $files
        if grep -sq '^byte-compile[^#]*optimize'
/etc/python/debian_config; then
            /usr/bin/python2.5 -O /usr/lib/python2.5/py_compile.py $files
        fi

It's compiling the py files relative to /usr/lib/python2.5. Please note
that the behavior of py_compile.py is intended. The relative path is
useful for people who pack the compiled files into a zip file or egg file.
msg58856 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2007-12-20 05:12
Well, if they do that, they apparently break inspect.py. Should they
be doing that? Why are they doing that? Can you contact the Ubuntu
folks about this?
msg58861 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2007-12-20 05:58
Guido van Rossum wrote:
> Guido van Rossum added the comment:
> 
> Well, if they do that, they apparently break inspect.py. Should they
> be doing that? Why are they doing that? Can you contact the Ubuntu
> folks about this?

No, they shouldn't. It may be plain ignorance or they have a hidden
agenda. I'm going to contact the Debian maintainers. I'm sure the Ubuntu
guys have copied the behavior from Debian.

Christian
msg58863 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2007-12-20 06:13
I proposed to the maintainer that he should change one line to 

    dpkg -L python2.5 | sed -n '/\.py$/p'

In the mean time you can easily fix the issue with:

sudo find /usr/lib/python2.5 -name '*.py[co]' -delete
sudo python2.5 /usr/lib/python2.5/compileall.py /usr/lib/python2.5/
sudo python2.5 -O /usr/lib/python2.5/compileall.py /usr/lib/python2.5/
msg58915 - (view) Author: Markus Korn (thekorn) Date: 2007-12-20 18:42
Thanks a lot, this works.

Markus
History
Date User Action Args
2022-04-11 14:56:29adminsetgithub: 46006
2008-01-04 01:11:43gvanrossumlinkissue1728 superseder
2007-12-20 18:42:23thekornsetmessages: + msg58915
2007-12-20 13:43:40georg.brandlsetstatus: pending -> closed
versions: + 3rd party, - Python 2.5
2007-12-20 06:13:57christian.heimessetmessages: + msg58863
2007-12-20 05:58:18christian.heimessetmessages: + msg58861
2007-12-20 05:12:06gvanrossumsetmessages: + msg58856
2007-12-20 05:00:12christian.heimessetstatus: open -> pending
nosy: + christian.heimes
resolution: works for me
messages: + msg58855
2007-12-19 23:55:14gvanrossumsetmessages: + msg58845
2007-12-19 23:13:59thekornsetmessages: + msg58841
2007-12-19 23:05:51gvanrossumsetnosy: + gvanrossum
messages: + msg58840
2007-12-19 23:02:13thekornsetmessages: + msg58838
2007-12-19 22:55:20thekorncreate