Skip to content
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

Revive sage live doc using jupyter-sphinx #36144

Merged
merged 42 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
8121580
Rework sage live doc
kwankyu Aug 27, 2023
19c1c09
Style activate button
kwankyu Aug 27, 2023
62928db
Fix activate button
kwankyu Aug 28, 2023
6ae42f5
Fix a typo
kwankyu Aug 28, 2023
12afe87
Fix the patch to jupyter-sphinx
kwankyu Aug 28, 2023
fd494e7
Adjust css styles of thebe elements
kwankyu Aug 28, 2023
fc84c30
Showcase live doc on a-tour-of-sage
kwankyu Aug 28, 2023
5f4dcb1
More edits on a-tour-of-Sage
kwankyu Aug 28, 2023
8bb20a6
Support furo dark mode
kwankyu Aug 29, 2023
27977dc
Fine fixes
kwankyu Aug 30, 2023
482d51f
Minor edits to the front of sage doc
kwankyu Aug 30, 2023
fafce5c
Add more comments to renamed jupyter-sphinx-furo.js
kwankyu Aug 30, 2023
910e866
Activate live doc in github doc previews
kwankyu Sep 1, 2023
5f8fb1a
Adjust button styles
kwankyu Sep 3, 2023
b5ff41a
Minimize the patch on jupyter-sphinx
kwankyu Sep 4, 2023
1ec45d6
Fix doctests
kwankyu Sep 4, 2023
a5dd948
Fix a doctest
kwankyu Sep 4, 2023
da82502
Allow custom binder repo
kwankyu Sep 4, 2023
225446f
%display latex is the default
kwankyu Sep 8, 2023
612d396
Use unofficial binder repo temporarily
kwankyu Sep 8, 2023
49dfc56
Minor css tweak
kwankyu Sep 9, 2023
7102fe0
Use the official thing
kwankyu Sep 9, 2023
747f3c5
Edit installation doc
kwankyu Sep 13, 2023
59ccc74
More edits of installation guide
kwankyu Sep 13, 2023
1061ab5
Use binder repo sagemath/sage-binder-env/dev
kwankyu Sep 14, 2023
d72bc2a
Fix thebe config error
kwankyu Sep 14, 2023
f80b252
Binder repo branch part can have slashes
kwankyu Sep 15, 2023
d644d93
Merge branch 'develop' into p/36144
kwankyu Sep 16, 2023
3fbf531
Edit doc
kwankyu Sep 16, 2023
b5c20e8
Merge branch 'develop' into p/36144/p/rework-on-live-sage-documentation
kwankyu Sep 25, 2023
91c6fa5
Merge branch 'develop' into p/36144/p/rework-on-live-sage-documentation
kwankyu Oct 3, 2023
c21421f
Show kernel status
kwankyu Oct 4, 2023
5b98e92
Merge branch 'develop' into p/36144/p/rework-on-live-sage-documentation
kwankyu Oct 18, 2023
f833de2
Merge branch 'develop' into p/36144/p/rework-on-live-sage-documentation
kwankyu Oct 24, 2023
ffa0af9
Fix for auto mode
kwankyu Oct 25, 2023
51fb8a0
Fix auto mode also in javascript
kwankyu Oct 25, 2023
b516acc
More edits on a-tour-of-sage
kwankyu Oct 25, 2023
2a150fb
Make auto mode behave according to system preference
kwankyu Oct 26, 2023
f592be0
Patch jupyter-sphinx a bit more
kwankyu Oct 26, 2023
33205e4
Fixes for conda failures
kwankyu Oct 26, 2023
146d170
Fix jupyter-sphinx css for dark mode
kwankyu Oct 26, 2023
857741c
Live doc for CI is left for further discussion
kwankyu Oct 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/doc-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ jobs:
run: |
set -ex
export SAGE_USE_CDNS=yes
export SAGE_LIVE_DOC=yes
export SAGE_JUPYTER_SERVER=binder:sagemath/sage-binder-env/dev
mv /sage/local/share/doc/sage/html/en/.git /sage/.git-doc
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should activate it in the doc-build workflow only on pushes to release tags.

Elsewhere, in particular in a PR, I think it is problematic that the live doc uses a Sage version that is unrelated to the tested branch!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right.

I will change this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

How we will incorporate live doc to our ci (if ever) will be discussed separately. So I will remove the two lines.

But as this PR now needs review, I will keep the lines for now. If it is decided to merge this PR, then I will immediately push a commit to remove them.

Copy link
Contributor

Choose a reason for hiding this comment

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

To conditionalize its use in "build.yml" , one could use $GITHUB_REF https://docs.github.com/en/actions/learn-github-actions/variables

make doc-clean doc-uninstall
mkdir -p /sage/local/share/doc/sage/html/en/ && mv /sage/.git-doc /sage/local/share/doc/sage/html/en/.git
Expand Down
6 changes: 3 additions & 3 deletions build/pkgs/jupyter_sphinx/checksums.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tarball=jupyter_sphinx-VERSION.tar.gz
sha1=241f6dfcd3aae4f44f330e2ba76480011b382d3d
md5=e7ab370d9793be5b20bce5447ccbd45b
cksum=2021246952
sha1=fb2abdd5e35da0886b12d45a6373c4dbcc24b244
md5=130daa6be810976c9f8e30aa04011e50
cksum=2882523000
upstream_url=https://pypi.io/packages/source/j/jupyter_sphinx/jupyter_sphinx-VERSION.tar.gz
2 changes: 1 addition & 1 deletion build/pkgs/jupyter_sphinx/package-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.2
0.4.0.p0
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
From 5bffbe38302c695123779f87300d84090b4bd118 Mon Sep 17 00:00:00 2001
From: Kwankyu Lee <[email protected]>
Date: Mon, 28 Aug 2023 00:18:59 +0900
Subject: [PATCH] Patch for sage live doc

---
jupyter_sphinx/__init__.py | 4 ++--
jupyter_sphinx/execute.py | 11 +++++++++++
2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/jupyter_sphinx/__init__.py b/jupyter_sphinx/__init__.py
index 34af884..b7ca8ee 100644
--- a/jupyter_sphinx/__init__.py
+++ b/jupyter_sphinx/__init__.py
@@ -31,7 +31,7 @@ from .thebelab import ThebeButton, ThebeButtonNode, ThebeOutputNode, ThebeSource
REQUIRE_URL_DEFAULT = (
"https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js"
)
-THEBELAB_URL_DEFAULT = "https://unpkg.com/thebelab@^0.4.0"
+THEBELAB_URL_DEFAULT = "https://unpkg.com/thebe@latest/lib/index.js"

logger = logging.getLogger(__name__)

@@ -186,7 +186,7 @@ def setup(app):
app.add_config_value("jupyter_sphinx_embed_url", None, "html")

# thebelab config, can be either a filename or a dict
- app.add_config_value("jupyter_sphinx_thebelab_config", None, "html")
+ app.add_config_value("jupyter_sphinx_thebelab_config", None, "env")
app.add_config_value("jupyter_sphinx_thebelab_url", THEBELAB_URL_DEFAULT, "html")

# linenos config
diff --git a/jupyter_sphinx/execute.py b/jupyter_sphinx/execute.py
index 558a26b..de44455 100644
--- a/jupyter_sphinx/execute.py
+++ b/jupyter_sphinx/execute.py
@@ -152,6 +152,17 @@ class ExecuteJupyterCells(SphinxTransform):
kernel_name = default_kernel
file_name = next(default_names)

+ # Save time when jupyter notebook execution is not necessary
+ if not any(not "execute" in node or node["execute"] for node in nodes):
+ # mimics empty cell output for each node
+ for node in nodes:
+ source = node.children[0]
+ source.attributes["classes"].append("code_cell")
+ node.attributes["cm_language"] = kernel_name
+ node += CellOutputNode(classes=["cell_output"])
+ apply_styling(node, thebe_config)
+ continue
+
# Add empty placeholder cells for non-executed nodes so nodes
# and cells can be zipped and the provided input/output
# can be inserted later
--
2.42.0

42 changes: 42 additions & 0 deletions src/doc/common/static/custom-codemirror-monokai.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* from https://codemirror.net/5/theme/monokai.css */
/* Based on Sublime Text's Monokai theme */

.cm-s-monokai.CodeMirror { background: #272822; color: #f8f8f2; }
.cm-s-monokai div.CodeMirror-selected { background: #49483E; }
.cm-s-monokai .CodeMirror-line::selection, .cm-s-monokai .CodeMirror-line > span::selection, .cm-s-monokai .CodeMirror-line > span > span::selection { background: rgba(73, 72, 62, .99); }
.cm-s-monokai .CodeMirror-line::-moz-selection, .cm-s-monokai .CodeMirror-line > span::-moz-selection, .cm-s-monokai .CodeMirror-line > span > span::-moz-selection { background: rgba(73, 72, 62, .99); }
.cm-s-monokai .CodeMirror-gutters { background: #272822; border-right: 0px; }
.cm-s-monokai .CodeMirror-guttermarker { color: white; }
.cm-s-monokai .CodeMirror-guttermarker-subtle { color: #d0d0d0; }
.cm-s-monokai .CodeMirror-linenumber { color: #d0d0d0; }
.cm-s-monokai .CodeMirror-cursor { border-left: 1px solid #f8f8f0; }

.cm-s-monokai span.cm-comment { color: #75715e; }
.cm-s-monokai span.cm-atom { color: #ae81ff; }
.cm-s-monokai span.cm-number { color: #ae81ff; }

.cm-s-monokai span.cm-comment.cm-attribute { color: #97b757; }
.cm-s-monokai span.cm-comment.cm-def { color: #bc9262; }
.cm-s-monokai span.cm-comment.cm-tag { color: #bc6283; }
.cm-s-monokai span.cm-comment.cm-type { color: #5998a6; }

.cm-s-monokai span.cm-property, .cm-s-monokai span.cm-attribute { color: #a6e22e; }
.cm-s-monokai span.cm-keyword { color: #f92672; }
.cm-s-monokai span.cm-builtin { color: #66d9ef; }
.cm-s-monokai span.cm-string { color: #e6db74; }

.cm-s-monokai span.cm-variable { color: #f8f8f2; }
.cm-s-monokai span.cm-variable-2 { color: #9effff; }
.cm-s-monokai span.cm-variable-3, .cm-s-monokai span.cm-type { color: #66d9ef; }
.cm-s-monokai span.cm-def { color: #fd971f; }
.cm-s-monokai span.cm-bracket { color: #f8f8f2; }
.cm-s-monokai span.cm-tag { color: #f92672; }
.cm-s-monokai span.cm-header { color: #ae81ff; }
.cm-s-monokai span.cm-link { color: #ae81ff; }
.cm-s-monokai span.cm-error { background: #f92672; color: #f8f8f0; }

.cm-s-monokai .CodeMirror-activeline-background { background: #373831; }
.cm-s-monokai .CodeMirror-matchingbracket {
text-decoration: underline;
color: white !important;
}
140 changes: 140 additions & 0 deletions src/doc/common/static/custom-jupyter-sphinx.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
div.jupyter_container {
margin: .5rem 0;
}

div.jupyter_container + div.jupyter_container {
margin: 0 0 .5rem 0;
}

div.jupyter_container div.cell_input pre {
margin: .5rem;
}

div.jupyter_container div.cell_output div.output {
margin: .5rem;
}

.thebelab-cell .jp-OutputArea {
margin: 0 .5rem;
}

.thebelab-cell .jp-OutputArea-output {
margin: 0 0 .5rem 0;
overflow-x: auto;
}

.thebelab-button {
margin: .5rem 0 .5rem .5rem;
padding: 0 .5rem;
min-width: 2rem;
}

.thebelab-button:active {
color: #0f0fff;
}

.thebelab-busy {
margin-left: .5rem;
}

#thebelab-activate-button {
position: fixed;
right: -5.1rem;
top: calc(50% - 1.5rem);
width: 6rem;
border-radius: 1rem;
transition-property: right;
transition-duration: 300ms;
transition-timing-function: ease-out;
z-index: 100;
}

#thebelab-activate-button:hover {
right: .4rem;
}

#thebelab-activate-button:active {
color: #0f0fff;
}

body[data-theme="dark"] {
.jupyter_container {
color: white;
background-color: black;
}

.jupyter_container .highlight {
background-color: black;
}

.thebelab-button {
color: #d0d0d0;
background-color: #383838;
}

.thebelab-button:active {
color: #368ce2;
}

#thebelab-activate-button {
background-color: #383838;
}

#thebelab-activate-button:active {
color: #368ce2;
}

.thebelab-cell .jp-OutputArea-output {
color: white;
background-color: black;
}

.thebelab-cell .jp-OutputArea-output pre {
color: white;
background-color: black;
}
}

@media (prefers-color-scheme: dark) {
body[data-theme="auto"] { /* the same styles with body[data-theme="dark"] */
.jupyter_container {
color: white;
background-color: black;
}

.jupyter_container .highlight {
background-color: black;
}

.thebelab-button {
color: #d0d0d0;
background-color: #383838;
}

.thebelab-button:active {
color: #368ce2;
}

#thebelab-activate-button {
background-color: #383838;
}

#thebelab-activate-button:active {
color: #368ce2;
}

.thebelab-cell .jp-OutputArea-output {
color: white;
background-color: black;
}

.thebelab-cell .jp-OutputArea-output pre {
color: white;
background-color: black;
}
}
}




114 changes: 114 additions & 0 deletions src/doc/common/static/jupyter-sphinx-furo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// Change the editor theme according to the furo light/dark/auto mode
function changeTheme(editor, theme) {
if (theme === 'dark') {
editor.setOption('theme', 'monokai'); // the same with pygments dark style in conf.py
} else if (theme === 'auto' && window.matchMedia('(prefers-color-scheme: dark)').matches) {
editor.setOption('theme', 'monokai');
} else {
editor.setOption('theme', 'default');
}
}

// Change the editor theme of all CodeMirror cells
function changeThemeAll(theme) {
const querySet = document.querySelectorAll('.CodeMirror');
for (var i = 0; i < querySet.length; i++) {
changeTheme(querySet[i].CodeMirror, theme);
}
}

// Use the theme data of the body element set by setTheme function
// defined in https://github.com/pradyunsg/furo/blob/main/src/furo/assets/scripts/furo.js
const body = document.body;
const observer1 = new MutationObserver((mutationsList) => {
for (let mutation of mutationsList) {
if (mutation.type === 'attributes' && mutation.attributeName === 'data-theme') {
const theme = body.dataset.theme;
changeThemeAll(theme);
}
}
});
observer1.observe(body, { attributes: true });


// In the furo auto mode, we watch prefers-color-scheme and use the theme data
// of the body element to change the CodeMirror editor theme
const prefersDarkMode = window.matchMedia('(prefers-color-scheme: dark)');

function handlePrefersColorSchemeChange(e) {
const theme = body.dataset.theme;
if (theme === 'auto') {
changeThemeAll(theme);
}
}

prefersDarkMode.addEventListener('change', handlePrefersColorSchemeChange);


// Change the editor theme of a new CodeMirror cell.
const callback = function(mutationsList, observer) {
for(const mutation of mutationsList) {
if (mutation.type === 'childList') {
const theme = body.dataset.theme;
for (const addedNode of mutation.addedNodes) {
if (addedNode.classList && addedNode.classList.contains('CodeMirror')) {
changeTheme(addedNode.CodeMirror, theme);
}}}}};
const observer2 = new MutationObserver(callback);
observer2.observe(document.getElementsByClassName("content")[0], { childList: true, subtree: true });


// Listen to the kernel status changes
// https://thebe.readthedocs.io/en/stable/events.html
thebelab.on("status", function (evt, data) {
if (data.status === 'building') {
const elements = document.querySelectorAll('.thebelab-cell');
elements.forEach(element => {
element.style.filter = 'opacity(50%)';
});
const element = document.getElementById("thebelab-activate-button");
element.innerHTML = "Building";
element.style.right = '.4rem';
}
else if (data.status === 'built') {
const elements = document.querySelectorAll('.thebelab-cell');
elements.forEach(element => {
element.style.filter = 'opacity(60%)';
});
const element = document.getElementById("thebelab-activate-button");
element.innerHTML = "Built";
element.style.right = '.4rem';
}
else if (data.status === 'launching') {
const elements = document.querySelectorAll('.thebelab-cell');
elements.forEach(element => {
element.style.filter = 'opacity(70%)';
});
const element = document.getElementById("thebelab-activate-button");
element.innerHTML = "Launching";
element.style.right = '.4rem';
}
else if (data.status === 'failed') {
const elements = document.querySelectorAll('.thebelab-cell');
elements.forEach(element => {
element.style.filter = 'opacity(50%)';
});
const element = document.getElementById("thebelab-activate-button");
element.innerHTML = 'Failed: ' + data.message;
element.style.right = '.4rem';
element.style.width = 'auto';
element.style.color = 'red';
}
else if (data.status === 'ready') {
const elements = document.querySelectorAll('.thebelab-cell');
elements.forEach(element => {
element.style.filter = 'opacity(100%)';
});
const element = document.getElementById("thebelab-activate-button");
element.innerHTML = "Ready";
element.style.right = null;
// Run custom code when the kernel is ready
const kernel = data.kernel;
kernel.requestExecute({code: "%display latex"});
}
});
Loading