2012/2/13 Timothy Baldridge <tbaldri...@gmail.com> > I'm in the process of writing a Clojure->Python bytecode compiler > (http://github.com/halgari/clojure-py). The project is going quite > well and runs great on PyPy and CPython. However there is one feature > I'm not quite sure how to implement in PyPy. What I would like, is to > extend 'import' so that it can handle .clj files: > > import clojure.core # where there is a file called clojure/core.clj > > Now in CPython I can simply ovewrite __builtins__.__import__ with a > new function that adds additional functionality to __import__. > However, in PyPy we can't change __builtins__. So is there a better > option? The interop between clojure and python is so good already, > that I'd hate to make users run: > > import clojure > clojure.import("core.clj") > > Any ideas? >
Have you tried with an import hook? sys.path_hooks is a list of callables tried to handle a sys.path item. For example, the zipimporter is already implemented as a path_hook, it catches sys.path entries that ends with ".zip". You could design a clojureimporter that would handle any entry in sys.path which ends with "/closure" (or better, which have a __init__.clj file) There is also sys.meta_path, which can be used for further customization, and may be needed if you want to have both .py and .cjl files in the same directory. Both kinds of hooks are normally supported by both CPython and PyPy... -- Amaury Forgeot d'Arc
_______________________________________________ pypy-dev mailing list pypy-dev@python.org http://mail.python.org/mailman/listinfo/pypy-dev