Skip to content

Conversation

kwankyu
Copy link
Collaborator

@kwankyu kwankyu commented Apr 27, 2024

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,

  • If SAGE_DOC_SERVER_URL is set, the url is used;
  • else if local sage documentation is installed, a doc http server with port SAGE_DOC_LOCAL_PORT starts. If the port is 0 (the default), then a random port is selected by the system and stored to the environment variable;
  • else the online official documentation website https://doc.sagemath.org is used

for the help menu of the Jupyter notebook.

Fixes #34794.

📝 Checklist

  • The title is concise and informative.
  • The description explains in detail what this PR is about.
  • 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

Copy link

github-actions bot commented Apr 27, 2024

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

@kwankyu kwankyu force-pushed the fix/34794/run-doc-server-along-with-jupyter branch from eb1fb4a to 22025a8 Compare April 27, 2024 23:16
Copy link
Contributor

@culler culler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@kwankyu
Copy link
Collaborator Author

kwankyu commented Apr 28, 2024

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
Copy link
Collaborator Author

kwankyu commented Apr 28, 2024

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

@kwankyu
Copy link
Collaborator Author

kwankyu commented Apr 28, 2024

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

@kwankyu
Copy link
Collaborator Author

kwankyu commented Apr 28, 2024

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
Copy link
Collaborator Author

kwankyu commented May 11, 2024

ping @culler @nbruin @mkoeppe

@mkoeppe
Copy link
Contributor

mkoeppe commented May 11, 2024

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
Copy link
Collaborator Author

kwankyu commented May 11, 2024

Thanks!!

@kwankyu
Copy link
Collaborator Author

kwankyu commented May 11, 2024

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

vbraun pushed a commit to vbraun/sage that referenced this pull request May 12, 2024
sagemathgh-37878: Run sage doc server for jupyterlab 
    
<!-- ^ Please provide a concise and informative title. -->
<!-- ^ Don't put issue numbers in the title, do this in the PR
description below. -->
<!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method
to calculate 1 + 2". -->
<!-- v Describe your changes below in detail. -->
<!-- v Why is this change required? What problem does it solve? -->
<!-- v If this PR resolves an open issue, please link to it here. For
example, "Fixes sagemath#12345". -->

Reopen sagemath#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,
- If `SAGE_DOC_SERVER_URL` is set, the url is used;
- else if local sage documentation is installed, a doc http server with
port `SAGE_DOC_LOCAL_PORT` starts. If the port is 0 (the default), then
a random port is selected by the system and stored to the environment
variable;
- else the online official documentation website
https://doc.sagemath.org is used

for the help menu of the Jupyter notebook.

Fixes sagemath#34794.

### 📝 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.
- [ ] 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#37878
Reported by: Kwankyu Lee
Reviewer(s): Kwankyu Lee, Marc Culler
@vbraun vbraun merged commit 39907fa into sagemath:develop May 12, 2024
vbraun pushed a commit to vbraun/sage that referenced this pull request May 18, 2024
sagemathgh-38005: Fix Help menu breakdown in external jupyterlab case
    
<!-- ^ Please provide a concise and informative title. -->
<!-- ^ Don't put issue numbers in the title, do this in the PR
description below. -->
<!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method
to calculate 1 + 2". -->
<!-- v Describe your changes below in detail. -->
<!-- v Why is this change required? What problem does it solve? -->
<!-- v If this PR resolves an open issue, please link to it here. For
example, "Fixes sagemath#12345". -->

sagemath#37878 introduced a local documentation server for jupyterlab. But it
missed a case for which the Help menu of jupyterlab may break down.

In the setup explained in
https://doc.sagemath.org/html/en/installation/launching.html#setting-up-
sagemath-as-a-jupyter-kernel-in-an-existing-jupyter-notebook-or-
jupyterlab-installation, external jupyterlab is launched and connected
to sage kernel. In this case, the local doc server does not run, but the
Help menu of the jupyterlab still expects a local doc server, and thus
the Help menu does not work well.

In this PR, local doc server is detected by testing the port number, and
the Help menu uses the online official documentation if local doc server
is not running.

### 📝 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.
- [ ] 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#38005
Reported by: Kwankyu Lee
Reviewer(s):
vbraun pushed a commit to vbraun/sage that referenced this pull request May 18, 2024
sagemathgh-38005: Fix Help menu breakdown in external jupyterlab case
    
<!-- ^ Please provide a concise and informative title. -->
<!-- ^ Don't put issue numbers in the title, do this in the PR
description below. -->
<!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method
to calculate 1 + 2". -->
<!-- v Describe your changes below in detail. -->
<!-- v Why is this change required? What problem does it solve? -->
<!-- v If this PR resolves an open issue, please link to it here. For
example, "Fixes sagemath#12345". -->

sagemath#37878 introduced a local documentation server for jupyterlab. But it
missed a case for which the Help menu of jupyterlab may break down.

In the setup explained in
https://doc.sagemath.org/html/en/installation/launching.html#setting-up-
sagemath-as-a-jupyter-kernel-in-an-existing-jupyter-notebook-or-
jupyterlab-installation, external jupyterlab is launched and connected
to sage kernel. In this case, the local doc server does not run, but the
Help menu of the jupyterlab still expects a local doc server, and thus
the Help menu does not work well.

In this PR, local doc server is detected by testing the port number, and
the Help menu uses the online official documentation if local doc server
is not running.

### 📝 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.
- [ ] 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#38005
Reported by: Kwankyu Lee
Reviewer(s):
vbraun pushed a commit to vbraun/sage that referenced this pull request May 24, 2024
sagemathgh-38005: Fix Help menu breakdown in external jupyterlab case
    
<!-- ^ Please provide a concise and informative title. -->
<!-- ^ Don't put issue numbers in the title, do this in the PR
description below. -->
<!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method
to calculate 1 + 2". -->
<!-- v Describe your changes below in detail. -->
<!-- v Why is this change required? What problem does it solve? -->
<!-- v If this PR resolves an open issue, please link to it here. For
example, "Fixes sagemath#12345". -->

sagemath#37878 introduced a local documentation server for jupyterlab. But it
missed a case for which the Help menu of jupyterlab may break down.

In the setup explained in
https://doc.sagemath.org/html/en/installation/launching.html#setting-up-
sagemath-as-a-jupyter-kernel-in-an-existing-jupyter-notebook-or-
jupyterlab-installation, external jupyterlab is launched and connected
to sage kernel. In this case, the local doc server does not run, but the
Help menu of the jupyterlab still expects a local doc server, and thus
the Help menu does not work well.

In this PR, local doc server is detected by testing the port number, and
the Help menu uses the online official documentation if local doc server
is not running.

### 📝 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.
- [ ] 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#38005
Reported by: Kwankyu Lee
Reviewer(s):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Run doc server along with jupyter server
4 participants