sagemath / sage

Main repository of SageMath. Now open for Issues and Pull Requests.
https://www.sagemath.org
Other
1.08k stars 394 forks source link

Run sage doc server for jupyterlab #37878

Closed kwankyu closed 1 day ago

kwankyu commented 2 weeks ago

Reopen #35139 because of the renewed interest: https://groups.google.com/g/sage-devel/c/kzSWB8ps7VA

New environment variables added to sage.env:

SAGE_DOC_SERVER_URL = var("SAGE_DOC_SERVER_URL")
SAGE_DOC_LOCAL_PORT = var("SAGE_DOC_LOCAL_PORT", "0")

When Jupyter notebook launches,

for the help menu of the Jupyter notebook.

Fixes #34794.

:memo: Checklist

:hourglass: Dependencies

github-actions[bot] commented 2 weeks ago

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

kwankyu commented 2 weeks ago

Why do you use 8000 for the default port? That is the http port > 1024 which is most likely to be used by another local http server. If you use 0 as the default port then the system will assign a random unused port > 1024. That way you won't have to worry about port conflicts.

But then how can I know the port randomly assigned?

kwankyu commented 2 weeks ago

More precisely, how kernel.py finds the port number?

kwankyu commented 2 weeks ago

server.server_address[-1] gives the port. Then I need to figure out how to pass this number to kernel.py...

kwankyu commented 2 weeks ago

Why do you use 8000 for the default port? That is the http port > 1024 which is most likely to be used by another local http server. If you use 0 as the default port then the system will assign a random unused port > 1024. That way you won't have to worry about port conflicts.

I also would recommend using 127.0.0.1 in the url, rather than localhost. The reason is that a (rogue) DNS nameserver could, in principle, assign an arbitrary IP address to the name localhost. But the IP address 127.0.0.1 always refers to the loopback interface and would never trigger a DNS lookup.

Done. Thanks for the tips!

kwankyu commented 2 days ago

ping @culler @nbruin @mkoeppe

mkoeppe commented 2 days ago

Looks like a reasonable approach. After #36730, one might discuss if the doc server should be the responsibility of the sagemath_doc_html distribution, but for now this looks good.

kwankyu commented 2 days ago

Thanks!!

kwankyu commented 2 days ago

Bump up priority since the original poster of the issue regards it as a bug.