<br><br><div class="gmail_quote">On Sun, Aug 12, 2012 at 6:07 PM, Eric Snow <span dir="ltr"><<a href="mailto:ericsnowcurrently@gmail.com" target="_blank">ericsnowcurrently@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im"><p>On Aug 12, 2012 12:56 PM, "PJ Eby" <<a href="mailto:pje@telecommunity.com" target="_blank">pje@telecommunity.com</a>> wrote:<br>
> I'm not sure if this is directly related or not, but making this<br>
> mechanism support custom compilation for new filename suffixes would<br>
> be nice, especially for various e.g. HTML/XML templating systems that<br>
> compile to Python or bytecode.<br>
><br>
> Specifically, having a way to add a new source suffix (e.g. ".kid",<br>
> ".zpt", etc.) and a matching compilation function, such that it's<br>
> automatically picked up for compilation by both the filesystem and zip<br>
> importers would be awesome. It'd also allow for DSLs and syntax<br>
> experiments using alternative filename extensions.</p>
</div><p>+1</p>
<p>I'm hacking around this right now for a project I'm working on. I definitely do this through the import system. Inserting a look-alike path hook and monkeypatching the cached path entry finders is not difficult, but certainly fragile and less than ideal.</p>
</blockquote><div>Why are you doing that? Can't you just use FileFinder with new loaders and file suffixes? Why do you feel the need to much with any cache? </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<p>Consequently I've been looking into simple and not-so-simple solutions to making it easier to add new suffixes to be handled. The source/pyc-to-code-to-module path during imports is so prevalent and critical that it may benefit from its own model.</p>
</blockquote><div><br></div><div>3.4 will expose more of this. The source-to-code method would get you the transformation that PJE wants while 3.3 already has FileFinder handle the finding of the proper files for you. Toss in a method or two to help in parsing byte-compiled files and writing them and most of the process is then exposed.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p> This is similar to how the path-based import subsystem has its own special-case model. Or source-based imports just need better special-casing in the path-based import subsystem. Perhaps just adding and using sys.source_suffixes as a mapping of suffixes to loader classes.</p>
</blockquote><div><br></div><div>This is starting to get off-topic, but no more adding stuff to sys in regards to import. There is already too much global state that is preventing good encapsulation and we don't need to make it any worse. The more we add to sys in regards to import the farther we get from any import engine solution that we might want to evolve towards.</div>
</div>