[Python-Dev] PEP 3147: PYC Repository Directories

Barry Warsaw barry at python.org
Sun Feb 7 18:48:10 CET 2010


On Feb 06, 2010, at 02:20 PM, Guido van Rossum wrote:

>> Upon further reflection, I agree.  __file__ also points to the source in
>> Python 2.7.
>
>Not in the 2.7 svn repo I have access to. It still points to the .pyc
>file if it was used.

Ah, I was fooled by a missing pyc file.  Run it a second time and you're
right, it points to the pyc.

>And I propose not to disturb this in 2.7, at least not by default. I'm
>fine though with a flag or distro-overridable config setting to change
>this behavior.

Cool.  I'm not sure this is absolutely necessary for Debian/Ubuntu, so I'll
call YAGNI on it for 2.x (until and unless it isn't ;).

>> Do we need an attribute to point to the compiled bytecode file?
>
>I think we do. Quite unrelated to this discussion I have a use case
>for knowing easily whether a module was actually loaded from bytecode
>or not -- but I also have a need for __file__ to point to the source.
>So having both __file__ and __compiled__ makes sense to me.

__compiled__ or __cached__?  I like the latter but don't have strong feelings
about it either way.

>When there is no source code but only bytecode I am file with both
>pointing to the bytecode; in that case I presume that the bytecode is
>not in a __pyr__ subdirectory. For dynamically loaded extension
>modules I think both should be left unset, and some other __xxx__
>variable could point to the .so or .dll file. FWIW the most common use
>case for __file__ is probably to find data files relative to it. Since
>the data won't be in the __pyr__ directory we couldn't make __file__
>point to the __pyr__/....pyc file without much code breakage.

The other main use case for having such an attribute on extension modules is
diagnostics.  I want to be able to find out where on the file system a .so
actually lives:

Python 2.7a3+ (trunk:78030, Feb  6 2010, 15:18:29) 
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import _socket
>>> _socket.__file__
'/home/barry/projects/python/trunk/build/lib.linux-x86_64-2.7/_socket.so'

>(Yes, I am still in favor of the folder-per-folder model.)

Cool.
-Barry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-dev/attachments/20100207/237c3bf2/attachment.pgp>


More information about the Python-Dev mailing list