On 5/9/09 9:12 AM, Martin Aspeli wrote:
> Chris McDonough wrote:
>> On 5/9/09 8:50 AM, Malthe Borch wrote:
>>> As a general improvement (in terms of clarity) and as part of the
>>> efforts of getting Chameleon working on GAE, I've begun reworking the
>>> compilation stage.
>>> If not explicitly disabled (using ``CHAMELEON_CACHE=0``), template
>>> files (ending in .pt) will be compiled with the result written to a
>>> Python-module with the same filename (ending in .pt.py); Python will
>>> of course attempt to write a byte-code compilation (ending in
>>> .pt.pyc), which will guarantee good performance when restarting the
>>> system.
>>> Then,
>>> On template instantiation:
>>> 1) If the ``CHAMELEON_EAGER`` flag is enabled, parse template source
>>> immediately.
>>> 2) Load the template source module.
>>> 3) If the ``CHAMELEON_STATIC`` flag is enabled, compile into
>>> one-method-fits-all-arguments render methods for main template and
>>> each available macro (if required).
>>> On render:
>>> 4) If the ``CHAMELEON_STATIC`` flag is enabled, collapse
>>> keyword-arguments into dynamic context (econtext).
>>> On compilation:
>>> 5) If the "render call signature" (keyword arguments and macro name)
>>> matches an already compiled render-method, return it.
>>> Else:
>>> 6) Compile template (to source string).
>>> 7) Append to template source module.
>>> 8) Reload template source module and return render-method.
>> I've lost track of what a lot of this means (particularly wrt 
>> but the stuff I do understand sounds pretty good to me.
>> At a higher level, let me try to repeat the use case here and tell me if I 
>> have
>> it right:
>> - On template instantiation (at least in eager mode and unless
>>     CHAMELEON_CACHE=0), a .py file will be written next to the
>>     template file being instantiated.
>> - The Chameleon code that actually performs rendering will
>>     try to find the .py file via some importy sort of thing.
>> - Python will write the .pyc file.
>> - When we want to deploy to GAE or other platforms without
>>     instantiation/compilation support, we'll just check in
>>     the .py files (or maybe even the .pyc files) and
>>     push them up.  The instantiation code won't ever need
>>     to do the compilation step.
> It'd be nice if there was a way to name the files that meant people
> won't accidentally commit a bunch of "compiled" .py files that may then
> end up conflicting later.

Maybe there could be a mode to compile template files directly to .pyc for 
that wanted it.  But if it complicated Chameleon at all to do so, I'd much 
rather say to those people "don't check in .pt.py files" than have 500 lines of 
source to enforce it.

- C
Repoze-dev mailing list

Reply via email to