sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.47k stars 485 forks source link

Allow Cython compilation to open a web browser containing the annotated HTML file #38946

Open user202729 opened 2 weeks ago

user202729 commented 2 weeks ago

As in the title.

I think this is a rather common use case, to investigate whether the code does get the desired speedup.

Remark: there's sage.misc.viewer.browser() which could be used instead, but then a lot of existing code in SageMath uses webbrowser.open() anyway?

:memo: Checklist

Dependencies

Depends on #38945 .

github-actions[bot] commented 2 weeks ago

Documentation preview for this PR (built with commit 99bce53524a82b506bde489951be933a17f5cba4; changes) is ready! :tada: This preview will update shortly after each push to this PR.

kwankyu commented 2 weeks ago

This looks nice.

It would be nicer if the new argument view_annotate is accepted to the cell magic %%cython. For example,

%%cython view_annotate=True
def f(int n):
...

or

%%cython --view_annotate
def f(int n):
...

The cell magic is defined in https://github.com/sagemath/sage/blob/develop/src/sage/repl/ipython_extension.py. Find the line

def cython(self, line, cell):

line seems to accept the part after "%%cython". So we may use it to provide arguments to the cython function. What do you think?

user202729 commented 2 weeks ago

Already did that in https://github.com/sagemath/sage/pull/38945 . (though whichever being merged first need to be modified to incorporate the other…)

kwankyu commented 2 weeks ago

You may set #38945 as a dependency and merge it here.

kwankyu commented 2 weeks ago

and instead of

- ``line`` -- parsed as keyword arguments. See :func:`~sage.misc.cython.cython` for details.

you may at least list the possible arguments for users' convenience, leaving details to sage.misc.cython.cython .