Repository navigation
Handle tempita templed cython files - #1924
Conversation
|
@ev-br just a naive question: what's the interest of using templates instead of global variables? |
|
@emmanuelle If you take a look at the PR referenced, you'll find a section of code that is generate by a for loop: While one could potentially use variables to switch out between copied and slightly modified code sections, this is much cleaner. |
| from_filename = tempita.Template.from_filename | ||
| template = from_filename(fromfile, encoding=sys.getdefaultencoding()) | ||
| pyxcontent = template.substitute() | ||
| assert fromfile.endswith('.pyx.in') |
There was a problem hiding this comment.
Assert is probably best replaced with a raise ValueError
|
Some minor style comments, but looks OK to me. |
|
@emmanuelle To add to what Stefan said: in this context, a dozen lines of a template helps to avoid either ~100 lines of repetetive boilerplate (check the .pyx file generated from .pyx.in during the build) or a large perf hit due to looping at run time (this is most useful when the loop is over a python data structure). In gh-1923 there are two templated routines, and together they account for about an order of magnitude speedup. |
|
LGTM, and I think for Stéfan as well, therefore merging. |
Handle tempita templed cython files
It got botched sometime around reviewing/merging/rebasing of scikit-imagegh-1924
A companion to #1923
The code here is basically adopted from https://github.com/scipy/scipy/blob/master/tools/cythonize.py