<div class="gmail_quote">2012/2/13 Timothy Baldridge <span dir="ltr">&lt;<a href="mailto:tbaldridge@gmail.com">tbaldridge@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I&#39;m in the process of writing a Clojure-&gt;Python bytecode compiler<br>
(<a href="http://github.com/halgari/clojure-py" target="_blank">http://github.com/halgari/clojure-py</a>). The project is going quite<br>
well and runs great on PyPy and CPython. However there is one feature<br>
I&#39;m not quite sure how to implement in PyPy. What I would like, is to<br>
extend &#39;import&#39; so that it can handle .clj files:<br>
<br>
import clojure.core # where there is a file called clojure/core.clj<br>
<br>
Now in CPython I can simply ovewrite __builtins__.__import__ with a<br>
new function that adds additional functionality to __import__.<br>
However, in PyPy we can&#39;t change __builtins__. So is there a better<br>
option? The interop between clojure and python is so good already,<br>
that I&#39;d hate to make users run:<br>
<br>
import clojure<br>
clojure.import(&quot;core.clj&quot;)<br>
<br>
Any ideas?<br></blockquote><div><br></div><div>Have you tried with an import hook? sys.path_hooks is a list of callables</div><div>tried to handle a sys.path item. For example, the zipimporter is already</div><div>implemented as a path_hook, it catches sys.path entries that ends with &quot;.zip&quot;.</div>
<div><br></div><div>You could design a clojureimporter that would handle any entry in sys.path</div><div>which ends with &quot;/closure&quot; (or better, which have a __init__.clj file)</div><div><br></div><div>There is also sys.meta_path, which can be used for further customization,</div>
<div>and may be needed if you want to have both .py and .cjl files in the same directory.</div><div><br></div><div>Both kinds of hooks are normally supported by both CPython and PyPy...</div><div><br></div></div>-- <br>Amaury Forgeot d&#39;Arc<br>