[PATCH 1 of 3 RFC] mercurial: implement a source transforming module loader on Python 3

Simon King simon at simonking.org.uk
Mon May 16 12:13:46 EDT 2016


On Mon, May 16, 2016 at 4:50 PM, Gregory Szorc <gregory.szorc at gmail.com> wrote:
>
>
>> On May 16, 2016, at 08:43, Simon King <simon at simonking.org.uk> wrote:
>>
>> I don't think that's supposed to happen, is it? Python should
>> automatically invalidate .pyc files based on a magic number that
>> changes when the format changes:
>>
>> https://hg.python.org/cpython/file/2.7/Python/import.c#l31
>
> The problem is we're inserting code between file reading and code generation - code that Python's importers don't know about. Python assumes file content gets converted into code in a deterministic manner that is defined by the Python distribution itself. We're outside of that, so we need to provide our own cache validation checking.
>

Yes, sorry, my reply was to timeless' comment about switching between
Py2.6 and Py2.7 causing problems. Invalidating pyc files when we
update this encoding hack is certainly more complicated.

The converter could insert a module-level constant into each rewritten
file indicating the converter version that was used, but I guess you'd
need a custom module loader to inspect those files and compare that
constant with the *current* version.

Simon


More information about the Mercurial-devel mailing list