-
-
Notifications
You must be signed in to change notification settings - Fork 503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow Cython compilation to open a web browser containing the annotated HTML file #38946
Conversation
Documentation preview for this PR (built with commit 6116696; changes) is ready! 🎉 |
This looks nice. It would be nicer if the new argument
or
The cell magic is defined in https://github.com/sagemath/sage/blob/develop/src/sage/repl/ipython_extension.py. Find the line
|
Already did that in #38945 . (though whichever being merged first need to be modified to incorporate the other…) |
You may set #38945 as a dependency and merge it here. |
and instead of
you may at least list the possible arguments for users' convenience, leaving details to |
b8d3e69
to
99bce53
Compare
I learnt it's possible to view the result in the Sage notebook (if Jupyter-based notebook GUI is used) from looking at cython-provided magic, so I implement that here. |
269c4d8
to
0447579
Compare
0447579
to
0fc93c2
Compare
@kwankyu Can you review the PR? Thanks. |
Conflicts? |
Huh, that only come from the new commits for 10.6.beta2 today. This one is pretty harmless. |
On comand line (on mac),
does not open a web browser. |
Not sure what's going on, but probably doesn't have anything to do with the code. There are some complaints e.g. https://stackoverflow.com/questions/65981130/python-webbrowser-module-doesnt-work-on-terminal or python/cpython#69143 You can try If it does work, maybe you can try this patch diff --git a/src/sage/misc/cython.py b/src/sage/misc/cython.py
index fde36372712..3689c896b4a 100644
--- a/src/sage/misc/cython.py
+++ b/src/sage/misc/cython.py
@@ -81,7 +81,7 @@ sequence_number = {}
def cython(filename, verbose=0, compile_message=False,
use_cache=False, create_local_c_file=False, annotate=True, view_annotate=False,
- view_annotate_callback=webbrowser.open, sage_namespace=True, create_local_so_file=False):
+ view_annotate_callback=lambda x: webbrowser.open("file://" + x), sage_namespace=True, create_local_so_file=False):
r"""
Compile a Cython file. This converts a Cython file to a C (or C++ file),
and then compiles that. The .c file and the .so file are |
Yes. That does the trick. For readability, you may want to store the lambda function to a variable first, before line 82. |
I come across #33931 , while it looks like the PR is stalled it is recommended to use webbrowser over |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. LGTM.
…aining the annotated HTML file 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? ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. (not aware of one) - [x] I have created tests covering the changes. - [x] I have updated the documentation and checked the documentation preview. ### Dependencies Depends on sagemath#38945 . URL: sagemath#38946 Reported by: user202729 Reviewer(s): Kwankyu Lee, user202729
* for some reason the proper header is needed to open the HTML file on my machine. * It's reported that `webbrowser.open()` doesn't work when called on a file path, rather an URI is needed (sagemath#38946) ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [x] I have updated the documentation and checked the documentation preview. (not needed) ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> URL: sagemath#39193 Reported by: user202729 Reviewer(s): Martin Rubey
* for some reason the proper header is needed to open the HTML file on my machine. * It's reported that `webbrowser.open()` doesn't work when called on a file path, rather an URI is needed (sagemath#38946) ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [x] I have updated the documentation and checked the documentation preview. (not needed) ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> URL: sagemath#39193 Reported by: user202729 Reviewer(s): Martin Rubey
A test is failing here
|
Should be fixed in #39282 |
Fixes issue pointed out in sagemath#38946 (comment) ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> URL: sagemath#39282 Reported by: user202729 Reviewer(s): Frédéric Chapoton
Fixes issue pointed out in sagemath#38946 (comment) ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> URL: sagemath#39282 Reported by: user202729 Reviewer(s): Frédéric Chapoton
Fixes issue pointed out in sagemath#38946 (comment) ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> URL: sagemath#39282 Reported by: user202729 Reviewer(s): Frédéric Chapoton
Fixes issue pointed out in sagemath#38946 (comment) ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> URL: sagemath#39282 Reported by: user202729 Reviewer(s): Frédéric Chapoton
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 useswebbrowser.open()
anyway?📝 Checklist
Dependencies
Depends on #38945 .