Re: [cython-users] Cython -a flag (to generate yellow-shaded HTML) without command line

1,211 views
Skip to first unread message

Stefan Behnel

unread,
Jun 17, 2012, 1:45:05 PM6/17/12
to cython...@googlegroups.com
SteveB, 17.06.2012 19:34:
> (copied from
> http://stackoverflow.com/questions/11058933/cython-a-flag-to-generate-yellow-shaded-html-without-command-line
> )
>
> When you run from the command prompt "cython -a ..." you get a really nice
> HTML 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?

Yes, pass "annotate=True" into cythonize().


> (2) Can I get this HTML file if I'm
> compiling using pyximport? Thanks in advance!!

I don't think there's a direct option for that in pyximport, but you can
always import Cython yourself and set the option globally in the Options
module.

Stefan

Ian Bell

unread,
Jun 17, 2012, 2:41:43 PM6/17/12
to cython...@googlegroups.com
On Sun, Jun 17, 2012 at 10:45 AM, Stefan Behnel <stef...@behnel.de> wrote:
SteveB, 17.06.2012 19:34:
> (copied from
> http://stackoverflow.com/questions/11058933/cython-a-flag-to-generate-yellow-shaded-html-without-command-line
> )
>
> When you run from the command prompt "cython -a ..." you get a really nice
> HTML 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?

Yes, pass "annotate=True" into cythonize().

Or if not using cythonize(), you can set the flag 

Cython.Compiler.Options.annotate = True

which is not documented anywhere as far as I can see

Bradley Froehle

unread,
Dec 6, 2012, 12:26:36 PM12/6/12
to cython...@googlegroups.com
I've gotten it to work by using `ext_modules = cythonize(..., annotate=True)` as shown on  http://docs.cython.org/src/reference/compilation.html

On Wednesday, December 5, 2012 11:01:19 AM UTC-8, John Tyree wrote:
When I was digging through the source on Github, it seemed to me that you should be able to pass cython_directives={"annontate": True} as kwarg in Cython.distutils.Extension, but when I tried it it didn't work. Any thoughts?

-John

Bradley Froehle

unread,
Dec 7, 2012, 2:07:19 PM12/7/12
to cython...@googlegroups.com
Fundamentally the distutils Extension class doesn't know anything about Cython unless you use the Cython provided build_ext command.  I've found its usually easier to use cythonize which processes the pyx source and returns an Extension that distutils knows how to process.

Only drawback is that the pyx -> c conversion is run, even if you do something like `python setup.py clean`.

On Friday, December 7, 2012 4:55:32 AM UTC-8, John Tyree wrote:
Yes that does work. I was just wondering about the Extension class specifically. I suppose in the end it doesn't matter. I should probably just use "cythonize" anyway.

Robert Bradshaw

unread,
Dec 7, 2012, 2:12:23 PM12/7/12
to cython...@googlegroups.com
On Fri, Dec 7, 2012 at 11:07 AM, Bradley Froehle <brad.f...@gmail.com> wrote:
> Fundamentally the distutils Extension class doesn't know anything about
> Cython unless you use the Cython provided build_ext command. I've found its
> usually easier to use cythonize which processes the pyx source and returns
> an Extension that distutils knows how to process.
>
> Only drawback is that the pyx -> c conversion is run, even if you do
> something like `python setup.py clean`.

A patch solving this issue would be very welcome! (I'm not sure the
best way to detect this...)
Reply all
Reply to author
Forward
0 new messages