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

Steve Byrnes picture Steve Byrnes · Jun 16, 2012 · Viewed 9.2k times · Source

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!!

Answer

Steve Byrnes picture Steve Byrnes · Jun 18, 2012

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.