robertwb / issues-import-test

0 stars 0 forks source link

Runtime Compilation of a module [patch] #146

Open robertwb opened 7 years ago

robertwb commented 7 years ago

Reported by bfredl on 11 Jan 2012 18:26 UTC It would be useful if there was a function that took a string of cython code, compiled it as a .pyx file, and then returned a live cython module. Now, cython.inline sort of does this, but it also preprocesses the code under the assumption that it is a function-level chunk, and then excutes this chunck, automagically fetching unbound variables from the invoking envirionment.

While this is very handy in many applications, I would also find it useful at runtime compile many defs/cdefs/cpdefs at the same time, and manually control passing in/out data. The main use case would be using cython as a backend for dynamic code generation.

First I tried to improve cython.inline to make this easier, but it felt like constructing a better screwdriver in order to hammer in a nail. Instead I wrote cython.compile_module (mostly reusing cython.inline) which just compiles a string as if it was a .pyx file, returning the module object. Patch attached.

Migrated-From: http://trac.cython.org/ticket/759

robertwb commented 7 years ago

Comment by scoder on 26 Jan 2013 10:54 UTC A couple of minor comments:

That being said, I think this feature is generally a nice thing to have. Github is a better place to provide patches, though, as it simplifies comments and discussions on pull requests.

robertwb commented 7 years ago

Modified by scoder on 26 Jan 2013 10:54 UTC Set cc to bfredl, scoder.