[Python-Dev] Should there be a way or API for retrieving from a code object a loader method and package file where the code comes from? (original) (raw)
rocky at gnu.org rocky at gnu.org
Tue Dec 23 15:35:20 CET 2008
- Previous message: [Python-Dev] Should there be a way or API for retrieving from a code object a loader method and package file where the code comes from?
- Next message: [Python-Dev] Should there be a way or API for retrieving from a code object a loader method and package file where the code comes from?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Paul Moore writes:
2008/12/23 Rocky Bernstein <rocky at gnu.org>:
Now that there is a package mechanism (are package mechanisms?) like zipimporter that bundle source code into a single file, should the notion of a "file" location should be adjusted to include the package and/or importer?
Check PEP 302 (http://www.python.org/dev/peps/pep-0302/) specifically the get_source (optional) method.
Yes, that's one of the things I was thinking when I wrote:
As best as I can tell, PEP 302 which discussed importer hooks and suggests a standard way to get file data.
And by "suggests" I meant was implying that yes I know this is optional.
It's not exactly what you describe, but it may help.
Yes, it's not exactly what is desired.
Please note that it's optional - if you loaded the code from a zipfile containing only bytecode files, there is no source to get, so you have to be prepared for that case. But if the source is available, this should give you a way of getting to it.
What is wanted is a uniform way get and describe a file location from a code object that takes into account the file might be a member of an archive.
Are there even guidelines for saying what string goes into a code object's co_filename? Clearly it should be related to the source code that generated the code, and there are various conventions that seem to exist when the code comes from an "eval" or an "exec".
But empirically it seems as though there's some variation. It could be an absolute file or a file with no root directory specified. (But is it possible to have things like "." and ".."?). And in the case of a member of a package what happens? Should it be just the member without the package? Or should it include the package name like /usr/lib/python2.5/site-packages/tracer-0.1.0-py2.5.egg/tracer.py ?
Or be unspecified? If left unspecified as I gather it is now, it makes it more important to have some sort of common routine to be able to pick out the archive part in a filesystem from the member name inside the archive.
Paul.
- Previous message: [Python-Dev] Should there be a way or API for retrieving from a code object a loader method and package file where the code comes from?
- Next message: [Python-Dev] Should there be a way or API for retrieving from a code object a loader method and package file where the code comes from?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]