Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cython -a flag (to generate yellow-shaded HTML) without command line

Tags:

cython

When you run from the command line

$ cython -a mycode.pyx

you get a really nice HTML "annotation" file with yellow shading to indicate slow python operations vs fast C operations. You also get this same HTML file as a link every time you compile Cython code in Sage. My questions are: (1) Can I get this HTML file if I'm compiling using distutils? (2) Can I get this HTML file if I'm compiling using pyximport? Thanks!!

like image 535
Steve Byrnes Avatar asked Jun 15 '12 22:06

Steve Byrnes


1 Answers

Thanks to larsmans's comment and the Cython email list, I now have many satisfying options to generate the "annotate" HTML file without leaving IPython:

(1) Use subprocess...

import subprocess
subprocess.call(["cython","-a","myfilename.pyx"])

(2) Turn on the global annotate flag in Cython myself, before compiling:

import Cython.Compiler.Options
Cython.Compiler.Options.annotate = True

(3) Pass annotate=True into cythonize() [when using the distutils compilation method].

It seems that pyximport does not have its own direct option for turning on annotation.

like image 53
Steve Byrnes Avatar answered Nov 24 '22 21:11

Steve Byrnes